diff options
Diffstat (limited to 'deps/npm/node_modules/pacote/lib/finalize-manifest.js')
-rw-r--r-- | deps/npm/node_modules/pacote/lib/finalize-manifest.js | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/deps/npm/node_modules/pacote/lib/finalize-manifest.js b/deps/npm/node_modules/pacote/lib/finalize-manifest.js index cd303a9fa3..321b37cdca 100644 --- a/deps/npm/node_modules/pacote/lib/finalize-manifest.js +++ b/deps/npm/node_modules/pacote/lib/finalize-manifest.js @@ -6,18 +6,17 @@ const cacache = require('cacache') const cacheKey = require('./util/cache-key') const fetchFromManifest = require('./fetch').fromManifest const finished = BB.promisify(require('mississippi').finished) -const gunzip = require('./util/gunzip-maybe') const minimatch = require('minimatch') const normalize = require('normalize-package-data') const optCheck = require('./util/opt-check') const path = require('path') const pipe = BB.promisify(require('mississippi').pipe) const ssri = require('ssri') -const tar = require('tar-stream') +const tar = require('tar') // `finalizeManifest` takes as input the various kinds of manifests that -// manifest handlers ('lib/handlers/*/manifest.js') return, and makes sure they -// are: +// manifest handlers ('lib/fetchers/*.js#manifest()') return, and makes sure +// they are: // // * filled out with any required data that the handler couldn't fill in // * formatted consistently @@ -149,23 +148,23 @@ function tarballedProps (pkg, spec, opts) { } else { opts = optCheck(opts) const tarStream = fetchFromManifest(pkg, spec, opts) - const extracted = needsExtract && tar.extract() - extracted && extracted.on('entry', (h, str, next) => { - // Drain it - str.on('data', () => {}).on('end', next).on('error', next) - }) + const extracted = needsExtract && new tar.Parse() return BB.join( needsShrinkwrap && jsonFromStream('npm-shrinkwrap.json', extracted), needsManifest && jsonFromStream('package.json', extracted), needsBin && getPaths(extracted), needsHash && ssri.fromStream(tarStream, { algorithms: ['sha1'] }), - needsExtract && pipe(tarStream, gunzip(), extracted), + needsExtract && pipe(tarStream, extracted), (sr, mani, paths, hash) => { + if (needsManifest && !mani) { + const err = new Error(`Non-registry package missing package.json: ${spec}.`) + err.code = 'ENOPACKAGEJSON' + throw err + } const extraProps = mani || {} delete extraProps._resolved // drain out the rest of the tarball - tarStream.unpipe() - tarStream.on('data', () => {}) + tarStream.resume() // if we have directories.bin, we need to collect any matching files // to add to bin if (paths && paths.length) { @@ -199,25 +198,22 @@ function tarballedProps (pkg, spec, opts) { function jsonFromStream (filename, dataStream) { return BB.fromNode(cb => { dataStream.on('error', cb) - dataStream.on('finish', cb) - dataStream.on('entry', function handler (header, stream, next) { - const filePath = header.name.replace(/[^/]+\//, '') + dataStream.on('close', cb) + dataStream.on('entry', entry => { + const filePath = entry.header.path.replace(/[^/]+\//, '') if (filePath !== filename) { - next() + entry.resume() } else { let data = '' - stream.on('data', d => { data += d }) - stream.on('error', cb) - finished(stream).then(() => { - dataStream.removeListener('entry', handler) + entry.on('data', d => { data += d }) + entry.on('error', cb) + finished(entry).then(() => { try { cb(null, JSON.parse(data)) - next() } catch (err) { cb(err) } }, err => { - dataStream.removeListener('entry', handler) cb(err) }) } @@ -229,12 +225,11 @@ function getPaths (dataStream) { return BB.fromNode(cb => { let paths = [] dataStream.on('error', cb) - dataStream.on('finish', () => cb(null, paths)) - dataStream.on('entry', function handler (header, stream, next) { - const filePath = header.name.replace(/[^/]+\//, '') - stream.on('data', () => {}) + dataStream.on('close', () => cb(null, paths)) + dataStream.on('entry', function handler (entry) { + const filePath = entry.header.path.replace(/[^/]+\//, '') + entry.resume() paths.push(filePath) - next() }) }) } |