fix(shrinkwrap): save non-default registries in resolution field

This commit is contained in:
Zoltan Kochan
2018-03-15 23:38:54 +02:00
parent a59c0be17d
commit e6ea9d4aee
2 changed files with 19 additions and 0 deletions

View File

@@ -179,16 +179,19 @@ function toShrResolution (
if (dp.isAbsolute(relDepPath) || resolution.type !== undefined || !resolution['integrity']) {
return resolution as ShrinkwrapResolution
}
const base = registry !== resolution['registry'] ? {registry: resolution['registry']} : {}
// Sometimes packages are hosted under non-standard tarball URLs.
// For instance, when they are hosted on npm Enterprise. See https://github.com/pnpm/pnpm/issues/867
// Or in othere weird cases, like https://github.com/pnpm/pnpm/issues/1072
if (getNpmTarballUrl(pkg.name, pkg.version, {registry}) !== resolution['tarball']) {
return {
...base,
integrity: resolution['integrity'],
tarball: relativeTarball(resolution['tarball'], registry),
}
}
return {
...base,
integrity: resolution['integrity'],
}
// tslint:enable:no-string-literal

View File

@@ -844,3 +844,19 @@ test('save tarball URL when it is non-standard', async (t: tape.Test) => {
t.equal(shr.packages['/esprima-fb/3001.1.0-dev-harmony-fb'].resolution.tarball, '/esprima-fb/-/esprima-fb-3001.0001.0000-dev-harmony-fb.tgz')
})
test('when package registry differs from default one, save it to resolution field', async (t: tape.Test) => {
const project = prepare(t)
await installPkgs(['@zkochan/git-config', 'is-positive'], await testDefaults({
rawNpmConfig: {
'@zkochan:registry': 'https://registry.node-modules.io/',
'registry': 'https://registry.npmjs.org/',
},
registry: 'https://registry.npmjs.org/',
}))
const shr = await project.loadShrinkwrap()
t.equal(shr.packages['/@zkochan/git-config/0.1.0'].resolution.registry, 'https://registry.node-modules.io/')
})