From 3f5629888b6d26d8e03d54d0f2fc07b8747a1cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 14 Apr 2017 17:43:25 -0700 Subject: [PATCH] fix(api): use npa@5 for spec parsing (#78) BREAKING CHANGE: spec objects can no longer be realize-package-specifier objects. Pass a string or generate npa@>=5 spec objects to pass in. --- extract.js | 22 +++++----- lib/finalize-manifest.js | 2 +- lib/handlers/directory/manifest.js | 10 ++--- lib/handlers/git/manifest.js | 14 +++---- lib/handlers/local/manifest.js | 4 +- lib/handlers/local/tarball.js | 2 +- lib/handlers/remote/tarball.js | 2 +- lib/registry/manifest.js | 2 +- lib/registry/pick-manifest.js | 12 +++--- manifest.js | 67 +++++++++++++----------------- package.json | 2 +- prefetch.js | 12 +++--- test/directory.js | 2 +- test/finalize-manifest.js | 4 +- test/local.tarball.js | 6 +-- test/prefetch.js | 9 ++-- test/registry.manifest.js | 11 +---- test/registry.pick-manifest.js | 2 +- test/registry.tarball.js | 41 +++--------------- test/remote.tarball.js | 6 +-- 20 files changed, 91 insertions(+), 141 deletions(-) diff --git a/extract.js b/extract.js index b8d563d..eb71bed 100644 --- a/extract.js +++ b/extract.js @@ -4,18 +4,19 @@ const BB = require('bluebird') const cache = require('./lib/cache') const extractStream = require('./lib/extract-stream') +const npa = require('npm-package-arg') const pipe = BB.promisify(require('mississippi').pipe) const optCheck = require('./lib/util/opt-check') const retry = require('promise-retry') const rimraf = BB.promisify(require('rimraf')) -const rps = BB.promisify(require('realize-package-specifier')) module.exports = extract function extract (spec, dest, opts) { opts = optCheck(opts) + spec = typeof spec === 'string' ? npa(spec, opts.where) : spec const startTime = Date.now() if (opts.integrity && opts.cache && !opts.preferOnline) { - opts.log.silly('pacote', 'trying', spec, 'by hash:', opts.integrity.toString()) + opts.log.silly('pacote', 'trying', spec.name, 'by hash:', opts.integrity.toString()) return extractByDigest( startTime, spec, dest, opts ).catch(err => { @@ -34,7 +35,7 @@ function extract (spec, dest, opts) { } }) } else { - opts.log.silly('pacote', 'no tarball hash provided for', spec, '- extracting by manifest') + opts.log.silly('pacote', 'no tarball hash provided for', spec.name, '- extracting by manifest') return retry((tryAgain, attemptNum) => { return extractByManifest( startTime, spec, dest, opts @@ -42,7 +43,7 @@ function extract (spec, dest, opts) { // We're only going to retry at this level if the local cache might // have gotten corrupted. if (err.code === 'EINTEGRITY' && opts.cache) { - opts.log.warn('pacote', `tarball integrity check for ${spec} failed. Clearing cache entry. ${err.message}`) + opts.log.warn('pacote', `tarball integrity check for ${spec.name}@${spec.saveSpec || spec.fetchSpec} failed. Clearing cache entry. ${err.message}`) return cleanUpCached( dest, opts.cache, err.sri, opts ).then(() => tryAgain(err)) @@ -58,20 +59,17 @@ function extractByDigest (start, spec, dest, opts) { const xtractor = extractStream(dest, opts) const cached = cache.get.stream.byDigest(opts.cache, opts.integrity, opts) return pipe(cached, xtractor).then(() => { - opts.log.verbose('pacote', `${spec} extracted to ${dest} by content address ${Date.now() - start}ms`) + opts.log.verbose('pacote', `${spec.name}@${spec.saveSpec || spec.fetchSpec} extracted to ${dest} by content address ${Date.now() - start}ms`) }) } function extractByManifest (start, spec, dest, opts) { - const res = typeof spec === 'string' - ? rps(spec, opts.where) - : BB.resolve(spec) const xtractor = extractStream(dest, opts) - return res.then(res => { - const tarball = require('./lib/handlers/' + res.type + '/tarball') - return pipe(tarball(res, opts), xtractor) + return BB.resolve(() => { + const tarball = require('./lib/handlers/' + spec.type + '/tarball') + return pipe(tarball(spec, opts), xtractor) }).then(() => { - opts.log.verbose('pacote', `${res.name}@${res.spec} extracted in ${Date.now() - start}ms`) + opts.log.verbose('pacote', `${spec.name}@${spec.saveSpec || spec.fetchSpec} extracted in ${Date.now() - start}ms`) }) } diff --git a/lib/finalize-manifest.js b/lib/finalize-manifest.js index ac7da95..a0dcea8 100644 --- a/lib/finalize-manifest.js +++ b/lib/finalize-manifest.js @@ -180,7 +180,7 @@ function tarballedProps (pkg, spec, opts) { _shrinkwrap: sr, _resolved: (mani && mani._resolved) || (pkg && pkg._resolved) || - spec.spec, + spec.fetchSpec, _integrity: hash && hash.toString() }) } diff --git a/lib/handlers/directory/manifest.js b/lib/handlers/directory/manifest.js index 5c3bd77..3ff16c5 100644 --- a/lib/handlers/directory/manifest.js +++ b/lib/handlers/directory/manifest.js @@ -9,8 +9,8 @@ const readFileAsync = BB.promisify(require('fs').readFile) module.exports = manifest function manifest (spec, opts) { - const pkgPath = path.join(spec.spec, 'package.json') - const srPath = path.join(spec.spec, 'npm-shrinkwrap.json') + const pkgPath = path.join(spec.fetchSpec, 'package.json') + const srPath = path.join(spec.fetchSpec, 'npm-shrinkwrap.json') return BB.join( readFileAsync(pkgPath).then(JSON.parse).catch({code: 'ENOENT'}, err => { err.code = 'ENOPACKAGEJSON' @@ -20,16 +20,16 @@ function manifest (spec, opts) { (pkg, sr) => { pkg._shrinkwrap = sr pkg._hasShrinkwrap = !!sr - pkg._resolved = spec.spec + pkg._resolved = spec.fetchSpec pkg._integrity = false // Don't auto-calculate integrity return pkg } ).then(pkg => { if (!pkg.bin && pkg.directories && pkg.directories.bin) { const dirBin = pkg.directories.bin - return glob(path.join(spec.spec, dirBin, '/**'), {nodir: true}).then(matches => { + return glob(path.join(spec.fetchSpec, dirBin, '/**'), {nodir: true}).then(matches => { matches.forEach(filePath => { - const relative = path.relative(spec.spec, filePath) + const relative = path.relative(spec.fetchSpec, filePath) if (relative && relative[0] !== '.') { if (!pkg.bin) { pkg.bin = {} } pkg.bin[path.basename(relative)] = relative diff --git a/lib/handlers/git/manifest.js b/lib/handlers/git/manifest.js index d85499b..51c1eb9 100644 --- a/lib/handlers/git/manifest.js +++ b/lib/handlers/git/manifest.js @@ -11,27 +11,27 @@ const semver = require('semver') module.exports = manifest function manifest (spec, opts) { opts = optCheck(opts) - if (spec.hosted && spec.spec === spec.hosted.shortcut) { + if (spec.hosted && spec.hosted.getDefaultRepresentation() === 'shortcut') { return hostedManifest(spec, opts) } else { // If it's not a shortcut, don't do fallbacks. - return plainManifest(spec.spec, spec, opts) + return plainManifest(spec.fetchSpec, spec, opts) } } function hostedManifest (spec, opts) { return BB.resolve(null).then(() => { - return plainManifest(spec.hosted.httpsUrl, spec, opts) + return plainManifest(spec.hosted.https(), spec, opts) }).catch(err => { - if (!spec.hosted.ssh) { + if (!spec.hosted.ssh()) { throw err } - return plainManifest(spec.hosted.ssh, spec, opts) + return plainManifest(spec.hosted.ssh(), spec, opts) }).catch(err => { - if (!spec.hosted.gitUrl) { + if (!spec.hosted.git()) { throw err } - return plainManifest(spec.hosted.gitUrl, spec, opts) + return plainManifest(spec.hosted.git(), spec, opts) }) } diff --git a/lib/handlers/local/manifest.js b/lib/handlers/local/manifest.js index 6a1be56..e1e7083 100644 --- a/lib/handlers/local/manifest.js +++ b/lib/handlers/local/manifest.js @@ -1,7 +1,9 @@ 'use strict' +const BB = require('bluebird') + module.exports = manifest function manifest () { // The tarball handler will take care of it! - return Promise.resolve(null) + return BB.resolve(null) } diff --git a/lib/handlers/local/tarball.js b/lib/handlers/local/tarball.js index 47619b8..20e4a35 100644 --- a/lib/handlers/local/tarball.js +++ b/lib/handlers/local/tarball.js @@ -13,7 +13,7 @@ const MAX_BULK_SIZE = 2 * 1024 * 1024 // 2MB module.exports = tarball function tarball (spec, opts) { - const src = spec._resolved || spec.spec + const src = spec._resolved || spec.fetchSpec const stream = through() statAsync(src).then(stat => { if (stat.size <= MAX_BULK_SIZE) { diff --git a/lib/handlers/remote/tarball.js b/lib/handlers/remote/tarball.js index a8aa43d..9be68cd 100644 --- a/lib/handlers/remote/tarball.js +++ b/lib/handlers/remote/tarball.js @@ -4,7 +4,7 @@ const registryTarball = require('../../registry/tarball') module.exports = tarball function tarball (spec, opts) { - const uri = spec._resolved || spec.spec + const uri = spec._resolved || spec.fetchSpec return registryTarball.fromManifest({ _resolved: uri, _integrity: opts.integrity diff --git a/lib/registry/manifest.js b/lib/registry/manifest.js index 57b81b7..ba284e9 100644 --- a/lib/registry/manifest.js +++ b/lib/registry/manifest.js @@ -29,7 +29,7 @@ function manifest (spec, opts) { ) { opts.log.silly( 'registry:manifest', - `no matching version for ${spec.name}@${spec.spec} in the cache. Forcing revalidation` + `no matching version for ${spec.name}@${spec.fetchSpec} in the cache. Forcing revalidation` ) opts.preferOnline = true return manifest(spec, opts) diff --git a/lib/registry/pick-manifest.js b/lib/registry/pick-manifest.js index 0dc1440..0276c4f 100644 --- a/lib/registry/pick-manifest.js +++ b/lib/registry/pick-manifest.js @@ -22,9 +22,9 @@ function pickManifest (metadata, spec, opts) { var target if (spec.type === 'tag') { - target = distTags[spec.spec] + target = distTags[spec.fetchSpec] } else if (spec.type === 'version') { - target = spec.spec + target = spec.fetchSpec } else if (spec.type !== 'range') { return cb(new Error('Only tag, version, and range are supported')) } @@ -35,16 +35,16 @@ function pickManifest (metadata, spec, opts) { !target && tagVersion && metadata.versions[tagVersion] && - semver.satisfies(tagVersion, spec.spec, true) + semver.satisfies(tagVersion, spec.fetchSpec, true) ) { target = tagVersion } if (!target) { - target = semver.maxSatisfying(versions, spec.spec, true) + target = semver.maxSatisfying(versions, spec.fetchSpec, true) } - if (!target && spec.spec === '*') { + if (!target && spec.fetchSpec === '*') { // npm hard-codes `latest` here, but it's likely intended // to be `defaultTag`. // @@ -56,7 +56,7 @@ function pickManifest (metadata, spec, opts) { var manifest = target && metadata.versions[target] if (!manifest) { - err = new Error(`No matching version found for ${spec.name}@${spec.spec}`) + err = new Error(`No matching version found for ${spec.name}@${spec.fetchSpec}`) err.code = 'ETARGET' err.name = metadata.name err.spec = spec diff --git a/manifest.js b/manifest.js index b473a96..c825ab3 100644 --- a/manifest.js +++ b/manifest.js @@ -1,54 +1,47 @@ 'use strict' -const BB = require('bluebird') - const finalizeManifest = require('./lib/finalize-manifest') const optCheck = require('./lib/util/opt-check') const pinflight = require('promise-inflight') -const rps = BB.promisify(require('realize-package-specifier')) +const npa = require('npm-package-arg') let handlers = {} module.exports = manifest function manifest (spec, opts) { opts = optCheck(opts) + spec = typeof spec === 'string' ? npa(spec, opts.where) : spec - const res = typeof spec === 'string' - ? rps(spec, opts.where) - : BB.resolve(spec) - - return res.then(res => { - const label = [ - res.raw, - res.spec, - res.type, - opts.cache, - opts.registry, - opts.scope - ].join(':') - return pinflight(label, () => { - const startTime = Date.now() - const fetcher = ( - handlers[res.type] || - ( - handlers[res.type] = - require('./lib/handlers/' + res.type + '/manifest') - ) + const label = [ + spec.name, + spec.saveSpec || spec.fetchSpec, + spec.type, + opts.cache, + opts.registry, + opts.scope + ].join(':') + return pinflight(label, () => { + const startTime = Date.now() + const fetcher = ( + handlers[spec.type] || + ( + handlers[spec.type] = + require('./lib/handlers/' + spec.type + '/manifest') ) - return fetcher(res, opts).then(manifest => { - return finalizeManifest(manifest, res, opts) - }).then(manifest => { - // Metadata about the way this manifest was requested - if (opts.annotate) { - manifest._requested = res - manifest._spec = spec - manifest._where = opts.where - } + ) + return fetcher(spec, opts).then(manifest => { + return finalizeManifest(manifest, spec, opts) + }).then(manifest => { + // Metadata about the way this manifest was requested + if (opts.annotate) { + manifest._requested = spec + manifest._spec = spec.raw + manifest._where = opts.where + } - const elapsedTime = Date.now() - startTime - opts.log.verbose('pacote', `${res.type} manifest for ${res.name}@${res.spec} fetched in ${elapsedTime}ms`) - return manifest - }) + const elapsedTime = Date.now() - startTime + opts.log.verbose('pacote', `${spec.type} manifest for ${spec.name}@${spec.saveSpec || spec.fetchSpec} fetched in ${elapsedTime}ms`) + return manifest }) }) } diff --git a/package.json b/package.json index 674eba8..69fa4e3 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,10 @@ "mississippi": "^1.2.0", "normalize-git-url": "^3.0.2", "normalize-package-data": "^2.3.6", + "npm-package-arg": "^5.0.0", "osenv": "^0.1.4", "promise-inflight": "^1.0.1", "promise-retry": "^1.1.1", - "realize-package-specifier": "^3.0.3", "semver": "^5.3.0", "ssri": "^4.1.1", "tar-fs": "^1.15.1", diff --git a/prefetch.js b/prefetch.js index 158e4c8..aefbe0b 100644 --- a/prefetch.js +++ b/prefetch.js @@ -5,11 +5,12 @@ const BB = require('bluebird') const cache = require('./lib/cache') const finished = BB.promisify(require('mississippi').finished) const optCheck = require('./lib/util/opt-check') -const rps = BB.promisify(require('realize-package-specifier')) +const npa = require('npm-package-arg') module.exports = prefetch function prefetch (spec, opts) { opts = optCheck(opts) + spec = typeof spec === 'string' ? npa(spec, opts.where) : spec const startTime = Date.now() if (!opts.cache) { opts.log.info('prefetch', 'skipping prefetch: no cache provided') @@ -36,20 +37,17 @@ function prefetch (spec, opts) { } function prefetchByManifest (start, spec, opts) { - const res = typeof spec === 'string' - ? rps(spec, opts.where) - : BB.resolve(spec) let manifest let integrity - return res.then(res => { - const stream = require('./lib/handlers/' + res.type + '/tarball')(res, opts) + return BB.resolve().then(() => { + const stream = require('./lib/handlers/' + spec.type + '/tarball')(spec, opts) if (!stream) { return } stream.on('data', function () {}) stream.on('manifest', m => { manifest = m }) stream.on('integrity', i => { integrity = i }) return finished(stream) }).then(() => { - opts.log.verbose('prefetch', `${spec} done in ${Date.now() - start}ms`) + opts.log.verbose('prefetch', `${spec.name}@${spec.saveSpec || spec.fetchSpec} done in ${Date.now() - start}ms`) return { manifest, spec, diff --git a/test/directory.js b/test/directory.js index 90f8151..b9f7ae5 100644 --- a/test/directory.js +++ b/test/directory.js @@ -51,7 +51,7 @@ test('supports directory deps', t => { bundleDependencies: false, peerDependencies: {}, deprecated: false, - _resolved: path.resolve(PKG), + _resolved: path.resolve(PKG).replace(/\\/g, '/'), _integrity: null, _shrinkwrap: sr, bin: { mybin: path.join('x', 'mybin') }, diff --git a/test/finalize-manifest.js b/test/finalize-manifest.js index 090aa87..5bcee08 100644 --- a/test/finalize-manifest.js +++ b/test/finalize-manifest.js @@ -223,7 +223,7 @@ test('uses package.json as base if passed null', t => { }).then(tarData => { tnock(t, OPTS.registry).get('/' + tarballPath).reply(200, tarData) return finalizeManifest(null, { - spec: OPTS.registry + tarballPath, + fetchSpec: OPTS.registry + tarballPath, type: 'remote' }, OPTS).then(manifest => { t.deepEqual(manifest, { @@ -279,7 +279,7 @@ test('caches finalized manifests', t => { t.ok(true, 'manifest entry exists in cache: ' + k) } }) - return Promise.all(promises) + return BB.all(promises) }).then(() => { return finalizeManifest(base, { name: base.name, diff --git a/test/local.tarball.js b/test/local.tarball.js index 20eea2a..0783513 100644 --- a/test/local.tarball.js +++ b/test/local.tarball.js @@ -5,6 +5,7 @@ const BB = require('bluebird') const finished = BB.promisify(require('mississippi').finished) const fs = BB.promisifyAll(require('fs')) const mockTar = require('./util/mock-tarball') +const npa = require('npm-package-arg') const npmlog = require('npmlog') const path = require('path') const test = require('tap').test @@ -31,10 +32,7 @@ test('basic tarball streaming', function (t) { return fs.writeFileAsync(tarballPath, tarData).then(() => { let data = '' return finished( - tarball({ - type: 'local', - spec: tarballPath - }, OPTS).on('data', d => { data += d }) + tarball(npa(tarballPath), OPTS).on('data', d => { data += d }) ).then(() => { t.equal(data, tarData, 'fetched tarball data matches one from local') }) diff --git a/test/prefetch.js b/test/prefetch.js index f39f731..dba1dd5 100644 --- a/test/prefetch.js +++ b/test/prefetch.js @@ -2,6 +2,7 @@ const cache = require('../lib/cache') const mockTar = require('./util/mock-tarball') +const npa = require('npm-package-arg') const npmlog = require('npmlog') const ssri = require('ssri') const test = require('tap').test @@ -71,7 +72,7 @@ test('prefetch by manifest if no integrity hash', t => { byDigest: false, integrity: BASE._integrity, manifest: BASE, - spec: 'foo@1.0.0' + spec: npa('foo@1.0.0') }, 'fresh fetch info returned') return cache.ls(CACHE) }).then(result => { @@ -84,7 +85,7 @@ test('skip if no cache is provided', t => { cache.clearMemoized() return prefetch('foo@1.0.0', {}).then(info => { t.deepEqual(info, { - spec: 'foo@1.0.0' + spec: npa('foo@1.0.0') }, 'no cache -> only spec returned') return cache.ls(CACHE) }).then(result => { @@ -104,7 +105,7 @@ test('use cache content if found', t => { }).then(info => { t.deepEqual(info, { manifest: BASE, - spec: 'foo@1.0.0', + spec: npa('foo@1.0.0'), integrity: BASE._integrity, // if coming from cache, get integrity byDigest: false }, '') @@ -129,7 +130,7 @@ test('prefetch by manifest if digest provided but no cache content found', t => byDigest: false, integrity: BASE._integrity, manifest: BASE, - spec: 'foo@1.0.0' + spec: npa('foo@1.0.0') }, 'fresh fetch info returned') t.equal(srv.isDone(), true) return cache.ls(CACHE) diff --git a/test/registry.manifest.js b/test/registry.manifest.js index 97d6e21..d280315 100644 --- a/test/registry.manifest.js +++ b/test/registry.manifest.js @@ -2,6 +2,7 @@ const BB = require('bluebird') +const npa = require('npm-package-arg') const npmlog = require('npmlog') const test = require('tap').test const tnock = require('./util/tnock') @@ -322,15 +323,7 @@ test('optionally annotates manifest with request-related metadata', t => { where: 'right here' } const annotated = new Manifest(BASE) - annotated._requested = { - escapedName: 'foo', - name: 'foo', - raw: 'foo@1.2.3', - rawSpec: '1.2.3', - scope: null, - spec: '1.2.3', - type: 'version' - } + annotated._requested = npa('foo@1.2.3') annotated._spec = 'foo@1.2.3' annotated._where = opts.where diff --git a/test/registry.pick-manifest.js b/test/registry.pick-manifest.js index 77b3417..9206b03 100644 --- a/test/registry.pick-manifest.js +++ b/test/registry.pick-manifest.js @@ -7,7 +7,7 @@ const test = require('tap').test const pickManifest = require('../lib/registry/pick-manifest') function spec (selector, type) { - return { spec: selector, type: type || 'range' } + return { fetchSpec: selector, type: type || 'range' } } test('basic carat range selection', t => { diff --git a/test/registry.tarball.js b/test/registry.tarball.js index c9e0fc0..983401e 100644 --- a/test/registry.tarball.js +++ b/test/registry.tarball.js @@ -4,6 +4,7 @@ const BB = require('bluebird') const finished = BB.promisify(require('mississippi').finished) const mockTar = require('./util/mock-tarball') +const npa = require('npm-package-arg') const npmlog = require('npmlog') const ssri = require('ssri') const test = require('tap').test @@ -58,15 +59,7 @@ test('basic tarball streaming', function (t) { srv.get('/foo/-/foo-1.2.3.tgz').reply(200, tarData) let data = '' return finished( - tarball({ - type: 'range', - raw: 'foo@^1.2.3', - name: 'foo', - escapedName: 'foo', - rawSpec: '^1.2.3', - spec: '>=1.2.3 <2.0.0', - scope: null - }, OPTS).on('data', d => { data += d }) + tarball(npa('foo@^1.2.3'), OPTS).on('data', d => { data += d }) ).then(() => { t.equal(data, tarData, 'fetched tarball data matches one from server') }) @@ -85,15 +78,7 @@ test('errors if manifest fails', t => { var srv = tnock(t, OPTS.registry) srv.get('/foo').reply(200, META(tarData)) srv.get('/foo/-/foo-1.2.3.tgz').reply(404) - return finished(tarball({ - type: 'range', - raw: 'foo@^1.2.3', - name: 'foo', - escapedName: 'foo', - rawSpec: '^1.2.3', - spec: '>=1.2.3 <2.0.0', - scope: null - }, OPTS).on('data', () => {})).then(() => { + return finished(tarball(npa('foo@^1.2.3'), OPTS).on('data', () => {})).then(() => { throw new Error('this was not supposed to succeed') }).catch(err => { t.ok(err, 'correctly errored') @@ -116,15 +101,7 @@ test('tarball url updated to fit registry protocol', t => { srv.get('/foo/-/foo-1.2.3.tgz').reply(200, tarData) let data = '' return finished( - tarball({ - type: 'range', - raw: 'foo@^1.2.3', - name: 'foo', - escapedName: 'foo', - rawSpec: '^1.2.3', - spec: '>=1.2.3 <2.0.0', - scope: null - }, OPTS).on('data', d => { data += d }) + tarball(npa('foo@^1.2.3'), OPTS).on('data', d => { data += d }) ).then(() => { t.equal(data, tarData, 'fetched tarball from https server') }) @@ -145,15 +122,7 @@ test('tarball url updated to fit registry protocol+port', t => { srv.get('/foo/-/foo-1.2.3.tgz').reply(200, tarData) let data = '' return finished( - tarball({ - type: 'range', - raw: 'foo@^1.2.3', - name: 'foo', - escapedName: 'foo', - rawSpec: '^1.2.3', - spec: '>=1.2.3 <2.0.0', - scope: null - }, OPTS).on('data', d => { data += d }) + tarball(npa('foo@^1.2.3'), OPTS).on('data', d => { data += d }) ).then(() => { t.equal(data, tarData, 'fetched tarball from https server and adjusted port') }) diff --git a/test/remote.tarball.js b/test/remote.tarball.js index c083e3d..34b226e 100644 --- a/test/remote.tarball.js +++ b/test/remote.tarball.js @@ -4,6 +4,7 @@ const BB = require('bluebird') const finished = BB.promisify(require('mississippi').finished) const mockTar = require('./util/mock-tarball') +const npa = require('npm-package-arg') const npmlog = require('npmlog') const test = require('tap').test const tnock = require('./util/tnock') @@ -38,10 +39,7 @@ test('basic tarball streaming', function (t) { srv.get(tarballPath).reply(200, tarData) let data = '' return finished( - tarball({ - type: 'remote', - spec: OPTS.registry + tarballPath.slice(1) - }, OPTS).on('data', d => { data += d }) + tarball(npa(OPTS.registry + tarballPath.slice(1)), OPTS).on('data', d => { data += d }) ).then(() => { t.equal(data, tarData, 'fetched tarball data matches one from server') })