Skip to content
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

fix: transitive js_library npm package deps #1836

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions e2e/pnpm_workspace/.bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
26 changes: 26 additions & 0 deletions e2e/pnpm_workspace/app/d/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
7 changes: 7 additions & 0 deletions e2e/pnpm_workspace/app/d/main.js
Original file line number Diff line number Diff line change
@@ -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())
8 changes: 8 additions & 0 deletions e2e/pnpm_workspace/app/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@app/c",
"private": true,
"dependencies": {
"@aspect-test/g": "1.0.0",
"@lib/d": "workspace:*"
}
}
1 change: 1 addition & 0 deletions e2e/pnpm_workspace/lib/d/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ js_library(
],
visibility = ["//visibility:public"],
deps = [
":node_modules/@aspect-test/d",
":node_modules/alias-2",
],
)
7 changes: 5 additions & 2 deletions e2e/pnpm_workspace/lib/d/index.js
Original file line number Diff line number Diff line change
@@ -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'),
}
1 change: 1 addition & 0 deletions e2e/pnpm_workspace/lib/d/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@lib/d",
"private": true,
"dependencies": {
"@aspect-test/d": "^2.0.0",
"alias-2": "npm:@types/node@16.18.11"
}
}
12 changes: 12 additions & 0 deletions e2e/pnpm_workspace/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/.bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
26 changes: 26 additions & 0 deletions e2e/pnpm_workspace_rerooted/app/d/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
7 changes: 7 additions & 0 deletions e2e/pnpm_workspace_rerooted/app/d/main.js
Original file line number Diff line number Diff line change
@@ -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())
8 changes: 8 additions & 0 deletions e2e/pnpm_workspace_rerooted/app/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@app/c",
"private": true,
"dependencies": {
"@aspect-test/g": "1.0.0",
"@lib/d": "workspace:*"
}
}
1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/lib/d/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ js_library(
],
visibility = ["//visibility:public"],
deps = [
":node_modules/@aspect-test/d",
":node_modules/alias-2",
],
)
7 changes: 5 additions & 2 deletions e2e/pnpm_workspace_rerooted/lib/d/index.js
Original file line number Diff line number Diff line change
@@ -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'),
}
1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/lib/d/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@lib/d",
"private": true,
"dependencies": {
"@aspect-test/d": "^2.0.0",
"alias-2": "npm:@types/node@16.18.11"
}
}
12 changes: 12 additions & 0 deletions e2e/pnpm_workspace_rerooted/root/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions examples/npm_deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
1 change: 1 addition & 0 deletions examples/npm_deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions examples/npm_package/packages/pkg_e/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
4 changes: 4 additions & 0 deletions examples/npm_package/packages/pkg_e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @mycorp/pkg-d package

'@mycorp/pkg-d' is an example of a first party package that is linked as a js_library with
transitive dependencies on other first party packages.
6 changes: 6 additions & 0 deletions examples/npm_package/packages/pkg_e/index.js
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 7 additions & 0 deletions examples/npm_package/packages/pkg_e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@mycorp/pkg-e",
"private": true,
"dependencies": {
"@mycorp/pkg-d": "workspace:*"
}
}
1 change: 1 addition & 0 deletions npm/private/npm_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading