Skip to content

Commit

Permalink
fix(npm): package file: versions not relative to the workspace root
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Oct 17, 2024
1 parent 31bf0e3 commit d7fd42c
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ lib/a/package.json=1162557353
lib/b/package.json=1612905941
lib/c/package.json=1015268365
lib/d/package.json=476969669
package.json=-716078204
root/pnpm-lock.yaml=1120945581
package.json=-1094473262
root/pnpm-lock.yaml=294643168
root/pnpm-workspace.yaml=1861018878
vendored/a/package.json=-174142441
vendored/b/package.json=536664170
vendored/lodash-4.17.19.tgz=-869163378
7 changes: 7 additions & 0 deletions e2e/pnpm_workspace_rerooted/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ build_test(
"//lib/d:node_modules/alias-2",
],
)

build_test(
name = "vendored",
targets = [
"//:node_modules/lodash",
],
)
1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ npm.npm_translate_lock(
"//lib/c:package.json",
"//lib/d:package.json",
"//root:pnpm-workspace.yaml",
"//vendored:lodash-4.17.19.tgz",
"//vendored/a:package.json",
"//vendored/b:package.json",
],
Expand Down
1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ npm_translate_lock(
"//lib/c:package.json",
"//lib/d:package.json",
"//root:pnpm-workspace.yaml",
"//vendored:lodash-4.17.19.tgz",
"//vendored/a:package.json",
"//vendored/b:package.json",
],
Expand Down
2 changes: 2 additions & 0 deletions e2e/pnpm_workspace_rerooted/app/a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ js_binary(
":node_modules/@aspect-test",
":node_modules/@lib",
"//:node_modules/@aspect-test",
"//:node_modules/lodash",
],
entry_point = "main.js",
)
Expand All @@ -23,6 +24,7 @@ js_test(
data = [
":node_modules",
"//:node_modules/@aspect-test",
"//:node_modules/lodash",
],
entry_point = "main.js",
log_level = "info",
Expand Down
1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/app/a/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ console.log('--@aspect-test/c--', require('@aspect-test/c').id())
console.log('--@aspect-test/g--', require('@aspect-test/g').id())
console.log('--@lib/a--', require('@lib/a').id())
console.log('--@lib/a--', require('@lib/a').test())
console.log('--lodash--', require('lodash'))
9 changes: 9 additions & 0 deletions e2e/pnpm_workspace_rerooted/lib/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NOTE: keep in sync with e2e/pnpm_workspace(_rerooted)

load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")
Expand All @@ -14,3 +15,11 @@ npm_package(
out = "pkg",
visibility = ["//visibility:public"],
)

build_test(
name = "vendored",
targets = [
":node_modules/vendored-a",
":node_modules/vendored-b",
],
)
3 changes: 2 additions & 1 deletion e2e/pnpm_workspace_rerooted/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"private": true,
"dependencies": {
"typescript": "4.9.5",
"@aspect-test/a": "5.0.2"
"@aspect-test/a": "5.0.2",
"lodash": "file:vendored/lodash-4.17.19.tgz"
},
"devDependencies": {
"@aspect-test/b": "5.0.2"
Expand Down
9 changes: 9 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.

1 change: 1 addition & 0 deletions e2e/pnpm_workspace_rerooted/vendored/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["lodash-4.17.19.tgz"])
Binary file not shown.
4 changes: 3 additions & 1 deletion npm/private/npm_translate_lock_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ ERROR: can not apply both `pnpm.patchedDependencies` and `npm_translate_lock(pat
else:
url = tarball
elif tarball.startswith("file:"):
url = tarball
file_path = tarball[5:]
file_path = paths.normalize(paths.join(root_package, file_path))
url = "file:{}".format(file_path)
else:
if not registry:
registry = utils.npm_registry_url(name, registries, default_registry)
Expand Down

0 comments on commit d7fd42c

Please sign in to comment.