generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fixture for declaration transpiler test #708
Open
MichaelMitchell-at
wants to merge
1
commit into
aspect-build:main
Choose a base branch
from
MichaelMitchell-at:declaration_transpiler_test_fixture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"Fixture to demonstrate a custom declaration transpiler for ts_project" | ||
|
||
load("@aspect_rules_js//js:providers.bzl", "JsInfo") | ||
load("@aspect_rules_ts//ts/private:ts_lib.bzl", "lib") | ||
|
||
def _mock_impl(ctx): | ||
out_files = [] | ||
|
||
for src in ctx.files.srcs: | ||
out_path = src.short_path | ||
|
||
if out_path.endswith(".json"): | ||
continue | ||
|
||
dts_file = ctx.actions.declare_file(lib.relative_to_package(out_path.replace(".ts", ".d.ts"), ctx)) | ||
out_files.append(dts_file) | ||
|
||
ctx.actions.run_shell( | ||
inputs = [src], | ||
outputs = [dts_file], | ||
command = "cp $@", | ||
arguments = [src.path, dts_file.path], | ||
) | ||
|
||
output_types_depset = depset(out_files) | ||
|
||
return [ | ||
JsInfo( | ||
target = ctx.label, | ||
sources = depset(), | ||
types = output_types_depset, | ||
transitive_sources = depset(), | ||
transitive_types = depset(), | ||
npm_sources = depset(), | ||
npm_package_store_infos = depset(), | ||
), | ||
DefaultInfo( | ||
files = output_types_depset, | ||
), | ||
] | ||
|
||
mock_impl = rule( | ||
attrs = { | ||
"srcs": attr.label_list( | ||
doc = "TypeScript source files", | ||
allow_files = True, | ||
mandatory = True, | ||
), | ||
}, | ||
implementation = _mock_impl, | ||
) | ||
|
||
def mock(name, srcs, **kwargs): | ||
# Run the rule producing those pre-declared outputs as well as any other outputs | ||
# which can not be determined ahead of time such as within directories, grouped | ||
# within a filegroup() etc. | ||
mock_impl( | ||
name = name, | ||
srcs = srcs, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this have to switch? The transpiler should just have to output the transpiled js or dts (+maps) as default info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having
JsInfo
seems typical of actual usage. Some examples:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That just means the rule can be used directly for things like
js_library(deps)
I guess, instead of howts_project
(the macro) orjs_library(srcs)
uses theDefaultInfo
.I guess it does not harm, but also isn't used in these tests 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's probably worth doing in case folks crib this as an example (though we could also provide a production-ready transpiler using oxc as an example ;)