Skip to content

Commit d9e38a4

Browse files
authored
fix(npm): support pnpm v9.7+ patches without version specifier (#2059)
Fix #2031
1 parent e55422e commit d9e38a4

File tree

8 files changed

+71
-2
lines changed

8 files changed

+71
-2
lines changed

e2e/pnpm_lockfiles/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ PNPM_LOCK_TEST_CASES = [
1919
"isaacs-cliui-v90.yaml",
2020
"docusaurus-direct-peer-v6.yaml",
2121
"docusaurus-direct-peer-v9.yaml",
22+
"versionless-patch-v9.yaml",
2223
]
2324

2425
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7")

e2e/pnpm_lockfiles/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ cases run on each of those lockfiles.
1212
- `override-with-alias-url-v9` - a package overridden with a different package
1313
- `tarball-no-url-v54` - a package with a tarball but not a full URL
1414
- `docusaurus-direct-peer-v*` - a direct dependency with a (peer=123) in the `importers` including within `npm:` dependencies
15+
- `versionless-patch-v9`: pnpm v9.7+ allows patches without a version specifier

e2e/pnpm_lockfiles/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PNPM_LOCK_TEST_CASES = [
1818
"isaacs-cliui-v90.yaml",
1919
"docusaurus-direct-peer-v6.yaml",
2020
"docusaurus-direct-peer-v9.yaml",
21+
"versionless-patch-v9.yaml",
2122
]
2223

2324
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
@@ -70,6 +71,7 @@ load("@docusaurus-direct-peer-v9//:repositories.bzl", npm_repositories_direct_wi
7071
load("@isaacs-cliui-v90//:repositories.bzl", npm_repositories_isaacs_cliui_v90 = "npm_repositories")
7172
load("@override-with-alias-url-v9//:repositories.bzl", npm_repositories_override_with_alias_v90 = "npm_repositories")
7273
load("@tarball-no-url-v54//:repositories.bzl", npm_repositories_tarball_no_url_v54 = "npm_repositories")
74+
load("@versionless-patch-v9//:repositories.bzl", npm_repositories_versionless_patch_v9 = "npm_repositories")
7375

7476
npm_repositories_tarball_no_url_v54()
7577

@@ -80,3 +82,5 @@ npm_repositories_isaacs_cliui_v90()
8082
npm_repositories_direct_with_peers_v6()
8183

8284
npm_repositories_direct_with_peers_v9()
85+
86+
npm_repositories_versionless_patch_v9()

e2e/pnpm_lockfiles/cases/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_test")
12
load("@bazel_skylib//rules:build_test.bzl", "build_test")
23
load("@docusaurus-direct-peer-v6//:defs.bzl", docusaurus_direct_with_peers_v6_link_all = "npm_link_all_packages")
34
load("@docusaurus-direct-peer-v9//:defs.bzl", docusaurus_direct_with_peers_v9_link_all = "npm_link_all_packages")
45
load("@isaacs-cliui-v90//:defs.bzl", isaacs_cliui_v90_link_all = "npm_link_all_packages")
56
load("@override-with-alias-url-v9//:defs.bzl", override_with_alias_link_all = "npm_link_all_packages")
67
load("@tarball-no-url-v54//:defs.bzl", tarball_no_url_link_all = "npm_link_all_packages")
8+
load("@versionless-patch-v9//:defs.bzl", versionless_patch_link_all = "npm_link_all_packages")
79

810
exports_files(glob(["*.yaml"]))
911

@@ -52,3 +54,21 @@ build_test(
5254
# ":docusaurus_direct_with_peers_v6-modules/@docusaurus/module-type-aliases",
5355
],
5456
)
57+
58+
versionless_patch_link_all(name = "versionless_patch_link_all-modules")
59+
60+
build_test(
61+
name = "versionless_patch_targets",
62+
targets = [
63+
":versionless_patch_link_all-modules",
64+
":versionless_patch_link_all-modules/@aspect-test/e",
65+
],
66+
)
67+
68+
js_test(
69+
name = "versionless_patch_test",
70+
data = [
71+
":versionless_patch_link_all-modules/@aspect-test/e",
72+
],
73+
entry_point = "versionless-patch.spec.js",
74+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/index.js b/index.js
2+
index 0e29dc2..6ae6e90 100644
3+
--- a/index.js
4+
+++ b/index.js
5+
@@ -1,4 +1,5 @@
6+
const packageJson = require('./package.json')
7+
module.exports = {
8+
id: () => `${packageJson.name}@${packageJson.version}`,
9+
+ PATCHED: 123,
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
lockfileVersion: '9.0'
2+
3+
settings:
4+
autoInstallPeers: true
5+
excludeLinksFromLockfile: false
6+
7+
patchedDependencies:
8+
'@aspect-test/e':
9+
hash: nc75t5kilw6vcobzaxylgmmg74
10+
path: patches/aspect-test-e-pnpm.patch
11+
12+
importers:
13+
.:
14+
dependencies:
15+
'@aspect-test/e':
16+
specifier: ^1.0.0
17+
version: 1.0.0(patch_hash=nc75t5kilw6vcobzaxylgmmg74)
18+
19+
packages:
20+
'@aspect-test/e@1.0.0':
21+
resolution:
22+
{
23+
integrity: sha512-GyAxHYKN650db+xnimHnL2LPz65ilmQsVhCasWA7drDNQn/rfmPiEVMzjRiS7m46scXIERaBmiJMzYDf0bIUbA==,
24+
}
25+
hasBin: true
26+
27+
snapshots:
28+
'@aspect-test/e@1.0.0(patch_hash=nc75t5kilw6vcobzaxylgmmg74)': {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const libE = require('@aspect-test/e')
2+
3+
if (libE.PATCHED !== 123) {
4+
throw new Error('Failed to patch @aspect-test/e')
5+
}

npm/private/npm_translate_lock_helpers.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def _get_npm_imports(importers, packages, patched_dependencies, only_built_depen
327327

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

330-
pnpm_patch = patched_dependencies.get(friendly_name, {}).get("path", None)
330+
pnpm_patch = patched_dependencies.get(friendly_name, patched_dependencies.get(name, None))
331331
pnpm_patched = pnpm_patch != None
332332

333333
if len(translate_patches) > 0 and pnpm_patched:
@@ -340,7 +340,7 @@ ERROR: can not apply both `pnpm.patchedDependencies` and `npm_translate_lock(pat
340340

341341
# Apply patch from `pnpm.patchedDependencies` first
342342
if pnpm_patched:
343-
patch_path = "//%s:%s" % (attr.pnpm_lock.package, pnpm_patch)
343+
patch_path = "//%s:%s" % (attr.pnpm_lock.package, pnpm_patch.get("path"))
344344
patches.append(patch_path)
345345

346346
# pnpm patches are always applied with -p1

0 commit comments

Comments
 (0)