Skip to content

Commit

Permalink
fix: prevent duplicate outputs when an link_js_package in an external…
Browse files Browse the repository at this point in the history
… repository has a lifecycle hook (#115)
  • Loading branch information
gregmagolan authored May 20, 2022
1 parent 3d3935b commit 1cb1bf3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions e2e/link_js_package/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ js_binary(
"@npm//@aspect-test/a",
"@npm//@aspect-test/b",
"@npm//@aspect-test/c",
"@rules_foo_npm//@aspect-test/a",
],
entry_point = "main.js",
)
Expand All @@ -20,6 +21,7 @@ js_test(
"@npm//@aspect-test/a",
"@npm//@aspect-test/b",
"@npm//@aspect-test/c",
"@rules_foo_npm//@aspect-test/a",
],
entry_point = "main.js",
verbose = True,
Expand Down
5 changes: 5 additions & 0 deletions e2e/link_js_package/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ console.log(c.id())
const fp = require('@e2e/lib')
console.log('--@e2e/lib--')
console.log(fp.id())
const rulesFooA = require('../external/rules_foo/foo/node_modules/@aspect-test/a')
console.log('--rulesFooA--')
console.log(rulesFooA.id())
console.log(rulesFooA.idB())
console.log(rulesFooA.idC())
6 changes: 5 additions & 1 deletion js/private/link_js_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ def _impl_store(ctx):
# "node_modules/{virtual_store_root}/{virtual_store_name}/node_modules/{package}"
virtual_store_directory_path = paths.join("node_modules", pnpm_utils.virtual_store_root, virtual_store_name, "node_modules", package)

if ctx.label.workspace_name:
expected_short_path = paths.join("..", ctx.label.workspace_name, ctx.label.package, virtual_store_directory_path)
else:
expected_short_path = paths.join(ctx.label.package, virtual_store_directory_path)
src_directory = ctx.attr.src[JsPackageInfo].directory
if src_directory.short_path == paths.join(ctx.label.package, virtual_store_directory_path):
if src_directory.short_path == expected_short_path:
# the input is already the desired output; this is the pattern for
# packages with lifecycle hooks
virtual_store_directory = src_directory
Expand Down

0 comments on commit 1cb1bf3

Please sign in to comment.