diff --git a/package.json b/package.json index a89d0fc231..252fc56bb1 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "find-up": "2.1.0", "fs-write-stream-atomic": "1.0.10", "get-link-target": "1.0.0", + "get-npm-tarball-url": "1.0.0", "global-bin-path": "0.1.1", "graceful-fs": "4.1.11", "is-ci": "1.0.10", diff --git a/src/install/fetch.ts b/src/install/fetch.ts index 4b868b6c3a..dfc273aadf 100644 --- a/src/install/fetch.ts +++ b/src/install/fetch.ts @@ -9,6 +9,8 @@ import resolve, { PackageMeta, } from '../resolve' import mkdirp = require('mkdirp-promise') +import getNpmTarballUrl from 'get-npm-tarball-url' +import registryUrl = require('registry-url') import readPkg from '../fs/readPkg' import exists = require('path-exists') import memoize, {MemoizedFunc} from '../memoize' @@ -69,6 +71,9 @@ export default async function fetch ( if (resolveResult.package) { fetchingPkg = Promise.resolve(resolveResult.package) } + } else if (resolution.type === undefined && resolution.tarball === undefined) { + const parts = pkgId!.split('/') + resolution.tarball = getNpmTarballUrl(parts[1], parts[2], {registry: registryUrl()}) } const id = pkgId diff --git a/src/install/installMultiple.ts b/src/install/installMultiple.ts index 58f8559120..2b6bcd59c6 100644 --- a/src/install/installMultiple.ts +++ b/src/install/installMultiple.ts @@ -211,7 +211,10 @@ async function install ( const shortId = pkgShortId(fetchedPkg.id, ctx.shrinkwrap.registry) ctx.shrinkwrap.packages[shortId] = ctx.shrinkwrap.packages[shortId] || {} - ctx.shrinkwrap.packages[shortId].resolution = fetchedPkg.resolution + ctx.shrinkwrap.packages[shortId].resolution = Object.assign({}, fetchedPkg.resolution) + if (shortId.startsWith('/') && ctx.shrinkwrap.packages[shortId].resolution.type === undefined) { + delete ctx.shrinkwrap.packages[shortId].resolution['tarball'] + } const pkg = await fetchedPkg.fetchingPkg diff --git a/test/shrinkwrap.ts b/test/shrinkwrap.ts index f3fd1779ae..598712c96b 100644 --- a/test/shrinkwrap.ts +++ b/test/shrinkwrap.ts @@ -29,7 +29,7 @@ test('shrinkwrap file has correct format', async t => { t.ok(shr.packages[id].dependencies, `has dependency resolutions for ${id}`) t.ok(shr.packages[id].dependencies['dep-of-pkg-with-1-dep'], `has dependency resolved for ${id}`) t.ok(shr.packages[id].resolution, `has resolution for ${id}`) - t.equal(shr.packages[id].resolution.tarball, 'http://localhost:4873/pkg-with-1-dep/-/pkg-with-1-dep-100.0.0.tgz', `has tarball for ${id}`) + t.ok(!shr.packages[id].resolution.tarball, `has no tarball for package in the default registry`) }) test('fail when shasum from shrinkwrap does not match with the actual one', async t => {