diff --git a/e2e/pnpm_lockfiles/BUILD.bazel b/e2e/pnpm_lockfiles/BUILD.bazel index b472c1e8e5..c539f89b20 100644 --- a/e2e/pnpm_lockfiles/BUILD.bazel +++ b/e2e/pnpm_lockfiles/BUILD.bazel @@ -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", +]) diff --git a/e2e/pnpm_lockfiles/base/aliases-test.js b/e2e/pnpm_lockfiles/base/aliases-test.js new file mode 100644 index 0000000000..be4086100d --- /dev/null +++ b/e2e/pnpm_lockfiles/base/aliases-test.js @@ -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') +} diff --git a/e2e/pnpm_lockfiles/base/package.json b/e2e/pnpm_lockfiles/base/package.json index ff77a51bec..c22416d53b 100644 --- a/e2e/pnpm_lockfiles/base/package.json +++ b/e2e/pnpm_lockfiles/base/package.json @@ -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", @@ -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" diff --git a/e2e/pnpm_lockfiles/lockfile-test.bzl b/e2e/pnpm_lockfiles/lockfile-test.bzl index 0536ffa7c6..9cc4d78373 100644 --- a/e2e/pnpm_lockfiles/lockfile-test.bzl +++ b/e2e/pnpm_lockfiles/lockfile-test.bzl @@ -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", @@ -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 = [ @@ -91,8 +106,13 @@ def lockfile_test(name = None): ":node_modules/hello", # ":node_modules/jsonify", TODO: v9 - # 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/is-odd@2.0.0", # Targets within the virtual store... # Direct dep targets diff --git a/e2e/pnpm_lockfiles/v54/pnpm-lock.yaml b/e2e/pnpm_lockfiles/v54/pnpm-lock.yaml index a58ca996b6..afa24b8811 100644 --- a/e2e/pnpm_lockfiles/v54/pnpm-lock.yaml +++ b/e2e/pnpm_lockfiles/v54/pnpm-lock.yaml @@ -26,9 +26,11 @@ importers: '@scoped/d': ../projects/d '@types/archiver': 5.3.1 '@types/node': 16.18.11 + alias-types-node: npm:@types/node@~16.18.11 debug: ngokevin/debug#9742c5f383a6f8046241920156236ade8ec30d53 hello: https://gitpkg.vercel.app/EqualMa/gitpkg-hello/packages/hello is-odd: 3.0.1 + is-odd-alt-version: npm:is-odd@^2.0.0 jsonify: https://github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz meaning-of-life: 1.0.0 rollup: 3.2.5 @@ -43,6 +45,7 @@ importers: debug: github.com/ngokevin/debug/9742c5f383a6f8046241920156236ade8ec30d53 hello: '@gitpkg.vercel.app/EqualMa/gitpkg-hello/packages/hello' is-odd: 3.0.1 + is-odd-alt-version: /is-odd/2.0.0 jsonify: '@github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz' meaning-of-life: 1.0.0_o3deharooos255qt5xdujc3cuq rollup: 3.2.5 @@ -53,6 +56,7 @@ importers: '@aspect-test/b': 5.0.2 '@types/archiver': registry.npmjs.org/@types/archiver/5.3.1 '@types/node': registry.npmjs.org/@types/node/16.18.11 + alias-types-node: registry.npmjs.org/@types/node/16.18.11 ../projects/a: specifiers: {} @@ -128,6 +132,13 @@ packages: dev: false optional: true + /is-odd/2.0.0: + resolution: {integrity: sha512-OTiixgpZAT1M4NHgS5IguFp/Vz2VI3U7Goh4/HA1adtwyLtSBrxYlcSYkhpAE07s4fKEcjrFxyvtQBND4vFQyQ==} + engines: {node: '>=0.10.0'} + dependencies: + is-number: file:../vendored/is-number + dev: false + /is-odd/3.0.1: resolution: {integrity: sha512-CQpnWPrDwmP1+SMHXZhtLtJv90yiyVfluGsX5iNCVkrhQtU3TQHsUWPG9wkdk9Lgd5yNpAg9jQEo90CBaXgWMA==} engines: {node: '>=4'} diff --git a/e2e/pnpm_lockfiles/v54/snapshots/defs.bzl b/e2e/pnpm_lockfiles/v54/snapshots/defs.bzl index 4a1bdbc706..a8d5b530b1 100644 --- a/e2e/pnpm_lockfiles/v54/snapshots/defs.bzl +++ b/e2e/pnpm_lockfiles/v54/snapshots/defs.bzl @@ -19,14 +19,15 @@ load("@@aspect_rules_js~~npm~lock-__dequal__2.0.3__links//:defs.bzl load("@@aspect_rules_js~~npm~lock-__diff__at_github.com_kpdecker_jsdiff_archive_refs_tags_v5.2.0.tar.gz__links//:defs.bzl", store_12 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__fsevents__2.3.3__links//:defs.bzl", store_13 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__hello__at_gitpkg.vercel.app_EqualMa_gitpkg-hello_packages_hello__links//:defs.bzl", link_14 = "npm_link_imported_package_store", store_14 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_15 = "npm_link_imported_package_store", store_15 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_16 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_17 = "npm_link_imported_package_store", store_17 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_18 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_19 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_20 = "npm_link_imported_package_store", store_20 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_21 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_22 = "npm_link_imported_package_store", store_22 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__2.0.0__links//:defs.bzl", link_15 = "npm_link_imported_package_store", store_15 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_17 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_18 = "npm_link_imported_package_store", store_18 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_19 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_20 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_21 = "npm_link_imported_package_store", store_21 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_22 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_23 = "npm_link_imported_package_store", store_23 = "npm_imported_package_store") _LINK_PACKAGES = ["", "projects/a", "projects/b", "projects/c", "projects/d", "vendored/is-number"] @@ -65,13 +66,14 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): store_13(name = "{}/fsevents".format(name)) store_14(name = "{}/hello".format(name)) store_15(name = "{}/is-odd".format(name)) - store_16(name = "{}/kleur".format(name)) - store_17(name = "{}/meaning-of-life".format(name)) - store_18(name = "{}/mri".format(name)) - store_19(name = "{}/ms".format(name)) - store_20(name = "{}/rollup".format(name)) - store_21(name = "{}/sade".format(name)) - store_22(name = "{}/uvu".format(name)) + store_16(name = "{}/is-odd".format(name)) + store_17(name = "{}/kleur".format(name)) + store_18(name = "{}/meaning-of-life".format(name)) + store_19(name = "{}/mri".format(name)) + store_20(name = "{}/ms".format(name)) + store_21(name = "{}/rollup".format(name)) + store_22(name = "{}/sade".format(name)) + store_23(name = "{}/uvu".format(name)) if link: if bazel_package == "": link_0(name = "{}/@aspect-test/a".format(name)) @@ -94,17 +96,21 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_9(name = "{}/@types/node".format(name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) scope_targets["@types"] = scope_targets["@types"] + [link_targets[-1]] if "@types" in scope_targets else [link_targets[-1]] + link_9(name = "{}/alias-types-node".format(name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_10(name = "{}/debug".format(name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_14(name = "{}/hello".format(name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) - link_15(name = "{}/is-odd".format(name)) + link_15(name = "{}/is-odd-alt-version".format(name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) + link_16(name = "{}/is-odd".format(name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) - link_17(name = "{}/meaning-of-life".format(name)) + link_18(name = "{}/meaning-of-life".format(name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) - link_20(name = "{}/rollup".format(name)) + link_21(name = "{}/rollup".format(name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) - link_22(name = "{}/uvu".format(name)) + link_23(name = "{}/uvu".format(name)) link_targets.append("//{}:{}/uvu".format(bazel_package, name)) if is_root: @@ -287,8 +293,10 @@ def npm_link_targets(name = "node_modules", package = None): link_targets.append("//{}:{}/jsonify".format(bazel_package, name)) link_targets.append("//{}:{}/@types/archiver".format(bazel_package, name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) diff --git a/e2e/pnpm_lockfiles/v60/pnpm-lock.yaml b/e2e/pnpm_lockfiles/v60/pnpm-lock.yaml index 5503a8ca65..6f26d5d4af 100644 --- a/e2e/pnpm_lockfiles/v60/pnpm-lock.yaml +++ b/e2e/pnpm_lockfiles/v60/pnpm-lock.yaml @@ -46,6 +46,9 @@ importers: is-odd: specifier: 3.0.1 version: 3.0.1 + is-odd-alt-version: + specifier: npm:is-odd@^2.0.0 + version: /is-odd@2.0.0 jsonify: specifier: https://github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz version: '@github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz' @@ -72,6 +75,9 @@ importers: '@types/node': specifier: 16.18.11 version: registry.npmjs.org/@types/node@16.18.11 + alias-types-node: + specifier: npm:@types/node@~16.18.11 + version: registry.npmjs.org/@types/node@16.18.11 ../projects/a: {} @@ -150,6 +156,13 @@ packages: dev: false optional: true + /is-odd@2.0.0: + resolution: {integrity: sha512-OTiixgpZAT1M4NHgS5IguFp/Vz2VI3U7Goh4/HA1adtwyLtSBrxYlcSYkhpAE07s4fKEcjrFxyvtQBND4vFQyQ==} + engines: {node: '>=0.10.0'} + dependencies: + is-number: file:../vendored/is-number + dev: false + /is-odd@3.0.1: resolution: {integrity: sha512-CQpnWPrDwmP1+SMHXZhtLtJv90yiyVfluGsX5iNCVkrhQtU3TQHsUWPG9wkdk9Lgd5yNpAg9jQEo90CBaXgWMA==} engines: {node: '>=4'} diff --git a/e2e/pnpm_lockfiles/v60/snapshots/defs.bzl b/e2e/pnpm_lockfiles/v60/snapshots/defs.bzl index 5b86fc5f63..6f7ebf07aa 100644 --- a/e2e/pnpm_lockfiles/v60/snapshots/defs.bzl +++ b/e2e/pnpm_lockfiles/v60/snapshots/defs.bzl @@ -20,14 +20,15 @@ load("@@aspect_rules_js~~npm~lock-__dequal__2.0.3__links//:defs.bzl load("@@aspect_rules_js~~npm~lock-__diff__at_github.com_kpdecker_jsdiff_archive_refs_tags_v5.2.0.tar.gz__links//:defs.bzl", store_13 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__fsevents__2.3.3__links//:defs.bzl", store_14 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__hello__at_gitpkg.vercel.app_EqualMa_gitpkg-hello_packages_hello__links//:defs.bzl", link_15 = "npm_link_imported_package_store", store_15 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_17 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_18 = "npm_link_imported_package_store", store_18 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_19 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_20 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_21 = "npm_link_imported_package_store", store_21 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_22 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_23 = "npm_link_imported_package_store", store_23 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__2.0.0__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_17 = "npm_link_imported_package_store", store_17 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_18 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_19 = "npm_link_imported_package_store", store_19 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_20 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_21 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_22 = "npm_link_imported_package_store", store_22 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_23 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_24 = "npm_link_imported_package_store", store_24 = "npm_imported_package_store") _LINK_PACKAGES = ["", "projects/a", "projects/b", "projects/c", "projects/d", "vendored/is-number"] @@ -67,13 +68,14 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): store_14(name = "{}/fsevents".format(name)) store_15(name = "{}/hello".format(name)) store_16(name = "{}/is-odd".format(name)) - store_17(name = "{}/kleur".format(name)) - store_18(name = "{}/meaning-of-life".format(name)) - store_19(name = "{}/mri".format(name)) - store_20(name = "{}/ms".format(name)) - store_21(name = "{}/rollup".format(name)) - store_22(name = "{}/sade".format(name)) - store_23(name = "{}/uvu".format(name)) + store_17(name = "{}/is-odd".format(name)) + store_18(name = "{}/kleur".format(name)) + store_19(name = "{}/meaning-of-life".format(name)) + store_20(name = "{}/mri".format(name)) + store_21(name = "{}/ms".format(name)) + store_22(name = "{}/rollup".format(name)) + store_23(name = "{}/sade".format(name)) + store_24(name = "{}/uvu".format(name)) if link: if bazel_package == "": link_0(name = "{}/@aspect-test/a".format(name)) @@ -99,17 +101,21 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_10(name = "{}/@types/node".format(name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) scope_targets["@types"] = scope_targets["@types"] + [link_targets[-1]] if "@types" in scope_targets else [link_targets[-1]] + link_10(name = "{}/alias-types-node".format(name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_11(name = "{}/debug".format(name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_15(name = "{}/hello".format(name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) - link_16(name = "{}/is-odd".format(name)) + link_16(name = "{}/is-odd-alt-version".format(name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) + link_17(name = "{}/is-odd".format(name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) - link_18(name = "{}/meaning-of-life".format(name)) + link_19(name = "{}/meaning-of-life".format(name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) - link_21(name = "{}/rollup".format(name)) + link_22(name = "{}/rollup".format(name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) - link_23(name = "{}/uvu".format(name)) + link_24(name = "{}/uvu".format(name)) link_targets.append("//{}:{}/uvu".format(bazel_package, name)) if is_root: @@ -293,8 +299,10 @@ def npm_link_targets(name = "node_modules", package = None): link_targets.append("//{}:{}/jsonify".format(bazel_package, name)) link_targets.append("//{}:{}/@types/archiver".format(bazel_package, name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) diff --git a/e2e/pnpm_lockfiles/v61/pnpm-lock.yaml b/e2e/pnpm_lockfiles/v61/pnpm-lock.yaml index 184063aa38..928f692c50 100644 --- a/e2e/pnpm_lockfiles/v61/pnpm-lock.yaml +++ b/e2e/pnpm_lockfiles/v61/pnpm-lock.yaml @@ -50,6 +50,9 @@ importers: is-odd: specifier: 3.0.1 version: 3.0.1 + is-odd-alt-version: + specifier: npm:is-odd@^2.0.0 + version: /is-odd@2.0.0 jsonify: specifier: https://github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz version: '@github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz' @@ -76,6 +79,9 @@ importers: '@types/node': specifier: 16.18.11 version: registry.npmjs.org/@types/node@16.18.11 + alias-types-node: + specifier: npm:@types/node@~16.18.11 + version: registry.npmjs.org/@types/node@16.18.11 ../projects/a: {} @@ -154,6 +160,13 @@ packages: dev: false optional: true + /is-odd@2.0.0: + resolution: {integrity: sha512-OTiixgpZAT1M4NHgS5IguFp/Vz2VI3U7Goh4/HA1adtwyLtSBrxYlcSYkhpAE07s4fKEcjrFxyvtQBND4vFQyQ==} + engines: {node: '>=0.10.0'} + dependencies: + is-number: file:../vendored/is-number + dev: false + /is-odd@3.0.1: resolution: {integrity: sha512-CQpnWPrDwmP1+SMHXZhtLtJv90yiyVfluGsX5iNCVkrhQtU3TQHsUWPG9wkdk9Lgd5yNpAg9jQEo90CBaXgWMA==} engines: {node: '>=4'} diff --git a/e2e/pnpm_lockfiles/v61/snapshots/defs.bzl b/e2e/pnpm_lockfiles/v61/snapshots/defs.bzl index 5b86fc5f63..6f7ebf07aa 100644 --- a/e2e/pnpm_lockfiles/v61/snapshots/defs.bzl +++ b/e2e/pnpm_lockfiles/v61/snapshots/defs.bzl @@ -20,14 +20,15 @@ load("@@aspect_rules_js~~npm~lock-__dequal__2.0.3__links//:defs.bzl load("@@aspect_rules_js~~npm~lock-__diff__at_github.com_kpdecker_jsdiff_archive_refs_tags_v5.2.0.tar.gz__links//:defs.bzl", store_13 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__fsevents__2.3.3__links//:defs.bzl", store_14 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__hello__at_gitpkg.vercel.app_EqualMa_gitpkg-hello_packages_hello__links//:defs.bzl", link_15 = "npm_link_imported_package_store", store_15 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_17 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_18 = "npm_link_imported_package_store", store_18 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_19 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_20 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_21 = "npm_link_imported_package_store", store_21 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_22 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_23 = "npm_link_imported_package_store", store_23 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__2.0.0__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_17 = "npm_link_imported_package_store", store_17 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_18 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_19 = "npm_link_imported_package_store", store_19 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_20 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_21 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_22 = "npm_link_imported_package_store", store_22 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_23 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_24 = "npm_link_imported_package_store", store_24 = "npm_imported_package_store") _LINK_PACKAGES = ["", "projects/a", "projects/b", "projects/c", "projects/d", "vendored/is-number"] @@ -67,13 +68,14 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): store_14(name = "{}/fsevents".format(name)) store_15(name = "{}/hello".format(name)) store_16(name = "{}/is-odd".format(name)) - store_17(name = "{}/kleur".format(name)) - store_18(name = "{}/meaning-of-life".format(name)) - store_19(name = "{}/mri".format(name)) - store_20(name = "{}/ms".format(name)) - store_21(name = "{}/rollup".format(name)) - store_22(name = "{}/sade".format(name)) - store_23(name = "{}/uvu".format(name)) + store_17(name = "{}/is-odd".format(name)) + store_18(name = "{}/kleur".format(name)) + store_19(name = "{}/meaning-of-life".format(name)) + store_20(name = "{}/mri".format(name)) + store_21(name = "{}/ms".format(name)) + store_22(name = "{}/rollup".format(name)) + store_23(name = "{}/sade".format(name)) + store_24(name = "{}/uvu".format(name)) if link: if bazel_package == "": link_0(name = "{}/@aspect-test/a".format(name)) @@ -99,17 +101,21 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_10(name = "{}/@types/node".format(name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) scope_targets["@types"] = scope_targets["@types"] + [link_targets[-1]] if "@types" in scope_targets else [link_targets[-1]] + link_10(name = "{}/alias-types-node".format(name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_11(name = "{}/debug".format(name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_15(name = "{}/hello".format(name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) - link_16(name = "{}/is-odd".format(name)) + link_16(name = "{}/is-odd-alt-version".format(name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) + link_17(name = "{}/is-odd".format(name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) - link_18(name = "{}/meaning-of-life".format(name)) + link_19(name = "{}/meaning-of-life".format(name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) - link_21(name = "{}/rollup".format(name)) + link_22(name = "{}/rollup".format(name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) - link_23(name = "{}/uvu".format(name)) + link_24(name = "{}/uvu".format(name)) link_targets.append("//{}:{}/uvu".format(bazel_package, name)) if is_root: @@ -293,8 +299,10 @@ def npm_link_targets(name = "node_modules", package = None): link_targets.append("//{}:{}/jsonify".format(bazel_package, name)) link_targets.append("//{}:{}/@types/archiver".format(bazel_package, name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) diff --git a/e2e/pnpm_lockfiles/v90/pnpm-lock.yaml b/e2e/pnpm_lockfiles/v90/pnpm-lock.yaml index f26434858f..d222d5a5b6 100644 --- a/e2e/pnpm_lockfiles/v90/pnpm-lock.yaml +++ b/e2e/pnpm_lockfiles/v90/pnpm-lock.yaml @@ -47,6 +47,9 @@ importers: is-odd: specifier: 3.0.1 version: 3.0.1 + is-odd-alt-version: + specifier: npm:is-odd@^2.0.0 + version: is-odd@2.0.0 jsonify: specifier: https://github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz version: '@foo/jsonify@https://github.com/aspect-build/test-packages/releases/download/0.0.0/@foo-jsonify-0.0.0.tgz' @@ -73,6 +76,9 @@ importers: '@types/node': specifier: 16.18.11 version: 16.18.11 + alias-types-node: + specifier: npm:@types/node@~16.18.11 + version: '@types/node@16.18.11' ../projects/a: {} @@ -173,6 +179,10 @@ packages: is-number@file:../vendored/is-number: resolution: {directory: ../vendored/is-number, type: directory} + is-odd@2.0.0: + resolution: {integrity: sha512-OTiixgpZAT1M4NHgS5IguFp/Vz2VI3U7Goh4/HA1adtwyLtSBrxYlcSYkhpAE07s4fKEcjrFxyvtQBND4vFQyQ==} + engines: {node: '>=0.10.0'} + is-odd@3.0.1: resolution: {integrity: sha512-CQpnWPrDwmP1+SMHXZhtLtJv90yiyVfluGsX5iNCVkrhQtU3TQHsUWPG9wkdk9Lgd5yNpAg9jQEo90CBaXgWMA==} engines: {node: '>=4'} @@ -264,6 +274,10 @@ snapshots: is-number@file:../vendored/is-number: {} + is-odd@2.0.0: + dependencies: + is-number: file:../vendored/is-number + is-odd@3.0.1: dependencies: is-number: file:../vendored/is-number diff --git a/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl b/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl index 4b579f6ed1..502e9fcc7c 100644 --- a/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl +++ b/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl @@ -20,14 +20,15 @@ load("@@aspect_rules_js~~npm~lock-__dequal__2.0.3__links//:defs.bzl load("@@aspect_rules_js~~npm~lock-__diff__https___github.com_kpdecker_jsdiff_archive_refs_tags_v5.2.0.tar.gz__links//:defs.bzl", store_13 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__fsevents__2.3.3__links//:defs.bzl", store_14 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__hello__https___gitpkg.vercel.app_EqualMa_gitpkg-hello_packages_hello__links//:defs.bzl", link_15 = "npm_link_imported_package_store", store_15 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_17 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_18 = "npm_link_imported_package_store", store_18 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_19 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_20 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_21 = "npm_link_imported_package_store", store_21 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_22 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_23 = "npm_link_imported_package_store", store_23 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__2.0.0__links//:defs.bzl", link_16 = "npm_link_imported_package_store", store_16 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_17 = "npm_link_imported_package_store", store_17 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_18 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0__o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_19 = "npm_link_imported_package_store", store_19 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_20 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_21 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__rollup__3.2.5__links//:defs.bzl", link_22 = "npm_link_imported_package_store", store_22 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_23 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_24 = "npm_link_imported_package_store", store_24 = "npm_imported_package_store") _LINK_PACKAGES = ["", "projects/a", "projects/b", "projects/c", "projects/d", "vendored/is-number"] @@ -67,13 +68,14 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): store_14(name = "{}/fsevents".format(name)) store_15(name = "{}/hello".format(name)) store_16(name = "{}/is-odd".format(name)) - store_17(name = "{}/kleur".format(name)) - store_18(name = "{}/meaning-of-life".format(name)) - store_19(name = "{}/mri".format(name)) - store_20(name = "{}/ms".format(name)) - store_21(name = "{}/rollup".format(name)) - store_22(name = "{}/sade".format(name)) - store_23(name = "{}/uvu".format(name)) + store_17(name = "{}/is-odd".format(name)) + store_18(name = "{}/kleur".format(name)) + store_19(name = "{}/meaning-of-life".format(name)) + store_20(name = "{}/mri".format(name)) + store_21(name = "{}/ms".format(name)) + store_22(name = "{}/rollup".format(name)) + store_23(name = "{}/sade".format(name)) + store_24(name = "{}/uvu".format(name)) if link: if bazel_package == "": link_0(name = "{}/@aspect-test/a".format(name)) @@ -97,17 +99,21 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_10(name = "{}/@types/node".format(name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) scope_targets["@types"] = scope_targets["@types"] + [link_targets[-1]] if "@types" in scope_targets else [link_targets[-1]] + link_10(name = "{}/alias-types-node".format(name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_11(name = "{}/debug".format(name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_15(name = "{}/hello".format(name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) - link_16(name = "{}/is-odd".format(name)) + link_16(name = "{}/is-odd-alt-version".format(name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) + link_17(name = "{}/is-odd".format(name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) - link_18(name = "{}/meaning-of-life".format(name)) + link_19(name = "{}/meaning-of-life".format(name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) - link_21(name = "{}/rollup".format(name)) + link_22(name = "{}/rollup".format(name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) - link_23(name = "{}/uvu".format(name)) + link_24(name = "{}/uvu".format(name)) link_targets.append("//{}:{}/uvu".format(bazel_package, name)) if is_root: @@ -290,8 +296,10 @@ def npm_link_targets(name = "node_modules", package = None): link_targets.append("//{}:{}/@aspect-test/e".format(bazel_package, name)) link_targets.append("//{}:{}/@types/archiver".format(bazel_package, name)) link_targets.append("//{}:{}/@types/node".format(bazel_package, name)) + link_targets.append("//{}:{}/alias-types-node".format(bazel_package, name)) link_targets.append("//{}:{}/debug".format(bazel_package, name)) link_targets.append("//{}:{}/hello".format(bazel_package, name)) + link_targets.append("//{}:{}/is-odd-alt-version".format(bazel_package, name)) link_targets.append("//{}:{}/is-odd".format(bazel_package, name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) diff --git a/npm/private/npm_translate_lock_helpers.bzl b/npm/private/npm_translate_lock_helpers.bzl index 2038ec01b6..6f0458b03c 100644 --- a/npm/private/npm_translate_lock_helpers.bzl +++ b/npm/private/npm_translate_lock_helpers.bzl @@ -255,9 +255,9 @@ def _get_npm_imports(importers, packages, patched_dependencies, only_built_depen for dep_package, dep_version in dependencies.items(): if dep_version.startswith("link:"): continue - if dep_version.startswith("/"): - # special case for alias dependencies such as /alias-to@version - maybe_package = dep_version[1:] + if dep_version.startswith("npm:"): + # special case for alias dependencies such as npm:alias-to@version + maybe_package = dep_version[4:] elif dep_version[0].isdigit(): maybe_package = utils.pnpm_name(dep_package, dep_version) else: diff --git a/npm/private/transitive_closure.bzl b/npm/private/transitive_closure.bzl index d379f3701e..27169add44 100644 --- a/npm/private/transitive_closure.bzl +++ b/npm/private/transitive_closure.bzl @@ -35,9 +35,9 @@ def gather_transitive_closure(packages, package, no_optional, cache = {}): deps = stack.pop() for name in deps.keys(): version = deps[name] - if version.startswith("/"): + if version.startswith("npm:"): # an aliased dependency - package_key = version[1:] + package_key = version[4:] name, version = utils.parse_pnpm_package_key(name, version) elif version[0].isdigit(): package_key = utils.pnpm_name(name, version) diff --git a/npm/private/utils.bzl b/npm/private/utils.bzl index ca4fb94ec0..ae90d8573d 100644 --- a/npm/private/utils.bzl +++ b/npm/private/utils.bzl @@ -66,26 +66,10 @@ def _parse_pnpm_package_key(pnpm_name, pnpm_version): if pnpm_version.startswith("link:") or pnpm_version.startswith("file:"): return pnpm_name, "0.0.0" - if not pnpm_version.startswith("/"): - if not pnpm_name: - fail("parse_pnpm_package_key: pnpm_name is empty for non-versioned package %s" % pnpm_version) + if pnpm_version.startswith("npm:"): + return pnpm_version[4:].rsplit("@", 1) - return pnpm_name, pnpm_version - - # Parse a package key such as: - # /name/version - # /@scope/name/version - # registry.com/name/version - # - # return a (name, version) tuple. This format is found in pnpm lock file v5. - # TODO: what if the registry has '/'s? - _, pnpm_version = pnpm_version.split("/", 1) - - segments = pnpm_version.rsplit("@", 1) - if len(segments) != 2: - msg = "unexpected pnpm versioned name {}".format(pnpm_version) - fail(msg) - return (segments[0], segments[1]) + return pnpm_name, pnpm_version # Metadata about a pnpm "project" (importer). # @@ -118,6 +102,12 @@ def _new_package_info(id, name, dependencies, optional_dependencies, peer_depend "resolution": resolution, } +def _strip_default_registry(name_version): + # Strip the default registry from the name_version string + if name_version.startswith(DEFAULT_REGISTRY_DOMAIN_SLASH): + return name_version[len(DEFAULT_REGISTRY_DOMAIN_SLASH):] + return name_version + def _strip_v5_default_registry_to_version(name, version): # Strip the default registry/name/ from the version string pre = DEFAULT_REGISTRY_DOMAIN_SLASH + name + "/" @@ -125,29 +115,36 @@ def _strip_v5_default_registry_to_version(name, version): return version[len(pre):] return version -def _convert_v5_importer_dependency_map(dep): +def _convert_v5_importer_dependency_map(specifiers, deps): result = {} - for name, version in dep.items(): - # conver v5 style aliases (/aliased/version) to v6+ style (/aliased@version) - if version.startswith("/"): - alias, version = version.rsplit("/", 1) - version = "{}@{}".format(alias, version) + for name, version in deps.items(): + specifier = specifiers.get(name) + + if specifier.startswith("npm:"): + # Keep the npm: specifier for aliased dependencies + # convert v5 style aliases ([default_registry]/aliased/version) to npm:aliased@version + alias, version = _strip_default_registry(version).lstrip("/").rsplit("/", 1) + version = "npm:{}@{}".format(alias, version) else: - version = _convert_pnpm_v5_version_deer_dep(_strip_v5_default_registry_to_version(name, version)) + # Transition [registry/]name/version[_patch][_peer_data] to a rules_js version format + version = _convert_pnpm_v5_version_peer_dep(_strip_v5_default_registry_to_version(name, version)) + result[name] = version return result def _convert_v5_importers(importers): result = {} for import_path, importer in importers.items(): + specifiers = importer.get("specifiers", {}) + result[import_path] = _new_import_info( - dependencies = _convert_v5_importer_dependency_map(importer.get("dependencies", {})), - dev_dependencies = _convert_v5_importer_dependency_map(importer.get("devDependencies", {})), - optional_dependencies = _convert_v5_importer_dependency_map(importer.get("optionalDependencies", {})), + dependencies = _convert_v5_importer_dependency_map(specifiers, importer.get("dependencies", {})), + dev_dependencies = _convert_v5_importer_dependency_map(specifiers, importer.get("devDependencies", {})), + optional_dependencies = _convert_v5_importer_dependency_map(specifiers, importer.get("optionalDependencies", {})), ) return result -def _convert_pnpm_v5_version_deer_dep(version): +def _convert_pnpm_v5_version_peer_dep(version): # Covert a pnpm lock file v5 version string of the format # 1.2.3_@scope+peer@2.0.2_@scope+peer@4.5.6 # to a version_peer_version that is compatible with rules_js. @@ -163,10 +160,24 @@ def _convert_pnpm_v5_version_deer_dep(version): return version +def _convert_pnpm_v5_package_dependency_version(name, version): + # an alias to an alternate package + if version.startswith("/"): + alias, version = version[1:].rsplit("@", 1) + return "npm:{}@{}".format(alias, version) + + # Removing the default registry+name from the version string + version = _strip_v5_default_registry_to_version(name, version) + + # Convert peer dependency data to rules_js ~v5 format + version = _convert_pnpm_v5_version_peer_dep(version) + + return version + def _convert_pnpm_v5_package_dependency_map(deps): result = {} for name, version in deps.items(): - result[name] = _convert_pnpm_v5_version_deer_dep(_strip_v5_default_registry_to_version(name, version)) + result[name] = _convert_pnpm_v5_package_dependency_version(name, version) return result def _convert_v5_v6_file_package(package_path, package_snapshot): @@ -192,7 +203,7 @@ def _convert_v5_packages(packages): msg = "package {} has no resolution field".format(package_path) fail(msg) - package_path = _convert_pnpm_v5_version_deer_dep(package_path) + package_path = _convert_pnpm_v5_version_peer_dep(package_path) if package_path.startswith("file:"): # direct reference to file @@ -266,23 +277,21 @@ def _strip_v6_default_registry_to_version(name, version): def _convert_pnpm_v6_importer_dependency_map(deps): result = {} for name, attributes in deps.items(): + specifier = attributes.get("specifier") version = attributes.get("version") - if version.startswith("/"): - version = version # keep aliases as-is + if specifier.startswith("npm:"): + # Keep the npm: specifier for aliased dependencies + # convert v6 style aliases ([registry]/aliased@version) to npm:aliased@version + alias, version = _strip_default_registry(version).lstrip("/").rsplit("@", 1) + version = "npm:{}@{}".format(alias, version) else: - # TODO: does not handle pnpm v9 `name: { version: realname@version }` + # Transition [registry/]name@version[(peer)(data)] to a rules_js version format version = _convert_pnpm_v6_v9_version_peer_dep(_strip_v6_default_registry_to_version(name, version)) result[name] = version return result -def _convert_pnpm_v6_v9_package_dependency_map(deps): - result = {} - for name, version in deps.items(): - result[name] = _convert_pnpm_v6_v9_version_peer_dep(_strip_v6_default_registry_to_version(name, version)) - return result - def _convert_v6_importers(importers): # Convert pnpm lockfile v6 importers to a rules_js compatible ~v5 format. # @@ -310,15 +319,32 @@ def _convert_v6_importers(importers): result = {} for import_path, importer in importers.items(): result[import_path] = _new_import_info( - # TODO: normalize edge cases such as: - # - deps with protocols - # - ? dependencies = _convert_pnpm_v6_importer_dependency_map(importer.get("dependencies", {})), dev_dependencies = _convert_pnpm_v6_importer_dependency_map(importer.get("devDependencies", {})), optional_dependencies = _convert_pnpm_v6_importer_dependency_map(importer.get("optionalDependencies", {})), ) return result +def _convert_pnpm_v6_package_dependency_version(name, version): + # an alias to an alternate package + if version.startswith("/"): + alias, version = version[1:].rsplit("@", 1) + return "npm:{}@{}".format(alias, version) + + # Removing the default registry+name from the version string + version = _strip_v6_default_registry_to_version(name, version) + + # Convert peer dependency data to rules_js ~v5 format + version = _convert_pnpm_v6_v9_version_peer_dep(version) + + return version + +def _convert_pnpm_v6_package_dependency_map(deps): + result = {} + for name, version in deps.items(): + result[name] = _convert_pnpm_v6_package_dependency_version(name, version) + return result + def _convert_v6_packages(packages): # Convert pnpm lockfile v6 importers to a rules_js compatible ~v5 format. # @@ -359,9 +385,9 @@ def _convert_v6_packages(packages): name = name, version = version, friendly_version = friendly_version, - dependencies = _convert_pnpm_v6_v9_package_dependency_map(package_snapshot.get("dependencies", {})), - peer_dependencies = _convert_pnpm_v6_v9_package_dependency_map(package_snapshot.get("peerDependencies", {})), - optional_dependencies = _convert_pnpm_v6_v9_package_dependency_map(package_snapshot.get("optionalDependencies", {})), + dependencies = _convert_pnpm_v6_package_dependency_map(package_snapshot.get("dependencies", {})), + peer_dependencies = _convert_pnpm_v6_package_dependency_map(package_snapshot.get("peerDependencies", {})), + optional_dependencies = _convert_pnpm_v6_package_dependency_map(package_snapshot.get("optionalDependencies", {})), dev = package_snapshot.get("dev", False), has_bin = package_snapshot.get("hasBin", False), optional = package_snapshot.get("optional", False), @@ -379,16 +405,47 @@ def _convert_v6_packages(packages): return result +def _convert_pnpm_v9_package_dependency_version(name, version): + # Convert peer dependency data to rules_js ~v5 format + version = _convert_pnpm_v6_v9_version_peer_dep(version) + + return version + def _convert_pnpm_v9_package_dependency_map(deps): result = {} for name, version in deps.items(): - # Otherwise assume a reference to another package@version(...maybe peers...) - result[name] = _convert_pnpm_v6_v9_version_peer_dep(version) + result[name] = _convert_pnpm_v9_package_dependency_version(name, version) + return result + +def _convert_pnpm_v9_importer_dependency_map(deps): + result = {} + for name, attributes in deps.items(): + specifier = attributes.get("specifier") + version = attributes.get("version") + + if specifier.startswith("npm:"): + # Keep the npm: specifier for aliased dependencies + alias, version = version.rsplit("@", 1) + version = "npm:{}@{}".format(alias, version) + else: + # Transition version[(patch)(peer)(data)] to a rules_js version format + version = _convert_pnpm_v6_v9_version_peer_dep(version) + result[name] = version return result -# v9 importers are the same as v6 importers -_convert_v9_importers = _convert_v6_importers +def _convert_v9_importers(importers): + # Convert pnpm lockfile v9 importers to a rules_js compatible ~v5 format. + # Almost identical to v6 but with fewer odd edge cases. + + result = {} + for import_path, importer in importers.items(): + result[import_path] = _new_import_info( + dependencies = _convert_pnpm_v9_importer_dependency_map(importer.get("dependencies", {})), + dev_dependencies = _convert_pnpm_v9_importer_dependency_map(importer.get("devDependencies", {})), + optional_dependencies = _convert_pnpm_v9_importer_dependency_map(importer.get("optionalDependencies", {})), + ) + return result def _convert_v9_packages(packages, snapshots): # Convert pnpm lockfile v9 importers to a rules_js compatible format. @@ -434,29 +491,27 @@ def _convert_v9_packages(packages, snapshots): fail(msg) # the raw name + version are the key, not including peerDeps+patch - version_index = static_key.find("@", 1) + version_index = static_key.index("@", 1) name = static_key[:version_index] - friendly_version = static_key[version_index + 1:] package_key = _convert_pnpm_v6_v9_version_peer_dep(package_key) # Extract the version including peerDeps+patch from the key - version = package_key[package_key.find("@", 1) + 1:] + version = package_key[package_key.index("@", 1) + 1:] + + # package_data can have the resolved "version" for things like https:// deps + friendly_version = package_data["version"] if "version" in package_data else static_key[version_index + 1:] # Convert the package_key to a rules_js compatible format package_key = _to_package_key(name, version) - # package_data can have the resolved "version" for things like https:// deps - if "version" in package_data: - friendly_version = package_data["version"] - package_info = _new_package_info( - id = package_data.get("id", None), + id = package_data.get("id", None), # TODO: does v9 have "id"? name = name, version = version, friendly_version = friendly_version, dependencies = _convert_pnpm_v9_package_dependency_map(package_snapshot.get("dependencies", {})), optional_dependencies = _convert_pnpm_v9_package_dependency_map(package_snapshot.get("optionalDependencies", {})), - peer_dependencies = _convert_pnpm_v9_package_dependency_map(package_data.get("peerDependencies", {})), + peer_dependencies = package_data.get("peerDependencies", {}), dev = None, # TODO(pnpm9): must inspect importers.*.devDependencies? has_bin = package_data.get("hasBin", False), optional = package_snapshot.get("optional", False),