fix(lockfile-to-pnp): ensure packageLocation ends in trailing slash (#9905)

Discovered via https://github.com/pnpm/pnpm/issues/9904.
PnP expects `packageLocation` to end in a trailing slash, this commit ensures that.
This commit is contained in:
Simon Knott
2025-08-27 02:07:27 +02:00
committed by GitHub
parent affdd5b5b9
commit 77d5b178d9
3 changed files with 16 additions and 6 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/lockfile-to-pnp": patch
"pnpm": patch
---
Fix `.pnp.cjs` crash when importing subpath [#9904](https://github.com/pnpm/pnpm/issues/9904).

View File

@@ -95,6 +95,9 @@ export function lockfileToPackageRegistry (
if (!packageLocation.startsWith('../')) {
packageLocation = `./${packageLocation}`
}
if (!packageLocation.endsWith('/')) {
packageLocation += '/'
}
packageStore.set(pnpVersion, {
packageDependencies: new Map([
[name, pnpVersion],

View File

@@ -129,7 +129,7 @@ test('lockfileToPackageRegistry', () => {
['dep1', '1.0.0'],
['dep2', ['foo', '2.0.0']],
],
packageLocation: './node_modules/.pnpm/dep1@1.0.0/node_modules/dep1',
packageLocation: './node_modules/.pnpm/dep1@1.0.0/node_modules/dep1/',
},
],
],
@@ -144,7 +144,7 @@ test('lockfileToPackageRegistry', () => {
['foo', '2.0.0'],
['qar', '3.0.0'],
],
packageLocation: './node_modules/.pnpm/foo@2.0.0/node_modules/foo',
packageLocation: './node_modules/.pnpm/foo@2.0.0/node_modules/foo/',
},
],
],
@@ -158,7 +158,7 @@ test('lockfileToPackageRegistry', () => {
packageDependencies: [
['qar', '2.0.0'],
],
packageLocation: './node_modules/.pnpm/qar@2.0.0/node_modules/qar',
packageLocation: './node_modules/.pnpm/qar@2.0.0/node_modules/qar/',
},
],
[
@@ -167,7 +167,7 @@ test('lockfileToPackageRegistry', () => {
packageDependencies: [
['qar', '3.0.0'],
],
packageLocation: './node_modules/.pnpm/qar@3.0.0/node_modules/qar',
packageLocation: './node_modules/.pnpm/qar@3.0.0/node_modules/qar/',
},
],
],
@@ -265,7 +265,7 @@ test('lockfileToPackageRegistry packages that have peer deps', () => {
['haspeer', 'virtual:2.0.0(peer@1.0.0)#2.0.0'],
['peer', '1.0.0'],
],
packageLocation: './node_modules/.pnpm/haspeer@2.0.0_peer@1.0.0/node_modules/haspeer',
packageLocation: './node_modules/.pnpm/haspeer@2.0.0_peer@1.0.0/node_modules/haspeer/',
},
],
],
@@ -279,7 +279,7 @@ test('lockfileToPackageRegistry packages that have peer deps', () => {
packageDependencies: [
['peer', '1.0.0'],
],
packageLocation: './node_modules/.pnpm/peer@1.0.0/node_modules/peer',
packageLocation: './node_modules/.pnpm/peer@1.0.0/node_modules/peer/',
},
],
],