From dd7df9aa02ede2c9b8beb5d0da898a3fa7b242c8 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Tue, 15 Oct 2024 20:38:52 -0700 Subject: [PATCH] fix(npm): pnpm v9 file: archive references Fix https://github.com/aspect-build/rules_js/issues/1977 --- e2e/pnpm_lockfiles/v90/snapshots/defs.bzl | 118 +++++++------------- npm/private/npm_translate_lock_generate.bzl | 2 +- npm/private/pnpm.bzl | 20 ++-- 3 files changed, 56 insertions(+), 84 deletions(-) diff --git a/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl b/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl index 6b3fdb2ec..177b5e11e 100644 --- a/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl +++ b/e2e/pnpm_lockfiles/v90/snapshots/defs.bzl @@ -42,25 +42,26 @@ load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.0__links//:defs.bzl load("@@aspect_rules_js~~npm~lock-__is-odd__3.0.1__links//:defs.bzl", link_39 = "npm_link_imported_package_store", store_39 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__jquery__https___codeload.github.com_jquery_jquery_tar.gz_e61fccb9d736235b4b011f89cba6866bc0b8997d__links//:defs.bzl", link_40 = "npm_link_imported_package_store", store_40 = "npm_imported_package_store") load("@@aspect_rules_js~~npm~lock-__kleur__4.1.5__links//:defs.bzl", store_41 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0_o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_42 = "npm_link_imported_package_store", store_42 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_43 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_44 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__path-parse__1.0.7__links//:defs.bzl", store_45 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__picomatch__2.3.1__links//:defs.bzl", store_46 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__resolve__1.22.8__links//:defs.bzl", store_47 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__rollup__2.14.0__links//:defs.bzl", link_48 = "npm_link_imported_package_store", store_48 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__rollup__3.29.4__links//:defs.bzl", link_49 = "npm_link_imported_package_store", store_49 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_50 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__string-width__4.2.3__links//:defs.bzl", store_51 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__string-width__5.1.2__links//:defs.bzl", store_52 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__strip-ansi__6.0.1__links//:defs.bzl", store_53 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__strip-ansi__7.1.0__links//:defs.bzl", store_54 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__supports-preserve-symlinks-flag__1.0.0__links//:defs.bzl", store_55 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__tslib__2.8.0__links//:defs.bzl", link_56 = "npm_link_imported_package_store", store_56 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__typescript__5.5.2__links//:defs.bzl", link_57 = "npm_link_imported_package_store", store_57 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_58 = "npm_link_imported_package_store", store_58 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__wrap-ansi__7.0.0__links//:defs.bzl", store_59 = "npm_imported_package_store") -load("@@aspect_rules_js~~npm~lock-__wrap-ansi__8.1.0__links//:defs.bzl", store_60 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__lodash__4.17.21__links//:defs.bzl", store_42 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__meaning-of-life__1.0.0_o3deharooos255qt5xdujc3cuq__links//:defs.bzl", link_43 = "npm_link_imported_package_store", store_43 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__mri__1.2.0__links//:defs.bzl", store_44 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__ms__0.7.3__links//:defs.bzl", store_45 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__path-parse__1.0.7__links//:defs.bzl", store_46 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__picomatch__2.3.1__links//:defs.bzl", store_47 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__resolve__1.22.8__links//:defs.bzl", store_48 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__rollup__2.14.0__links//:defs.bzl", link_49 = "npm_link_imported_package_store", store_49 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__rollup__3.29.4__links//:defs.bzl", link_50 = "npm_link_imported_package_store", store_50 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__sade__1.8.1__links//:defs.bzl", store_51 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__string-width__4.2.3__links//:defs.bzl", store_52 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__string-width__5.1.2__links//:defs.bzl", store_53 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__strip-ansi__6.0.1__links//:defs.bzl", store_54 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__strip-ansi__7.1.0__links//:defs.bzl", store_55 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__supports-preserve-symlinks-flag__1.0.0__links//:defs.bzl", store_56 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__tslib__2.8.0__links//:defs.bzl", link_57 = "npm_link_imported_package_store", store_57 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__typescript__5.5.2__links//:defs.bzl", link_58 = "npm_link_imported_package_store", store_58 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__uvu__0.5.6__links//:defs.bzl", link_59 = "npm_link_imported_package_store", store_59 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__wrap-ansi__7.0.0__links//:defs.bzl", store_60 = "npm_imported_package_store") +load("@@aspect_rules_js~~npm~lock-__wrap-ansi__8.1.0__links//:defs.bzl", store_61 = "npm_imported_package_store") # buildifier: disable=bzl-visibility load("@aspect_rules_js//js:defs.bzl", _js_library = "js_library") @@ -136,25 +137,26 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): store_39(name = "{}/is-odd".format(name)) store_40(name = "{}/jquery".format(name)) store_41(name = "{}/kleur".format(name)) - store_42(name = "{}/meaning-of-life".format(name)) - store_43(name = "{}/mri".format(name)) - store_44(name = "{}/ms".format(name)) - store_45(name = "{}/path-parse".format(name)) - store_46(name = "{}/picomatch".format(name)) - store_47(name = "{}/resolve".format(name)) - store_48(name = "{}/rollup".format(name)) + store_42(name = "{}/lodash".format(name)) + store_43(name = "{}/meaning-of-life".format(name)) + store_44(name = "{}/mri".format(name)) + store_45(name = "{}/ms".format(name)) + store_46(name = "{}/path-parse".format(name)) + store_47(name = "{}/picomatch".format(name)) + store_48(name = "{}/resolve".format(name)) store_49(name = "{}/rollup".format(name)) - store_50(name = "{}/sade".format(name)) - store_51(name = "{}/string-width".format(name)) + store_50(name = "{}/rollup".format(name)) + store_51(name = "{}/sade".format(name)) store_52(name = "{}/string-width".format(name)) - store_53(name = "{}/strip-ansi".format(name)) + store_53(name = "{}/string-width".format(name)) store_54(name = "{}/strip-ansi".format(name)) - store_55(name = "{}/supports-preserve-symlinks-flag".format(name)) - store_56(name = "{}/tslib".format(name)) - store_57(name = "{}/typescript".format(name)) - store_58(name = "{}/uvu".format(name)) - store_59(name = "{}/wrap-ansi".format(name)) + store_55(name = "{}/strip-ansi".format(name)) + store_56(name = "{}/supports-preserve-symlinks-flag".format(name)) + store_57(name = "{}/tslib".format(name)) + store_58(name = "{}/typescript".format(name)) + store_59(name = "{}/uvu".format(name)) store_60(name = "{}/wrap-ansi".format(name)) + store_61(name = "{}/wrap-ansi".format(name)) if link: if bazel_package == "": link_4(name = "{}/@aspect-test-a-bad-scope".format(name)) @@ -247,17 +249,17 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): link_targets.append("//{}:{}/is-odd-alias".format(bazel_package, name)) link_40(name = "{}/jquery-git-ssh-e61fccb".format(name)) link_targets.append("//{}:{}/jquery-git-ssh-e61fccb".format(bazel_package, name)) - link_42(name = "{}/meaning-of-life".format(name)) + link_43(name = "{}/meaning-of-life".format(name)) link_targets.append("//{}:{}/meaning-of-life".format(bazel_package, name)) - link_48(name = "{}/rollup".format(name)) + link_49(name = "{}/rollup".format(name)) link_targets.append("//{}:{}/rollup".format(bazel_package, name)) - link_49(name = "{}/rollup3".format(name)) + link_50(name = "{}/rollup3".format(name)) link_targets.append("//{}:{}/rollup3".format(bazel_package, name)) - link_56(name = "{}/tslib".format(name)) + link_57(name = "{}/tslib".format(name)) link_targets.append("//{}:{}/tslib".format(bazel_package, name)) - link_57(name = "{}/typescript".format(name)) + link_58(name = "{}/typescript".format(name)) link_targets.append("//{}:{}/typescript".format(bazel_package, name)) - link_58(name = "{}/uvu".format(name)) + link_59(name = "{}/uvu".format(name)) link_targets.append("//{}:{}/uvu".format(bazel_package, name)) if is_root: @@ -309,38 +311,6 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): tags = ["manual"], ) - if is_root: - _npm_package_store( - name = ".aspect_rules_js/{}/lodash@0.0.0".format(name), - src = "//vendored/lodash-4.17.21.tgz:pkg", - package = "lodash", - version = "0.0.0", - deps = {}, - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - for link_package in [""]: - if link_package == bazel_package: - # terminal target for direct dependencies - _npm_link_package_store( - name = "{}/lodash".format(name), - src = "//:.aspect_rules_js/{}/lodash@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 = "{}/lodash/dir".format(name), - srcs = [":{}/lodash".format(name)], - output_group = "package_directory", - visibility = ["//visibility:public"], - tags = ["manual"], - ) - link_targets.append(":{}/lodash".format(name)) - if is_root: _npm_package_store( name = ".aspect_rules_js/{}/@scoped+a@0.0.0".format(name), @@ -547,10 +517,6 @@ def npm_link_targets(name = "node_modules", package = None): if link_package == bazel_package: link_targets.append("//{}:{}/@scoped/c".format(bazel_package, name)) - for link_package in [""]: - if link_package == bazel_package: - link_targets.append("//{}:{}/lodash".format(bazel_package, name)) - for link_package in ["", "projects/b", "projects/c", "projects/d"]: if link_package == bazel_package: link_targets.append("//{}:{}/@scoped/a".format(bazel_package, name)) diff --git a/npm/private/npm_translate_lock_generate.bzl b/npm/private/npm_translate_lock_generate.bzl index b85445ae1..6b12df1f6 100644 --- a/npm/private/npm_translate_lock_generate.bzl +++ b/npm/private/npm_translate_lock_generate.bzl @@ -166,7 +166,7 @@ sh_binary( dep_path = helpers.link_package(root_package, dep_version[len("file:"):]) dep_key = "{}+{}".format(dep_package, dep_version) if not dep_key in fp_links.keys(): - msg = "Expected to file: referenced package {} in first-party links".format(dep_key) + msg = "Expected file: referenced package {} in first-party links {}".format(dep_key, fp_links.keys()) fail(msg) fp_links[dep_key]["link_packages"][link_package] = [] elif dep_version.startswith("link:"): diff --git a/npm/private/pnpm.bzl b/npm/private/pnpm.bzl index 92b563bd8..df42c5a44 100644 --- a/npm/private/pnpm.bzl +++ b/npm/private/pnpm.bzl @@ -5,7 +5,7 @@ load(":utils.bzl", "DEFAULT_REGISTRY_DOMAIN_SLASH", "utils") def _is_vendored_tarfile(package_snapshot): if "resolution" in package_snapshot: - return "tarball" in package_snapshot["resolution"] + return "tarball" in package_snapshot["resolution"] and package_snapshot["resolution"]["tarball"].startswith("file:") return False def _to_package_key(name, version): @@ -461,9 +461,9 @@ def _convert_v9_packages(packages, snapshots): result = {} # Snapshots contains the packages with the keys (which include peers) to return - for package_key, package_snapshot in snapshots.items(): - peer_meta_index = package_key.find("(") - static_key = package_key[:peer_meta_index] if peer_meta_index > 0 else package_key + for package_path, package_snapshot in snapshots.items(): + peer_meta_index = package_path.find("(") + static_key = package_path[:peer_meta_index] if peer_meta_index > 0 else package_path if not static_key in packages: msg = "package {} not found in pnpm 'packages'".format(static_key) fail(msg) @@ -474,17 +474,23 @@ def _convert_v9_packages(packages, snapshots): msg = "package {} has no resolution field".format(static_key) fail(msg) - # the raw name + version are the key, not including peerDeps+patch + package_key = _convert_pnpm_v6_v9_version_peer_dep(package_path) + + # the raw name + version are the static_key, not including peerDeps+patch version_index = static_key.index("@", 1) name = static_key[:version_index] - package_key = _convert_pnpm_v6_v9_version_peer_dep(package_key) - # Extract the version including peerDeps+patch from the key + # Extract the version including peerDeps+patch from the package_key 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:] + # direct reference to tarball files: use the friendly_version to align with pnpm