From e6ea9d4aeec4c28cd6ff75c8b871d9dc8420903f Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Thu, 15 Mar 2018 23:38:54 +0200 Subject: [PATCH] fix(shrinkwrap): save non-default registries in resolution field --- src/link/updateShrinkwrap.ts | 3 +++ test/shrinkwrap.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/link/updateShrinkwrap.ts b/src/link/updateShrinkwrap.ts index 7f1fa88441..855c72d032 100644 --- a/src/link/updateShrinkwrap.ts +++ b/src/link/updateShrinkwrap.ts @@ -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 diff --git a/test/shrinkwrap.ts b/test/shrinkwrap.ts index b2c5a8fc97..eee033b1b8 100644 --- a/test/shrinkwrap.ts +++ b/test/shrinkwrap.ts @@ -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/') +})