Skip to content

Commit

Permalink
fix(pnpm): various npm package aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed May 31, 2024
1 parent 54ec2ff commit fbba1a2
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 147 deletions.
5 changes: 4 additions & 1 deletion e2e/pnpm_lockfiles/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# gazelle:exclude **/snapshots/**/*

exports_files(["base/patched-dependencies-test.js"])
exports_files([
"base/patched-dependencies-test.js",
"base/aliases-test.js",
])
24 changes: 24 additions & 0 deletions e2e/pnpm_lockfiles/base/aliases-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// `@aspect-test/{a,a2}` should be importable and equal
if (require('@aspect-test/a') !== require('@aspect-test/a2')) {
throw new Error(
'aliased `@aspect-test/a` as `@aspect-test/a2` are not the same'
)
}

// `alias-types-node` and `@types/node` should be importable and equal
if (
require('alias-types-node/package.json') !==
require('@types/node/package.json')
) {
throw new Error(
'aliased `@types/node` as `alias-types-node` is not the same'
)
}

// `is-odd` and the aliased `is-odd-alt-version` should be different versions
if (
require('is-odd/package.json').version ===
require('is-odd-alt-version/package.json').version
) {
throw new Error('aliased `is-odd` as `is-odd-alt-version` are the same')
}
4 changes: 3 additions & 1 deletion e2e/pnpm_lockfiles/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"rollup": "3.2.5",
"meaning-of-life": "1.0.0",
"is-odd": "3.0.1",
"is-odd-alt-version": "npm:is-odd@^2.0.0",
"uvu": "0.5.6",
"@scoped/a": "workspace:*",
"@scoped/b": "link:../projects/b",
Expand All @@ -19,7 +20,8 @@
"devDependencies": {
"@aspect-test/b": "5.0.2",
"@types/node": "16.18.11",
"@types/archiver": "5.3.1"
"@types/archiver": "5.3.1",
"alias-types-node": "npm:@types/node@~16.18.11"
},
"optionalDependencies": {
"@aspect-test/c": "2.0.0"
Expand Down
34 changes: 27 additions & 7 deletions e2e/pnpm_lockfiles/lockfile-test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ def lockfile_test(name = None):
lock_version = name if name else native.package_name()
lock_repo = "lock-%s" % lock_version

copy_file(
name = "copy-tests",
src = "//:base/patched-dependencies-test.js",
out = "patched-dependencies-test.js",
)
# Copy each test to this lockfile dir
for test in ["patched-dependencies-test.js", "aliases-test.js"]:
copy_file(
name = "copy-{}".format(test),
src = "//:base/{}".format(test),
out = test,
)

js_test(
name = "patch-test",
Expand All @@ -53,6 +55,19 @@ def lockfile_test(name = None):
entry_point = "patched-dependencies-test.js",
)

js_test(
name = "aliases-test",
data = [
":node_modules/@aspect-test/a",
":node_modules/@aspect-test/a2",
":node_modules/@types/node",
":node_modules/alias-types-node",
":node_modules/is-odd",
":node_modules/is-odd-alt-version",
],
entry_point = "aliases-test.js",
)

build_test(
name = "targets",
targets = [
Expand Down Expand Up @@ -89,10 +104,15 @@ def lockfile_test(name = None):
# Odd git/http versions
":node_modules/debug",
":node_modules/hello",
# ":node_modules/jsonify", TODO: v9
":node_modules/jsonify",

# npm:
# npm: alias
":node_modules/@aspect-test/a2",
# npm: alias to registry-scoped packages
":node_modules/alias-types-node",
# npm: alias to alternate versions
":node_modules/is-odd-alt-version",
":.aspect_rules_js/node_modules/[email protected]",

# Targets within the virtual store...
# Direct dep targets
Expand Down
11 changes: 11 additions & 0 deletions e2e/pnpm_lockfiles/v54/pnpm-lock.yaml

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

46 changes: 27 additions & 19 deletions e2e/pnpm_lockfiles/v54/snapshots/defs.bzl

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

13 changes: 13 additions & 0 deletions e2e/pnpm_lockfiles/v60/pnpm-lock.yaml

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

Loading

0 comments on commit fbba1a2

Please sign in to comment.