-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(builtin): fix linker bug when there are no third-party modules
- Loading branch information
1 parent
91d81b3
commit becd9bc
Showing
5 changed files
with
58 additions
and
4 deletions.
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
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,11 @@ | ||
load(":no_npm_deps.bzl", "no_npm_deps") | ||
|
||
# Tests the | ||
# ``` | ||
# [link_node_modules.js] no third-party packages; mkdir node_modules at npm/node_modules | ||
# ``` | ||
# path in the linker | ||
no_npm_deps( | ||
name = "no_npm_deps_linker_test", | ||
src = "input.js", | ||
) |
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 @@ | ||
console.log('here'); |
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,42 @@ | ||
""" | ||
This rule runs terser executable directly via ctx.actions.run instead of using the run_node function. | ||
This ensures that there are no third-party npm deps in runfiles since run_node will add any | ||
NodeRuntimeDepsInfo deps from the executable terser. | ||
""" | ||
|
||
_ATTRS = { | ||
"src": attr.label( | ||
allow_single_file = True, | ||
mandatory = True, | ||
), | ||
"terser": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
default = Label("@npm//terser/bin:terser"), | ||
), | ||
} | ||
|
||
_OUTPUTS = { | ||
"minified": "%{name}.js", | ||
} | ||
|
||
def _impl(ctx): | ||
args = ctx.actions.args() | ||
args.add(ctx.file.src.path) | ||
args.add_all(["--output", ctx.outputs.minified.path]) | ||
|
||
ctx.actions.run( | ||
progress_message = "Optimizing JavaScript %s [terser]" % ctx.outputs.minified.short_path, | ||
executable = ctx.executable.terser, | ||
inputs = [ctx.file.src], | ||
outputs = [ctx.outputs.minified], | ||
arguments = [args], | ||
) | ||
|
||
return [DefaultInfo()] | ||
|
||
no_npm_deps = rule( | ||
implementation = _impl, | ||
attrs = _ATTRS, | ||
outputs = _OUTPUTS, | ||
) |