mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
fix: registry set in lockfile resolution should not be ignored
ref #2687 PR #2733
This commit is contained in:
5
.changeset/moody-humans-jam.md
Normal file
5
.changeset/moody-humans-jam.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lockfile-utils": patch
|
||||
---
|
||||
|
||||
When getting resolution from package snapshot, always prefer the registry that is present in the package snapshot.
|
||||
@@ -12,27 +12,23 @@ export default (
|
||||
registries: Registries
|
||||
): Resolution => {
|
||||
// tslint:disable:no-string-literal
|
||||
if (pkgSnapshot.resolution['type']) {
|
||||
return pkgSnapshot.resolution as Resolution
|
||||
}
|
||||
if (!pkgSnapshot.resolution['tarball']) {
|
||||
const { name } = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
|
||||
const registry = name[0] === '@' && registries[name.split('/')[0]] || registries.default
|
||||
return {
|
||||
...pkgSnapshot.resolution,
|
||||
registry,
|
||||
tarball: getTarball(registry),
|
||||
} as Resolution
|
||||
}
|
||||
if (pkgSnapshot.resolution['tarball'].startsWith('file:')) {
|
||||
if (pkgSnapshot.resolution['type'] || pkgSnapshot.resolution['tarball']?.startsWith('file:')) {
|
||||
return pkgSnapshot.resolution as Resolution
|
||||
}
|
||||
const { name } = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
|
||||
const registry = name[0] === '@' && registries[name.split('/')[0]] || registries.default
|
||||
const registry = pkgSnapshot.resolution['registry']
|
||||
|| (name[0] === '@' && registries[name.split('/')[0]])
|
||||
|| registries.default
|
||||
let tarball!: string
|
||||
if (!pkgSnapshot.resolution['tarball']) {
|
||||
tarball = getTarball(registry)
|
||||
} else {
|
||||
tarball = url.resolve(registry, pkgSnapshot.resolution['tarball'])
|
||||
}
|
||||
return {
|
||||
...pkgSnapshot.resolution,
|
||||
registry,
|
||||
tarball: url.resolve(registry, pkgSnapshot.resolution['tarball']),
|
||||
tarball,
|
||||
} as Resolution
|
||||
|
||||
function getTarball (registry: string) {
|
||||
|
||||
@@ -23,5 +23,17 @@ test('pkgSnapshotToResolution()', (t) => {
|
||||
tarball: 'https://mycompany.jfrog.io/mycompany/api/npm/npm-local/@mycompany/mypackage/-/@mycompany/mypackage-2.0.0.tgz',
|
||||
})
|
||||
|
||||
t.deepEqual(pkgSnapshotToResolution('/foo/1.0.0', {
|
||||
resolution: {
|
||||
integrity: 'AAAA',
|
||||
registry: 'https://npm.pkg.github.com/',
|
||||
tarball: 'https://npm.pkg.github.com/download/@foo/bar/1.0.0/aaa',
|
||||
},
|
||||
}, { default: 'https://registry.npmjs.org/' }), {
|
||||
integrity: 'AAAA',
|
||||
registry: 'https://npm.pkg.github.com/',
|
||||
tarball: 'https://npm.pkg.github.com/download/@foo/bar/1.0.0/aaa',
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user