Skip to content

Commit

Permalink
feat: support pnpm lock v9 (#1679)
Browse files Browse the repository at this point in the history
Close #1652
  • Loading branch information
jbedard authored May 14, 2024
1 parent 4db6bd0 commit 3528874
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 7 deletions.
1 change: 1 addition & 0 deletions e2e/pnpm_lockfiles/.bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ projects/c/node_modules
v54/node_modules/
v60/node_modules/
v61/node_modules/
v90/node_modules/
2 changes: 2 additions & 0 deletions e2e/pnpm_lockfiles/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ npm = use_extension(
"v54",
"v60",
"v61",
"v90",
]
]

Expand All @@ -52,5 +53,6 @@ npm = use_extension(
"v54",
"v60",
"v61",
"v90",
]
]
4 changes: 4 additions & 0 deletions e2e/pnpm_lockfiles/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
"v54",
"v60",
"v61",
"v90",
]
]

load("@lock-v54//:repositories.bzl", npm_repositories_v54 = "npm_repositories")
load("@lock-v60//:repositories.bzl", npm_repositories_v60 = "npm_repositories")
load("@lock-v61//:repositories.bzl", npm_repositories_v61 = "npm_repositories")
load("@lock-v90//:repositories.bzl", npm_repositories_v90 = "npm_repositories")

npm_repositories_v54()

npm_repositories_v60()

npm_repositories_v61()

npm_repositories_v90()
5 changes: 4 additions & 1 deletion e2e/pnpm_lockfiles/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"pnpm": {
"patchedDependencies": {
"meaning-of-life@1.0.0": "patches/meaning-of-life@1.0.0-pnpm.patch"
}
},
"onlyBuildDependencies": [
"@aspect-test/c"
]
}
}
4 changes: 4 additions & 0 deletions e2e/pnpm_lockfiles/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# 5.4 - pnpm v7.0.0 bumped the lockfile version to 5.4
# 6.0 - pnpm v8.0.0 bumped the lockfile version to 6.0; this included breaking changes
# 6.1 - pnpm v8.6.0 bumped the lockfile version to 6.1
# 9.0 - pnpm v9.0.0 bumped the lockfile version to 9.0; this includes breaking changes regarding lifecycle hooks and patches

mv v54/pnpm-lock.yaml base && pushd base && npx pnpm@^7.0 install --lockfile-only && mv pnpm-lock.yaml ../v54/ && popd

# pnpm v8.0.0 bumped the lockfile version to 6.0, 8.6.0 bumped it to 6.1 which was then reverted to 6.0
# while still presenting minor differences from <8.6.0.
mv v60/pnpm-lock.yaml base && pushd base && npx pnpm@8.5.1 install --lockfile-only && mv pnpm-lock.yaml ../v60/ && popd
mv v61/pnpm-lock.yaml base && pushd base && npx pnpm@8.6.0 install --lockfile-only && mv pnpm-lock.yaml ../v61/ && popd

# pnpm v9.0.0 bumped the lockfile version to 9.0
mv v90/pnpm-lock.yaml base && pushd base && npx pnpm@^9.0 install --lockfile-only && mv pnpm-lock.yaml ../v90 && popd
6 changes: 6 additions & 0 deletions e2e/pnpm_lockfiles/v90/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@lock-v90//:defs.bzl", "npm_link_all_packages")
load("//:lockfile-test.bzl", "lockfile_test")

npm_link_all_packages()

lockfile_test()
1 change: 1 addition & 0 deletions e2e/pnpm_lockfiles/v90/package.json
1 change: 1 addition & 0 deletions e2e/pnpm_lockfiles/v90/patches
172 changes: 172 additions & 0 deletions e2e/pnpm_lockfiles/v90/pnpm-lock.yaml

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

6 changes: 4 additions & 2 deletions npm/private/npm_translate_lock_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def _get_npm_imports(importers, packages, patched_dependencies, only_built_depen
optional_deps = package_info.get("optional_dependencies")
dev = package_info.get("dev")
optional = package_info.get("optional")
pnpm_patched = package_info.get("patched")
requires_build = package_info.get("requires_build")
transitive_closure = package_info.get("transitive_closure")
resolution = package_info.get("resolution")
Expand Down Expand Up @@ -331,6 +330,9 @@ def _get_npm_imports(importers, packages, patched_dependencies, only_built_depen

translate_patches, patches_keys = _gather_values_from_matching_names(True, attr.patches, name, friendly_name, unfriendly_name)

pnpm_patch = patched_dependencies.get(friendly_name, {}).get("path", None)
pnpm_patched = pnpm_patch != None

if len(translate_patches) > 0 and pnpm_patched:
msg = """\
ERROR: can not apply both `pnpm.patchedDependencies` and `npm_translate_lock(patches)` to the same package {pkg}.
Expand All @@ -341,7 +343,7 @@ ERROR: can not apply both `pnpm.patchedDependencies` and `npm_translate_lock(pat

# Apply patch from `pnpm.patchedDependencies` first
if pnpm_patched:
patch_path = "//%s:%s" % (attr.pnpm_lock.package, patched_dependencies.get(friendly_name).get("path"))
patch_path = "//%s:%s" % (attr.pnpm_lock.package, pnpm_patch)
patches.append(patch_path)

# pnpm patches are always applied with -p1
Expand Down
3 changes: 2 additions & 1 deletion npm/private/test/utils_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ def test_version_supported(ctx):
msg = utils.assert_lockfile_version(1.2, testonly = True)
asserts.equals(env, "npm_translate_lock requires lock_version at least 5.4, but found 1.2. Please upgrade to pnpm v7 or greater.", msg)
msg = utils.assert_lockfile_version(99.99, testonly = True)
asserts.equals(env, "npm_translate_lock currently supports a maximum lock_version of 6.1, but found 99.99. Please file an issue on rules_js", msg)
asserts.equals(env, "npm_translate_lock currently supports a maximum lock_version of 9.0, but found 99.99. Please file an issue on rules_js", msg)

# supported versions
utils.assert_lockfile_version(5.4)
utils.assert_lockfile_version(6.0)
utils.assert_lockfile_version(6.1)
utils.assert_lockfile_version(9.0)

return unittest.end(env)

Expand Down
1 change: 0 additions & 1 deletion npm/private/transitive_closure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def _gather_package_info(package_path, package_snapshot):
"optional_dependencies": package_snapshot.get("optionalDependencies", {}),
"dev": package_snapshot.get("dev", False),
"optional": package_snapshot.get("optional", False),
"patched": package_snapshot.get("patched", False),
"has_bin": package_snapshot.get("hasBin", False),
"requires_build": package_snapshot.get("requiresBuild", False),
}
Expand Down
Loading

0 comments on commit 3528874

Please sign in to comment.