fix(fix-lockfile): crash on tarballs (#7404)

close  #7368
This commit is contained in:
Khải
2023-12-13 06:01:31 +07:00
committed by GitHub
parent 418866ac07
commit d5a176af77
5 changed files with 27 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/resolve-dependencies": patch
"@pnpm/lockfile-utils": patch
"pnpm": patch
---
Fix a bug where `--fix-lockfile` crashes on tarballs [#7368](https://github.com/pnpm/pnpm/issues/7368).

View File

@@ -212,6 +212,7 @@
"sels",
"semistrict",
"serverjs",
"sheetjs",
"sindresorhus",
"sirv",
"soporan",

View File

@@ -20,7 +20,15 @@ export function pkgSnapshotToResolution (
return pkgSnapshot.resolution as Resolution
}
const { name } = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
const registry: string = (name[0] === '@' && registries[name.split('/')[0]]) || registries.default
let registry: string = ''
if (name != null) {
if (name.startsWith('@')) {
registry = registries[name.split('/')[0]]
}
}
if (!registry) {
registry = registries.default
}
let tarball!: string
if (!(pkgSnapshot.resolution as TarballResolution).tarball) {
tarball = getTarball(registry)

View File

@@ -29,4 +29,12 @@ test('pkgSnapshotToResolution()', () => {
integrity: 'AAAA',
tarball: 'https://mycompany.jfrog.io/mycompany/api/npm/npm-local/@mycompany/mypackage/-/@mycompany/mypackage-2.0.0.tgz',
})
expect(pkgSnapshotToResolution('@cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz', {
resolution: {
tarball: 'https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz',
},
}, { default: 'https://registry.npmjs.org/' })).toEqual({
tarball: 'https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz',
})
})

View File

@@ -1039,12 +1039,13 @@ async function resolveDependency (
currentLockfileContainsTheDep &&
currentPkg.depPath &&
currentPkg.dependencyLockfile &&
currentPkg.name &&
await exists(
path.join(
ctx.virtualStoreDir,
dp.depPathToFilename(currentPkg.depPath),
'node_modules',
currentPkg.name!,
currentPkg.name,
'package.json'
)
)