From 5600df4a6b9b7537d4412a69bc6697a19de327f6 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Fri, 28 Jun 2024 18:01:39 -0700 Subject: [PATCH] fix: transitive js_library npm package deps --- .../npm_translate_lock_LTE4Nzc1MDcwNjU= | 7 +-- .bazelignore | 1 + .../npm_translate_lock_LTE4Nzc1MDcwNjU= | 5 ++- e2e/pnpm_workspace/.bazelignore | 1 + e2e/pnpm_workspace/app/d/BUILD.bazel | 26 +++++++++++ e2e/pnpm_workspace/app/d/main.js | 7 +++ e2e/pnpm_workspace/app/d/package.json | 8 ++++ e2e/pnpm_workspace/lib/d/BUILD.bazel | 1 + e2e/pnpm_workspace/lib/d/index.js | 7 ++- e2e/pnpm_workspace/lib/d/package.json | 1 + e2e/pnpm_workspace/pnpm-lock.yaml | 12 +++++ .../npm_translate_lock_LTE1MzU4OTk= | 5 ++- e2e/pnpm_workspace_rerooted/.bazelignore | 1 + e2e/pnpm_workspace_rerooted/app/d/BUILD.bazel | 26 +++++++++++ e2e/pnpm_workspace_rerooted/app/d/main.js | 7 +++ .../app/d/package.json | 8 ++++ e2e/pnpm_workspace_rerooted/lib/d/BUILD.bazel | 1 + e2e/pnpm_workspace_rerooted/lib/d/index.js | 7 ++- .../lib/d/package.json | 1 + .../root/pnpm-lock.yaml | 12 +++++ examples/npm_deps/BUILD.bazel | 17 +++++++ examples/npm_deps/package.json | 1 + .../npm_package/packages/pkg_e/BUILD.bazel | 19 ++++++++ examples/npm_package/packages/pkg_e/README.md | 3 ++ examples/npm_package/packages/pkg_e/index.js | 6 +++ .../npm_package/packages/pkg_e/package.json | 7 +++ npm/private/npm_package_store.bzl | 1 + .../test/snapshots/bzlmod/npm_defs.bzl | 45 +++++++++++++++++-- npm/private/test/snapshots/wksp/npm_defs.bzl | 45 +++++++++++++++++-- pnpm-lock.yaml | 12 +++++ pnpm-workspace.yaml | 1 + 31 files changed, 284 insertions(+), 17 deletions(-) create mode 100644 e2e/pnpm_workspace/app/d/BUILD.bazel create mode 100644 e2e/pnpm_workspace/app/d/main.js create mode 100644 e2e/pnpm_workspace/app/d/package.json create mode 100644 e2e/pnpm_workspace_rerooted/app/d/BUILD.bazel create mode 100644 e2e/pnpm_workspace_rerooted/app/d/main.js create mode 100644 e2e/pnpm_workspace_rerooted/app/d/package.json create mode 100644 examples/npm_package/packages/pkg_e/BUILD.bazel create mode 100644 examples/npm_package/packages/pkg_e/README.md create mode 100644 examples/npm_package/packages/pkg_e/index.js create mode 100644 examples/npm_package/packages/pkg_e/package.json diff --git a/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= b/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= index a10cf8eb0a..76274b49a1 100755 --- a/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= +++ b/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= @@ -5,12 +5,13 @@ examples/js_binary/package.json=-41174383 examples/linked_empty_node_modules/package.json=-1039372825 examples/macro/package.json=857146175 -examples/npm_deps/package.json=-1377141392 +examples/npm_deps/package.json=-929156430 examples/npm_deps/patches/meaning-of-life@1.0.0-pnpm.patch=-442666336 examples/npm_package/libs/lib_a/package.json=-1377103079 examples/npm_package/packages/pkg_a/package.json=1006424040 examples/npm_package/packages/pkg_b/package.json=1041247977 examples/npm_package/packages/pkg_d/package.json=1110895851 +examples/npm_package/packages/pkg_e/package.json=-2145239245 examples/webpack_cli/package.json=1911342006 js/private/coverage/bundle/package.json=-1543718929 js/private/image/package.json=-1260474848 @@ -23,5 +24,5 @@ npm/private/test/vendored/is-odd/package.json=1041695223 npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349 npm/private/test/vendored/semver-max/package.json=578664053 package.json=-275319675 -pnpm-lock.yaml=-1309835144 -pnpm-workspace.yaml=-1178830835 +pnpm-lock.yaml=2129089772 +pnpm-workspace.yaml=-1282513813 diff --git a/.bazelignore b/.bazelignore index cea9bbcc7b..90af469185 100644 --- a/.bazelignore +++ b/.bazelignore @@ -8,6 +8,7 @@ examples/npm_package/packages/pkg_a/node_modules/ examples/npm_package/packages/pkg_b/node_modules/ examples/npm_package/packages/pkg_c/node_modules/ examples/npm_package/packages/pkg_d/node_modules/ +examples/npm_package/packages/pkg_e/node_modules/ examples/webpack_cli/node_modules/ js/private/coverage/bundle/node_modules js/private/image/node_modules diff --git a/e2e/pnpm_workspace/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= b/e2e/pnpm_workspace/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= index a37a741967..adc129ae51 100755 --- a/e2e/pnpm_workspace/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= +++ b/e2e/pnpm_workspace/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= @@ -5,12 +5,13 @@ app/a/package.json=574382986 app/b/package.json=795450875 app/c/package.json=1357235418 +app/d/package.json=1859553579 lib/a/package.json=1162557353 lib/b/package.json=1612905941 lib/c/package.json=1015268365 -lib/d/package.json=-1311314987 +lib/d/package.json=476969669 package.json=-716078204 -pnpm-lock.yaml=793845425 +pnpm-lock.yaml=-1749700182 pnpm-workspace.yaml=-67685769 vendored/a/package.json=-174142441 vendored/b/package.json=536664170 diff --git a/e2e/pnpm_workspace/.bazelignore b/e2e/pnpm_workspace/.bazelignore index d63f7a7c6c..9452b67fe2 100644 --- a/e2e/pnpm_workspace/.bazelignore +++ b/e2e/pnpm_workspace/.bazelignore @@ -4,6 +4,7 @@ node_modules/ app/a/node_modules/ app/b/node_modules/ app/c/node_modules/ +app/d/node_modules/ lib/a/node_modules/ lib/b/node_modules/ lib/c/node_modules/ diff --git a/e2e/pnpm_workspace/app/d/BUILD.bazel b/e2e/pnpm_workspace/app/d/BUILD.bazel new file mode 100644 index 0000000000..45bb3fcd6d --- /dev/null +++ b/e2e/pnpm_workspace/app/d/BUILD.bazel @@ -0,0 +1,26 @@ +load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_test") +load("@npm//:defs.bzl", "npm_link_all_packages") + +npm_link_all_packages(name = "node_modules") + +js_binary( + name = "main", + args = ["foo"], + data = [ + ":node_modules/@aspect-test", + ":node_modules/@lib/d", + "//:node_modules/@aspect-test", + ], + entry_point = "main.js", +) + +js_test( + name = "test", + args = ["foo"], + data = [ + ":node_modules", + "//:node_modules/@aspect-test", + ], + entry_point = "main.js", + log_level = "info", +) diff --git a/e2e/pnpm_workspace/app/d/main.js b/e2e/pnpm_workspace/app/d/main.js new file mode 100644 index 0000000000..241dbe1c54 --- /dev/null +++ b/e2e/pnpm_workspace/app/d/main.js @@ -0,0 +1,7 @@ +console.log(process.argv) +console.log('--@aspect-test/a--', require('@aspect-test/a').id()) +console.log('--@aspect-test/b--', require('@aspect-test/b').id()) +console.log('--@aspect-test/c--', require('@aspect-test/c').id()) +console.log('--@aspect-test/g--', require('@aspect-test/g').id()) +console.log('--@lib/d--', require('@lib/d').id()) +console.log('--@lib/d--', require('@lib/d').test()) diff --git a/e2e/pnpm_workspace/app/d/package.json b/e2e/pnpm_workspace/app/d/package.json new file mode 100644 index 0000000000..c2fac3f8c4 --- /dev/null +++ b/e2e/pnpm_workspace/app/d/package.json @@ -0,0 +1,8 @@ +{ + "name": "@app/c", + "private": true, + "dependencies": { + "@aspect-test/g": "1.0.0", + "@lib/d": "workspace:*" + } +} diff --git a/e2e/pnpm_workspace/lib/d/BUILD.bazel b/e2e/pnpm_workspace/lib/d/BUILD.bazel index 24e45d0604..75fdced3ca 100644 --- a/e2e/pnpm_workspace/lib/d/BUILD.bazel +++ b/e2e/pnpm_workspace/lib/d/BUILD.bazel @@ -11,6 +11,7 @@ js_library( ], visibility = ["//visibility:public"], deps = [ + ":node_modules/@aspect-test/d", ":node_modules/alias-2", ], ) diff --git a/e2e/pnpm_workspace/lib/d/index.js b/e2e/pnpm_workspace/lib/d/index.js index afc605dd38..fa41678d30 100644 --- a/e2e/pnpm_workspace/lib/d/index.js +++ b/e2e/pnpm_workspace/lib/d/index.js @@ -1,9 +1,12 @@ const packageJson = require('./package.json') -const a2 = require('alias-2/package.json') module.exports = { id: () => `${packageJson.name}@${ packageJson.version ? packageJson.version : '0.0.0' }`, - test: () => [a2.name].join('\n'), + test: () => + [ + require('@aspect-test/d').version, + require('alias-2/package.json').name, + ].join('\n'), } diff --git a/e2e/pnpm_workspace/lib/d/package.json b/e2e/pnpm_workspace/lib/d/package.json index 9b2511b868..cc8b93dd55 100644 --- a/e2e/pnpm_workspace/lib/d/package.json +++ b/e2e/pnpm_workspace/lib/d/package.json @@ -2,6 +2,7 @@ "name": "@lib/d", "private": true, "dependencies": { + "@aspect-test/d": "^2.0.0", "alias-2": "npm:@types/node@16.18.11" } } diff --git a/e2e/pnpm_workspace/pnpm-lock.yaml b/e2e/pnpm_workspace/pnpm-lock.yaml index 9c5356dbe1..435eb4566b 100644 --- a/e2e/pnpm_workspace/pnpm-lock.yaml +++ b/e2e/pnpm_workspace/pnpm-lock.yaml @@ -59,6 +59,15 @@ importers: specifier: file:../../lib/c version: file:lib/c + app/d: + dependencies: + '@aspect-test/g': + specifier: 1.0.0 + version: 1.0.0 + '@lib/d': + specifier: workspace:* + version: link:../../lib/d + lib/a: dependencies: '@aspect-test/e': @@ -91,6 +100,9 @@ importers: lib/d: dependencies: + '@aspect-test/d': + specifier: ^2.0.0 + version: 2.0.0(@aspect-test/c@2.0.2) alias-2: specifier: npm:@types/node@16.18.11 version: /@types/node@16.18.11 diff --git a/e2e/pnpm_workspace_rerooted/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE1MzU4OTk= b/e2e/pnpm_workspace_rerooted/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE1MzU4OTk= index 6fba3bd3aa..eb4a70b6b9 100755 --- a/e2e/pnpm_workspace_rerooted/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE1MzU4OTk= +++ b/e2e/pnpm_workspace_rerooted/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE1MzU4OTk= @@ -5,12 +5,13 @@ app/a/package.json=574382986 app/b/package.json=795450875 app/c/package.json=1357235418 +app/d/package.json=1859553579 lib/a/package.json=1162557353 lib/b/package.json=1612905941 lib/c/package.json=1015268365 -lib/d/package.json=-1311314987 +lib/d/package.json=476969669 package.json=-716078204 -root/pnpm-lock.yaml=-1844676859 +root/pnpm-lock.yaml=1120945581 root/pnpm-workspace.yaml=1861018878 vendored/a/package.json=-174142441 vendored/b/package.json=536664170 diff --git a/e2e/pnpm_workspace_rerooted/.bazelignore b/e2e/pnpm_workspace_rerooted/.bazelignore index d63f7a7c6c..9452b67fe2 100644 --- a/e2e/pnpm_workspace_rerooted/.bazelignore +++ b/e2e/pnpm_workspace_rerooted/.bazelignore @@ -4,6 +4,7 @@ node_modules/ app/a/node_modules/ app/b/node_modules/ app/c/node_modules/ +app/d/node_modules/ lib/a/node_modules/ lib/b/node_modules/ lib/c/node_modules/ diff --git a/e2e/pnpm_workspace_rerooted/app/d/BUILD.bazel b/e2e/pnpm_workspace_rerooted/app/d/BUILD.bazel new file mode 100644 index 0000000000..45bb3fcd6d --- /dev/null +++ b/e2e/pnpm_workspace_rerooted/app/d/BUILD.bazel @@ -0,0 +1,26 @@ +load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_test") +load("@npm//:defs.bzl", "npm_link_all_packages") + +npm_link_all_packages(name = "node_modules") + +js_binary( + name = "main", + args = ["foo"], + data = [ + ":node_modules/@aspect-test", + ":node_modules/@lib/d", + "//:node_modules/@aspect-test", + ], + entry_point = "main.js", +) + +js_test( + name = "test", + args = ["foo"], + data = [ + ":node_modules", + "//:node_modules/@aspect-test", + ], + entry_point = "main.js", + log_level = "info", +) diff --git a/e2e/pnpm_workspace_rerooted/app/d/main.js b/e2e/pnpm_workspace_rerooted/app/d/main.js new file mode 100644 index 0000000000..241dbe1c54 --- /dev/null +++ b/e2e/pnpm_workspace_rerooted/app/d/main.js @@ -0,0 +1,7 @@ +console.log(process.argv) +console.log('--@aspect-test/a--', require('@aspect-test/a').id()) +console.log('--@aspect-test/b--', require('@aspect-test/b').id()) +console.log('--@aspect-test/c--', require('@aspect-test/c').id()) +console.log('--@aspect-test/g--', require('@aspect-test/g').id()) +console.log('--@lib/d--', require('@lib/d').id()) +console.log('--@lib/d--', require('@lib/d').test()) diff --git a/e2e/pnpm_workspace_rerooted/app/d/package.json b/e2e/pnpm_workspace_rerooted/app/d/package.json new file mode 100644 index 0000000000..c2fac3f8c4 --- /dev/null +++ b/e2e/pnpm_workspace_rerooted/app/d/package.json @@ -0,0 +1,8 @@ +{ + "name": "@app/c", + "private": true, + "dependencies": { + "@aspect-test/g": "1.0.0", + "@lib/d": "workspace:*" + } +} diff --git a/e2e/pnpm_workspace_rerooted/lib/d/BUILD.bazel b/e2e/pnpm_workspace_rerooted/lib/d/BUILD.bazel index 24e45d0604..75fdced3ca 100644 --- a/e2e/pnpm_workspace_rerooted/lib/d/BUILD.bazel +++ b/e2e/pnpm_workspace_rerooted/lib/d/BUILD.bazel @@ -11,6 +11,7 @@ js_library( ], visibility = ["//visibility:public"], deps = [ + ":node_modules/@aspect-test/d", ":node_modules/alias-2", ], ) diff --git a/e2e/pnpm_workspace_rerooted/lib/d/index.js b/e2e/pnpm_workspace_rerooted/lib/d/index.js index afc605dd38..fa41678d30 100644 --- a/e2e/pnpm_workspace_rerooted/lib/d/index.js +++ b/e2e/pnpm_workspace_rerooted/lib/d/index.js @@ -1,9 +1,12 @@ const packageJson = require('./package.json') -const a2 = require('alias-2/package.json') module.exports = { id: () => `${packageJson.name}@${ packageJson.version ? packageJson.version : '0.0.0' }`, - test: () => [a2.name].join('\n'), + test: () => + [ + require('@aspect-test/d').version, + require('alias-2/package.json').name, + ].join('\n'), } diff --git a/e2e/pnpm_workspace_rerooted/lib/d/package.json b/e2e/pnpm_workspace_rerooted/lib/d/package.json index 9b2511b868..cc8b93dd55 100644 --- a/e2e/pnpm_workspace_rerooted/lib/d/package.json +++ b/e2e/pnpm_workspace_rerooted/lib/d/package.json @@ -2,6 +2,7 @@ "name": "@lib/d", "private": true, "dependencies": { + "@aspect-test/d": "^2.0.0", "alias-2": "npm:@types/node@16.18.11" } } diff --git a/e2e/pnpm_workspace_rerooted/root/pnpm-lock.yaml b/e2e/pnpm_workspace_rerooted/root/pnpm-lock.yaml index 917e5ea646..cb83254d1e 100644 --- a/e2e/pnpm_workspace_rerooted/root/pnpm-lock.yaml +++ b/e2e/pnpm_workspace_rerooted/root/pnpm-lock.yaml @@ -59,6 +59,15 @@ importers: specifier: file:../../lib/c version: file:../lib/c + ../app/d: + dependencies: + '@aspect-test/g': + specifier: 1.0.0 + version: 1.0.0 + '@lib/d': + specifier: workspace:* + version: link:../../lib/d + ../lib/a: dependencies: '@aspect-test/e': @@ -91,6 +100,9 @@ importers: ../lib/d: dependencies: + '@aspect-test/d': + specifier: ^2.0.0 + version: 2.0.0(@aspect-test/c@2.0.2) alias-2: specifier: npm:@types/node@16.18.11 version: /@types/node@16.18.11 diff --git a/examples/npm_deps/BUILD.bazel b/examples/npm_deps/BUILD.bazel index 296e222cf0..1d13a83634 100644 --- a/examples/npm_deps/BUILD.bazel +++ b/examples/npm_deps/BUILD.bazel @@ -279,3 +279,20 @@ js_test( ], entry_point = "case9.js", ) + +####################################### +# Case 10: use a first-party npm package a transitive dependency on a monorepo workspace from a js_library target + +write_file( + name = "write10", + out = "case10.js", + content = ["require('@mycorp/pkg-e')"], +) + +js_test( + name = "test10", + data = [ + ":node_modules/@mycorp/pkg-e", + ], + entry_point = "case10.js", +) diff --git a/examples/npm_deps/package.json b/examples/npm_deps/package.json index bf297409a8..0a22da2557 100644 --- a/examples/npm_deps/package.json +++ b/examples/npm_deps/package.json @@ -6,6 +6,7 @@ "@gregmagolan/test-b": "0.0.2", "@mycorp/pkg-a": "workspace:*", "@mycorp/pkg-d": "workspace:*", + "@mycorp/pkg-e": "workspace:*", "@rollup/plugin-commonjs": "21.1.0", "acorn": "8.7.1", "debug": "3.2.7", diff --git a/examples/npm_package/packages/pkg_e/BUILD.bazel b/examples/npm_package/packages/pkg_e/BUILD.bazel new file mode 100644 index 0000000000..366b368fcc --- /dev/null +++ b/examples/npm_package/packages/pkg_e/BUILD.bazel @@ -0,0 +1,19 @@ +load("@aspect_rules_js//js:defs.bzl", "js_library") +load("@npm//:defs.bzl", "npm_link_all_packages") + +npm_link_all_packages(name = "node_modules") + +js_library( + name = "pkg", + srcs = [ + "index.js", + "package.json", + ], + visibility = ["//visibility:public"], + # because we're linking this js_library, we must explictly add our npm dependendies to `deps` so + # they are picked up my the linker. npm dependendies in `data` are not propogated through the + # linker when linking a js_libary. + deps = [ + ":node_modules", + ], +) diff --git a/examples/npm_package/packages/pkg_e/README.md b/examples/npm_package/packages/pkg_e/README.md new file mode 100644 index 0000000000..74f4c65c96 --- /dev/null +++ b/examples/npm_package/packages/pkg_e/README.md @@ -0,0 +1,3 @@ +# @mycorp/pkg-d package + +'@mycorp/pkg-d' is an example of a first party package that is linked as a js_library diff --git a/examples/npm_package/packages/pkg_e/index.js b/examples/npm_package/packages/pkg_e/index.js new file mode 100644 index 0000000000..83db516b86 --- /dev/null +++ b/examples/npm_package/packages/pkg_e/index.js @@ -0,0 +1,6 @@ +/** + * @fileoverview minimal test program that requires a another workspace project + * that defines its package using js_library. + */ + +module.exports = require('@mycorp/pkg-d') diff --git a/examples/npm_package/packages/pkg_e/package.json b/examples/npm_package/packages/pkg_e/package.json new file mode 100644 index 0000000000..20ba5f1b7b --- /dev/null +++ b/examples/npm_package/packages/pkg_e/package.json @@ -0,0 +1,7 @@ +{ + "name": "@mycorp/pkg-e", + "private": true, + "dependencies": { + "@mycorp/pkg-d": "workspace:*" + } +} diff --git a/npm/private/npm_package_store.bzl b/npm/private/npm_package_store.bzl index 0898a93926..862c0f746d 100644 --- a/npm/private/npm_package_store.bzl +++ b/npm/private/npm_package_store.bzl @@ -287,6 +287,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package, else: symlink_path = "{}/{}".format(ctx.label.package or ".", package_store_directory_path) + transitive_files_depsets.append(jsinfo.npm_sources) transitive_files_depsets.append(jsinfo.transitive_sources) transitive_files_depsets.append(jsinfo.transitive_types) npm_package_store_infos.extend(jsinfo.npm_package_store_infos.to_list()) diff --git a/npm/private/test/snapshots/bzlmod/npm_defs.bzl b/npm/private/test/snapshots/bzlmod/npm_defs.bzl index f61320577d..3080b309d3 100644 --- a/npm/private/test/snapshots/bzlmod/npm_defs.bzl +++ b/npm/private/test/snapshots/bzlmod/npm_defs.bzl @@ -988,7 +988,7 @@ load("@aspect_rules_js//npm/private:npm_link_package_store.bzl", _npm_link_packa # buildifier: disable=bzl-visibility load("@aspect_rules_js//npm/private:npm_package_store.bzl", _npm_package_store = "npm_package_store") -_LINK_PACKAGES = ["", "examples/js_binary", "examples/linked_empty_node_modules", "examples/macro", "examples/npm_deps", "examples/npm_package/libs/lib_a", "examples/npm_package/packages/pkg_a", "examples/npm_package/packages/pkg_b", "examples/npm_package/packages/pkg_d", "examples/webpack_cli", "js/private/coverage/bundle", "js/private/image", "js/private/test/image", "js/private/test/js_run_devserver", "js/private/worker/src", "npm/private/test", "npm/private/test/npm_package"] +_LINK_PACKAGES = ["", "examples/js_binary", "examples/linked_empty_node_modules", "examples/macro", "examples/npm_deps", "examples/npm_package/libs/lib_a", "examples/npm_package/packages/pkg_a", "examples/npm_package/packages/pkg_b", "examples/npm_package/packages/pkg_d", "examples/npm_package/packages/pkg_e", "examples/webpack_cli", "js/private/coverage/bundle", "js/private/image", "js/private/test/image", "js/private/test/js_run_devserver", "js/private/worker/src", "npm/private/test", "npm/private/test/npm_package"] # buildifier: disable=function-docstring def npm_link_all_packages(name = "node_modules", imported_links = []): @@ -2288,7 +2288,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): tags = ["manual"], ) - for link_package in ["examples/npm_deps", "js/private/test/image"]: + for link_package in ["examples/npm_deps", "examples/npm_package/packages/pkg_e", "js/private/test/image"]: if link_package == native.package_name(): # terminal target for direct dependencies _npm_link_package_store( @@ -2310,6 +2310,41 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_targets.append(":{}/@mycorp/pkg-d".format(name)) scope_targets["@mycorp"] = scope_targets["@mycorp"] + [link_targets[-1]] if "@mycorp" in scope_targets else [link_targets[-1]] + if is_root: + _npm_package_store( + name = ".aspect_rules_js/{}/@mycorp+pkg-e@0.0.0".format(name), + src = "//examples/npm_package/packages/pkg_e:pkg", + package = "@mycorp/pkg-e", + version = "0.0.0", + deps = { + "//:.aspect_rules_js/{}/@mycorp+pkg-d@0.0.0".format(name): "@mycorp/pkg-d", + }, + visibility = ["//visibility:public"], + tags = ["manual"], + ) + + for link_package in ["examples/npm_deps"]: + if link_package == native.package_name(): + # terminal target for direct dependencies + _npm_link_package_store( + name = "{}/@mycorp/pkg-e".format(name), + src = "//:.aspect_rules_js/{}/@mycorp+pkg-e@0.0.0".format(name), + visibility = ["//visibility:public"], + tags = ["manual"], + ) + + # filegroup target that provides a single file which is + # package directory for use in $(execpath) and $(rootpath) + native.filegroup( + name = "{}/@mycorp/pkg-e/dir".format(name), + srcs = [":{}/@mycorp/pkg-e".format(name)], + output_group = "package_directory", + visibility = ["//visibility:public"], + tags = ["manual"], + ) + link_targets.append(":{}/@mycorp/pkg-e".format(name)) + scope_targets["@mycorp"] = scope_targets["@mycorp"] + [link_targets[-1]] if "@mycorp" in scope_targets else [link_targets[-1]] + if is_root: _npm_package_store( name = ".aspect_rules_js/{}/test-npm_package@0.0.0".format(name), @@ -2478,10 +2513,14 @@ def npm_link_targets(name = "node_modules", package = None): if link_package == bazel_package: link_targets.append("//{}:{}/@mycorp/pkg-a".format(bazel_package, name)) - for link_package in ["examples/npm_deps", "js/private/test/image"]: + for link_package in ["examples/npm_deps", "examples/npm_package/packages/pkg_e", "js/private/test/image"]: if link_package == bazel_package: link_targets.append("//{}:{}/@mycorp/pkg-d".format(bazel_package, name)) + for link_package in ["examples/npm_deps"]: + if link_package == bazel_package: + link_targets.append("//{}:{}/@mycorp/pkg-e".format(bazel_package, name)) + for link_package in ["npm/private/test"]: if link_package == bazel_package: link_targets.append("//{}:{}/test-npm_package".format(bazel_package, name)) diff --git a/npm/private/test/snapshots/wksp/npm_defs.bzl b/npm/private/test/snapshots/wksp/npm_defs.bzl index 7bfc15dce1..2814b8c039 100644 --- a/npm/private/test/snapshots/wksp/npm_defs.bzl +++ b/npm/private/test/snapshots/wksp/npm_defs.bzl @@ -988,7 +988,7 @@ load("@aspect_rules_js//npm/private:npm_link_package_store.bzl", _npm_link_packa # buildifier: disable=bzl-visibility load("@aspect_rules_js//npm/private:npm_package_store.bzl", _npm_package_store = "npm_package_store") -_LINK_PACKAGES = ["", "examples/js_binary", "examples/linked_empty_node_modules", "examples/macro", "examples/npm_deps", "examples/npm_package/libs/lib_a", "examples/npm_package/packages/pkg_a", "examples/npm_package/packages/pkg_b", "examples/npm_package/packages/pkg_d", "examples/webpack_cli", "js/private/coverage/bundle", "js/private/image", "js/private/test/image", "js/private/test/js_run_devserver", "js/private/worker/src", "npm/private/test", "npm/private/test/npm_package"] +_LINK_PACKAGES = ["", "examples/js_binary", "examples/linked_empty_node_modules", "examples/macro", "examples/npm_deps", "examples/npm_package/libs/lib_a", "examples/npm_package/packages/pkg_a", "examples/npm_package/packages/pkg_b", "examples/npm_package/packages/pkg_d", "examples/npm_package/packages/pkg_e", "examples/webpack_cli", "js/private/coverage/bundle", "js/private/image", "js/private/test/image", "js/private/test/js_run_devserver", "js/private/worker/src", "npm/private/test", "npm/private/test/npm_package"] # buildifier: disable=function-docstring def npm_link_all_packages(name = "node_modules", imported_links = []): @@ -2288,7 +2288,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): tags = ["manual"], ) - for link_package in ["examples/npm_deps", "js/private/test/image"]: + for link_package in ["examples/npm_deps", "examples/npm_package/packages/pkg_e", "js/private/test/image"]: if link_package == native.package_name(): # terminal target for direct dependencies _npm_link_package_store( @@ -2310,6 +2310,41 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_targets.append(":{}/@mycorp/pkg-d".format(name)) scope_targets["@mycorp"] = scope_targets["@mycorp"] + [link_targets[-1]] if "@mycorp" in scope_targets else [link_targets[-1]] + if is_root: + _npm_package_store( + name = ".aspect_rules_js/{}/@mycorp+pkg-e@0.0.0".format(name), + src = "//examples/npm_package/packages/pkg_e:pkg", + package = "@mycorp/pkg-e", + version = "0.0.0", + deps = { + "//:.aspect_rules_js/{}/@mycorp+pkg-d@0.0.0".format(name): "@mycorp/pkg-d", + }, + visibility = ["//visibility:public"], + tags = ["manual"], + ) + + for link_package in ["examples/npm_deps"]: + if link_package == native.package_name(): + # terminal target for direct dependencies + _npm_link_package_store( + name = "{}/@mycorp/pkg-e".format(name), + src = "//:.aspect_rules_js/{}/@mycorp+pkg-e@0.0.0".format(name), + visibility = ["//visibility:public"], + tags = ["manual"], + ) + + # filegroup target that provides a single file which is + # package directory for use in $(execpath) and $(rootpath) + native.filegroup( + name = "{}/@mycorp/pkg-e/dir".format(name), + srcs = [":{}/@mycorp/pkg-e".format(name)], + output_group = "package_directory", + visibility = ["//visibility:public"], + tags = ["manual"], + ) + link_targets.append(":{}/@mycorp/pkg-e".format(name)) + scope_targets["@mycorp"] = scope_targets["@mycorp"] + [link_targets[-1]] if "@mycorp" in scope_targets else [link_targets[-1]] + if is_root: _npm_package_store( name = ".aspect_rules_js/{}/test-npm_package@0.0.0".format(name), @@ -2478,10 +2513,14 @@ def npm_link_targets(name = "node_modules", package = None): if link_package == bazel_package: link_targets.append("//{}:{}/@mycorp/pkg-a".format(bazel_package, name)) - for link_package in ["examples/npm_deps", "js/private/test/image"]: + for link_package in ["examples/npm_deps", "examples/npm_package/packages/pkg_e", "js/private/test/image"]: if link_package == bazel_package: link_targets.append("//{}:{}/@mycorp/pkg-d".format(bazel_package, name)) + for link_package in ["examples/npm_deps"]: + if link_package == bazel_package: + link_targets.append("//{}:{}/@mycorp/pkg-e".format(bazel_package, name)) + for link_package in ["npm/private/test"]: if link_package == bazel_package: link_targets.append("//{}:{}/test-npm_package".format(bazel_package, name)) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84516a45fb..ff27c09bc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -73,6 +73,9 @@ importers: '@mycorp/pkg-d': specifier: workspace:* version: link:../npm_package/packages/pkg_d + '@mycorp/pkg-e': + specifier: workspace:* + version: link:../npm_package/packages/pkg_e '@rollup/plugin-commonjs': specifier: 21.1.0 version: 21.1.0(rollup@2.70.2) @@ -134,6 +137,12 @@ importers: specifier: 8.3.2 version: 8.3.2 + examples/npm_package/packages/pkg_e: + dependencies: + '@mycorp/pkg-d': + specifier: workspace:* + version: link:../pkg_d + examples/webpack_cli: dependencies: '@vanilla-extract/css': @@ -1714,6 +1723,7 @@ packages: /are-we-there-yet@1.1.7: resolution: {integrity: sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==} + deprecated: This package is no longer supported. dependencies: delegates: 1.0.0 readable-stream: 2.3.8 @@ -3317,6 +3327,7 @@ packages: /gauge@2.7.4: resolution: {integrity: sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==} + deprecated: This package is no longer supported. dependencies: aproba: 1.2.0 console-control-strings: 1.1.0 @@ -3829,6 +3840,7 @@ packages: /inflight@1.0.6: resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. dependencies: once: 1.4.0 wrappy: 1.0.2 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 41d12ea672..0db08f5562 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -6,6 +6,7 @@ packages: - 'examples/npm_package/packages/pkg_a' - 'examples/npm_package/packages/pkg_b' - 'examples/npm_package/packages/pkg_d' + - 'examples/npm_package/packages/pkg_e' - 'examples/webpack_cli' - 'examples/linked_empty_node_modules' - 'js/private/coverage/bundle'