Skip to content

Commit 16d3a25

Browse files
authored
fix(builtin): don't restart npm_install rule just to look up a label (#2621)
Fixes #2620
1 parent fea3db3 commit 16d3a25

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

internal/npm_install/npm_install.bzl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ cd /D "{root}" && "{npm}" {npm_args}
473473
env[env_key] = "1"
474474
env["BUILD_BAZEL_RULES_NODEJS_VERSION"] = VERSION
475475

476+
# NB: after running npm install, it's essential that we don't cause the repository rule to restart
477+
# This means we must not reference any additional labels after this point.
478+
# See https://github.com/bazelbuild/rules_nodejs/issues/2620
476479
repository_ctx.report_progress("Running npm install on %s" % repository_ctx.attr.package_json)
477480
result = repository_ctx.execute(
478481
[repository_ctx.path("_npm.cmd" if is_windows_host else "_npm.sh")],
@@ -484,16 +487,18 @@ cd /D "{root}" && "{npm}" {npm_args}
484487
if result.return_code:
485488
fail("npm_install failed: %s (%s)" % (result.stdout, result.stderr))
486489

487-
remove_npm_absolute_paths = Label("//third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths:bin/removeNPMAbsolutePaths")
488-
489490
# removeNPMAbsolutePaths is run on node_modules after npm install as the package.json files
490491
# generated by npm are non-deterministic. They contain absolute install paths and other private
491492
# information fields starting with "_". removeNPMAbsolutePaths removes all fields starting with "_".
493+
fix_absolute_paths_cmd = [
494+
node,
495+
repository_ctx.path(repository_ctx.attr._remove_npm_absolute_paths),
496+
root + "/node_modules",
497+
]
498+
492499
if not repository_ctx.attr.quiet:
493-
print([node, repository_ctx.path(remove_npm_absolute_paths), root + "/node_modules"])
494-
result = repository_ctx.execute(
495-
[node, repository_ctx.path(remove_npm_absolute_paths), root + "/node_modules"],
496-
)
500+
print(fix_absolute_paths_cmd)
501+
result = repository_ctx.execute(fix_absolute_paths_cmd)
497502

498503
if result.return_code:
499504
fail("remove_npm_absolute_paths failed: %s (%s)" % (result.stdout, result.stderr))
@@ -526,6 +531,7 @@ See npm CLI docs https://docs.npmjs.com/cli/install.html for complete list of su
526531
mandatory = True,
527532
allow_single_file = True,
528533
),
534+
"_remove_npm_absolute_paths": attr.label(default = Label("//third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths:bin/removeNPMAbsolutePaths")),
529535
}),
530536
doc = """Runs npm install during workspace setup.
531537

0 commit comments

Comments
 (0)