diff options
Diffstat (limited to 'deps/npm/node_modules/pacote/lib')
22 files changed, 300 insertions, 389 deletions
diff --git a/deps/npm/node_modules/pacote/lib/extract-stream.js b/deps/npm/node_modules/pacote/lib/extract-stream.js index d7e8fd5a18..d967b9f897 100644 --- a/deps/npm/node_modules/pacote/lib/extract-stream.js +++ b/deps/npm/node_modules/pacote/lib/extract-stream.js @@ -57,6 +57,7 @@ function extractStream (spec, dest, opts) { onwarn: msg => opts.log && opts.log.warn('tar', msg), uid: opts.uid, gid: opts.gid, + umask: opts.umask, transform: opts.resolved && pkgJsonTransform(spec, opts), onentry (entry) { if (entry.type.toLowerCase() === 'file') { diff --git a/deps/npm/node_modules/pacote/lib/fetch.js b/deps/npm/node_modules/pacote/lib/fetch.js index 5c45fa21df..36fb6b6d3d 100644 --- a/deps/npm/node_modules/pacote/lib/fetch.js +++ b/deps/npm/node_modules/pacote/lib/fetch.js @@ -3,13 +3,20 @@ const duck = require('protoduck') const Fetcher = duck.define(['spec', 'opts', 'manifest'], { + packument: ['spec', 'opts'], manifest: ['spec', 'opts'], tarball: ['spec', 'opts'], fromManifest: ['manifest', 'spec', 'opts'], clearMemoized () {} -}, {name: 'Fetcher'}) +}, { name: 'Fetcher' }) module.exports = Fetcher +module.exports.packument = packument +function packument (spec, opts) { + const fetcher = getFetcher(spec.type) + return fetcher.packument(spec, opts) +} + module.exports.manifest = manifest function manifest (spec, opts) { const fetcher = getFetcher(spec.type) @@ -40,6 +47,9 @@ function getFetcher (type) { // This is spelled out both to prevent sketchy stuff and to make life // easier for bundlers/preprocessors. switch (type) { + case 'alias': + fetchers[type] = require('./fetchers/alias') + break case 'directory': fetchers[type] = require('./fetchers/directory') break diff --git a/deps/npm/node_modules/pacote/lib/fetchers/alias.js b/deps/npm/node_modules/pacote/lib/fetchers/alias.js new file mode 100644 index 0000000000..f22cbb1d7c --- /dev/null +++ b/deps/npm/node_modules/pacote/lib/fetchers/alias.js @@ -0,0 +1,24 @@ +'use strict' + +const Fetcher = require('../fetch') +const fetchRegistry = require('./registry') + +const fetchRemote = module.exports = Object.create(null) + +Fetcher.impl(fetchRemote, { + packument (spec, opts) { + return fetchRegistry.packument(spec.subSpec, opts) + }, + + manifest (spec, opts) { + return fetchRegistry.manifest(spec.subSpec, opts) + }, + + tarball (spec, opts) { + return fetchRegistry.tarball(spec.subSpec, opts) + }, + + fromManifest (manifest, spec, opts) { + return fetchRegistry.fromManifest(manifest, spec.subSpec, opts) + } +}) diff --git a/deps/npm/node_modules/pacote/lib/fetchers/directory.js b/deps/npm/node_modules/pacote/lib/fetchers/directory.js index f6e680f660..83f3d7d558 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/directory.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/directory.js @@ -14,16 +14,31 @@ const readFileAsync = BB.promisify(require('fs').readFile) const fetchDirectory = module.exports = Object.create(null) Fetcher.impl(fetchDirectory, { + packument (spec, opts) { + return this.manifest(spec, opts).then(manifest => { + return Object.assign({}, manifest, { + 'dist-tags': { + 'latest': manifest.version + }, + time: { + [manifest.version]: (new Date()).toISOString() + }, + versions: { + [manifest.version]: manifest + } + }) + }) + }, // `directory` manifests come from the actual manifest/lockfile data. manifest (spec, opts) { 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 => { + readFileAsync(pkgPath).then(JSON.parse).catch({ code: 'ENOENT' }, err => { err.code = 'ENOPACKAGEJSON' throw err }), - readFileAsync(srPath).then(JSON.parse).catch({code: 'ENOENT'}, () => null), + readFileAsync(srPath).then(JSON.parse).catch({ code: 'ENOENT' }, () => null), (pkg, sr) => { pkg._shrinkwrap = sr pkg._hasShrinkwrap = !!sr @@ -35,7 +50,7 @@ Fetcher.impl(fetchDirectory, { ).then(pkg => { if (!pkg.bin && pkg.directories && pkg.directories.bin) { const dirBin = pkg.directories.bin - return glob(path.join(spec.fetchSpec, dirBin, '/**'), {nodir: true}).then(matches => { + return glob(path.join(spec.fetchSpec, dirBin, '/**'), { nodir: true }).then(matches => { matches.forEach(filePath => { const relative = path.relative(spec.fetchSpec, filePath) if (relative && relative[0] !== '.') { diff --git a/deps/npm/node_modules/pacote/lib/fetchers/file.js b/deps/npm/node_modules/pacote/lib/fetchers/file.js index 5688cd1bdd..a58e329130 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/file.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/file.js @@ -17,6 +17,10 @@ const MAX_BULK_SIZE = 2 * 1024 * 1024 // 2MB const fetchFile = module.exports = Object.create(null) Fetcher.impl(fetchFile, { + packument (spec, opts) { + return BB.reject(new Error('Not implemented yet')) + }, + manifest (spec, opts) { // We can't do much here. `finalizeManifest` will take care of // calling `tarball` to fill out all the necessary details. @@ -39,9 +43,9 @@ Fetcher.impl(fetchFile, { opts.cache, `pacote:tarball:file:${src}`, data, { integrity: opts.integrity } - ).then(integrity => ({data, integrity})) + ).then(integrity => ({ data, integrity })) } else { - return {data} + return { data } } }).then(info => { if (info.integrity) { stream.emit('integrity', info.integrity) } @@ -64,7 +68,7 @@ Fetcher.impl(fetchFile, { return pipe(fs.createReadStream(src), stream) }) } - }, err => stream.emit('error', err)) + }).catch(err => stream.emit('error', err)) return stream }, diff --git a/deps/npm/node_modules/pacote/lib/fetchers/git.js b/deps/npm/node_modules/pacote/lib/fetchers/git.js index 66a2093ee3..7db4a79de3 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/git.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/git.js @@ -21,6 +21,10 @@ const uniqueFilename = require('unique-filename') const fetchGit = module.exports = Object.create(null) Fetcher.impl(fetchGit, { + packument (spec, opts) { + return BB.reject(new Error('Not implemented yet.')) + }, + manifest (spec, opts) { opts = optCheck(opts) if (spec.hosted && spec.hosted.getDefaultRepresentation() === 'shortcut') { @@ -41,7 +45,7 @@ Fetcher.impl(fetchGit, { manifest, spec, opts ).on('integrity', i => stream.emit('integrity', i)), stream ) - }, err => stream.emit('error', err)) + }).catch(err => stream.emit('error', err)) return stream }, @@ -153,7 +157,7 @@ function resolve (url, spec, name, opts) { function withTmp (opts, cb) { if (opts.cache) { // cacache has a special facility for working in a tmp dir - return cacache.tmp.withTmp(opts.cache, {tmpPrefix: 'git-clone'}, cb) + return cacache.tmp.withTmp(opts.cache, { tmpPrefix: 'git-clone', uid: opts.uid, gid: opts.gid }, cb) } else { const tmpDir = path.join(osenv.tmpdir(), 'pacote-git-tmp') const tmpName = uniqueFilename(tmpDir, 'git-clone') diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/check-warning-header.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/check-warning-header.js deleted file mode 100644 index b17a233d43..0000000000 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/check-warning-header.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict' - -const LRU = require('lru-cache') - -const WARNING_REGEXP = /^\s*(\d{3})\s+(\S+)\s+"(.*)"\s+"([^"]+)"/ -const BAD_HOSTS = new LRU({ max: 50 }) - -module.exports = checkWarnings -function checkWarnings (res, registry, opts) { - if (res.headers.has('warning') && !BAD_HOSTS.has(registry)) { - const warnings = {} - res.headers.raw()['warning'].forEach(w => { - const match = w.match(WARNING_REGEXP) - if (match) { - warnings[match[1]] = { - code: match[1], - host: match[2], - message: match[3], - date: new Date(match[4]) - } - } - }) - BAD_HOSTS.set(registry, true) - if (warnings['199']) { - if (warnings['199'].message.match(/ENOTFOUND/)) { - opts.log.warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`) - } else { - opts.log.warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`) - } - } - if (warnings['111']) { - // 111 Revalidation failed -- we're using stale data - opts.log.warn( - 'registry', - `Using stale package data from ${registry} due to a request error during revalidation.` - ) - } - } -} diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/fetch.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/fetch.js deleted file mode 100644 index 3a2a4a5a77..0000000000 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/fetch.js +++ /dev/null @@ -1,109 +0,0 @@ -'use strict' - -const BB = require('bluebird') -const Buffer = require('safe-buffer').Buffer - -const checkWarnings = require('./check-warning-header') -const fetch = require('make-fetch-happen') -const registryKey = require('./registry-key') -const url = require('url') - -module.exports = regFetch -function regFetch (uri, registry, opts) { - const startTime = Date.now() - return fetch(uri, { - agent: opts.agent, - algorithms: opts.algorithms, - cache: getCacheMode(opts), - cacheManager: opts.cache, - ca: opts.ca, - cert: opts.cert, - headers: getHeaders(uri, registry, opts), - integrity: opts.integrity, - key: opts.key, - localAddress: opts.localAddress, - maxSockets: opts.maxSockets, - memoize: opts.memoize, - noProxy: opts.noProxy, - Promise: BB, - proxy: opts.proxy, - referer: opts.refer, - retry: opts.retry, - strictSSL: !!opts.strictSSL, - timeout: opts.timeout, - uid: opts.uid, - gid: opts.gid - }).then(res => { - if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) { - opts.log.warn('notice', res.headers.get('npm-notice')) - } - checkWarnings(res, registry, opts) - if (res.status >= 400) { - const err = new Error(`${res.status} ${res.statusText}: ${ - opts.spec ? opts.spec : uri - }`) - err.code = `E${res.status}` - err.uri = uri - err.response = res - err.spec = opts.spec - logRequest(uri, res, startTime, opts) - throw err - } else { - res.body.on('end', () => logRequest(uri, res, startTime, opts)) - return res - } - }) -} - -function logRequest (uri, res, startTime, opts) { - const elapsedTime = Date.now() - startTime - const attempt = res.headers.get('x-fetch-attempts') - const attemptStr = attempt && attempt > 1 ? ` attempt #${attempt}` : '' - const cacheStr = res.headers.get('x-local-cache') ? ' (from cache)' : '' - opts.log.http( - 'fetch', - `GET ${res.status} ${uri} ${elapsedTime}ms${attemptStr}${cacheStr}` - ) -} - -function getCacheMode (opts) { - return opts.offline - ? 'only-if-cached' - : opts.preferOffline - ? 'force-cache' - : opts.preferOnline - ? 'no-cache' - : 'default' -} - -function getHeaders (uri, registry, opts) { - const headers = Object.assign({ - 'npm-in-ci': opts.isFromCI, - 'npm-scope': opts.projectScope, - 'npm-session': opts.npmSession, - 'user-agent': opts.userAgent, - 'referer': opts.refer - }, opts.headers) - // check for auth settings specific to this registry - let auth = ( - opts.auth && - opts.auth[registryKey(registry)] - ) || opts.auth - // If a tarball is hosted on a different place than the manifest, only send - // credentials on `alwaysAuth` - const shouldAuth = auth && ( - auth.alwaysAuth || - url.parse(uri).host === url.parse(registry).host - ) - if (shouldAuth && auth.token) { - headers.authorization = `Bearer ${auth.token}` - } else if (shouldAuth && auth.username && auth.password) { - const encoded = Buffer.from( - `${auth.username}:${auth.password}`, 'utf8' - ).toString('base64') - headers.authorization = `Basic ${encoded}` - } else if (shouldAuth && auth._auth) { - headers.authorization = `Basic ${auth._auth}` - } - return headers -} diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/index.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/index.js index 78bdc23426..2cca7040bd 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/index.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/registry/index.js @@ -3,11 +3,16 @@ const cacache = require('cacache') const Fetcher = require('../../fetch') const regManifest = require('./manifest') +const regPackument = require('./packument') const regTarball = require('./tarball') const fetchRegistry = module.exports = Object.create(null) Fetcher.impl(fetchRegistry, { + packument (spec, opts) { + return regPackument(spec, opts) + }, + manifest (spec, opts) { return regManifest(spec, opts) }, @@ -22,6 +27,6 @@ Fetcher.impl(fetchRegistry, { clearMemoized () { cacache.clearMemoized() - regManifest.clearMemoized() + regPackument.clearMemoized() } }) diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/manifest.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/manifest.js index 4e5a8010e2..d29ec71c33 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/manifest.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/registry/manifest.js @@ -1,56 +1,48 @@ 'use strict' -const BB = require('bluebird') - -const fetch = require('./fetch') -const LRU = require('lru-cache') +const fetch = require('npm-registry-fetch') +const fetchPackument = require('./packument') const optCheck = require('../../util/opt-check') const pickManifest = require('npm-pick-manifest') -const pickRegistry = require('./pick-registry') const ssri = require('ssri') -const url = require('url') - -// Corgis are cute. 🐕🐶 -const CORGI_DOC = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*' -const JSON_DOC = 'application/json' module.exports = manifest function manifest (spec, opts) { opts = optCheck(opts) - const registry = pickRegistry(spec, opts) - const uri = metadataUrl(registry, spec.escapedName) - - return getManifest(uri, registry, spec, opts).then(manifest => { - return annotateManifest(uri, registry, manifest) + return getManifest(spec, opts).then(manifest => { + return annotateManifest(spec, manifest, opts) }) } -function metadataUrl (registry, name) { - const normalized = registry.slice(-1) !== '/' - ? registry + '/' - : registry - return url.resolve(normalized, name) -} - -function getManifest (uri, registry, spec, opts) { - return fetchPackument(uri, spec, registry, opts).then(packument => { +function getManifest (spec, opts) { + opts = opts.concat({ + fullMetadata: opts.enjoyBy ? true : opts.fullMetadata + }) + return fetchPackument(spec, opts).then(packument => { try { return pickManifest(packument, spec.fetchSpec, { defaultTag: opts.defaultTag, + enjoyBy: opts.enjoyBy, includeDeprecated: opts.includeDeprecated }) } catch (err) { if (err.code === 'ETARGET' && packument._cached && !opts.offline) { opts.log.silly( 'registry:manifest', - `no matching version for ${spec.name}@${spec.fetchSpec} in the cache. Forcing revalidation` + `no matching version for ${spec.name}@${spec.fetchSpec} in the cache. Forcing revalidation.` ) - opts.preferOffline = false - opts.preferOnline = true - return fetchPackument(uri, spec, registry, opts).then(packument => { + opts = opts.concat({ + preferOffline: false, + preferOnline: true + }) + return fetchPackument(spec, opts.concat({ + // Fetch full metadata in case ETARGET was due to corgi delay + fullMetadata: true + })).then(packument => { return pickManifest(packument, spec.fetchSpec, { - defaultTag: opts.defaultTag + defaultTag: opts.defaultTag, + enjoyBy: opts.enjoyBy }) }) } else { @@ -60,69 +52,7 @@ function getManifest (uri, registry, spec, opts) { }) } -// TODO - make this an opt -const MEMO = new LRU({ - length: m => m._contentLength, - max: 200 * 1024 * 1024, // 200MB - maxAge: 30 * 1000 // 30s -}) - -module.exports.clearMemoized = clearMemoized -function clearMemoized () { - MEMO.reset() -} - -function fetchPackument (uri, spec, registry, opts) { - const mem = pickMem(opts) - if (mem && !opts.preferOnline && mem.has(uri)) { - return BB.resolve(mem.get(uri)) - } - - return fetch(uri, registry, Object.assign({ - headers: { - 'pacote-req-type': 'packument', - 'pacote-pkg-id': `registry:${manifest.name}`, - accept: opts.fullMetadata ? JSON_DOC : CORGI_DOC - }, - spec - }, opts, { - // Force integrity to null: we never check integrity hashes for manifests - integrity: null - })).then(res => res.json().then(packument => { - packument._cached = decodeURIComponent(res.headers.has('x-local-cache')) - packument._contentLength = +res.headers.get('content-length') - // NOTE - we need to call pickMem again because proxy - // objects get reused! - const mem = pickMem(opts) - if (mem) { - mem.set(uri, packument) - } - return packument - })) -} - -class ObjProxy { - get (key) { return this.obj[key] } - set (key, val) { this.obj[key] = val } -} - -// This object is used synchronously and immediately, so -// we can safely reuse it instead of consing up new ones -const PROX = new ObjProxy() -function pickMem (opts) { - if (!opts || !opts.memoize) { - return MEMO - } else if (opts.memoize.get && opts.memoize.set) { - return opts.memoize - } else if (typeof opts.memoize === 'object') { - PROX.obj = opts.memoize - return PROX - } else { - return null - } -} - -function annotateManifest (uri, registry, manifest) { +function annotateManifest (spec, manifest, opts) { const shasum = manifest.dist && manifest.dist.shasum manifest._integrity = manifest.dist && manifest.dist.integrity manifest._shasum = shasum @@ -134,6 +64,9 @@ function annotateManifest (uri, registry, manifest) { manifest.dist && manifest.dist.tarball ) if (!manifest._resolved) { + const registry = fetch.pickRegistry(spec, opts) + const uri = registry.replace(/\/?$/, '/') + spec.escapedName + const err = new Error( `Manifest for ${manifest.name}@${manifest.version} from ${uri} is missing a tarball url (pkg.dist.tarball). Guessing a default.` ) diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/packument.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/packument.js new file mode 100644 index 0000000000..f5286c8037 --- /dev/null +++ b/deps/npm/node_modules/pacote/lib/fetchers/registry/packument.js @@ -0,0 +1,92 @@ +'use strict' + +const BB = require('bluebird') + +const fetch = require('npm-registry-fetch') +const LRU = require('lru-cache') +const optCheck = require('../../util/opt-check') + +// Corgis are cute. 🐕🐶 +const CORGI_DOC = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*' +const JSON_DOC = 'application/json' + +module.exports = packument +function packument (spec, opts) { + opts = optCheck(opts) + + const registry = fetch.pickRegistry(spec, opts) + const uri = registry.replace(/\/?$/, '/') + spec.escapedName + + return fetchPackument(uri, registry, spec, opts) +} + +const MEMO = new LRU({ + length: m => m._contentLength, + max: 200 * 1024 * 1024, // 200MB + maxAge: 30 * 1000 // 30s +}) + +module.exports.clearMemoized = clearMemoized +function clearMemoized () { + MEMO.reset() +} + +function fetchPackument (uri, registry, spec, opts) { + const mem = pickMem(opts) + const accept = opts.fullMetadata ? JSON_DOC : CORGI_DOC + const memoKey = `${uri}~(${accept})` + if (mem && !opts.preferOnline && mem.has(memoKey)) { + return BB.resolve(mem.get(memoKey)) + } + + return fetch(uri, opts.concat({ + headers: { + 'pacote-req-type': 'packument', + 'pacote-pkg-id': `registry:${spec.name}`, + accept + }, + spec + }, opts, { + // Force integrity to null: we never check integrity hashes for manifests + integrity: null + })).then(res => res.json().then(packument => { + packument._cached = res.headers.has('x-local-cache') + packument._contentLength = +res.headers.get('content-length') + // NOTE - we need to call pickMem again because proxy + // objects get reused! + const mem = pickMem(opts) + if (mem) { + mem.set(memoKey, packument) + } + return packument + })).catch(err => { + if (err.code === 'E404' && !opts.fullMetadata) { + return fetchPackument(uri, registry, spec, opts.concat({ + fullMetadata: true + })) + } else { + throw err + } + }) +} + +class ObjProxy { + get (key) { return this.obj[key] } + set (key, val) { this.obj[key] = val } +} + +// This object is used synchronously and immediately, so +// we can safely reuse it instead of consing up new ones +const PROX = new ObjProxy() +function pickMem (opts) { + if (!opts || !opts.memoize) { + return MEMO + } else if (opts.memoize.get && opts.memoize.set) { + return opts.memoize + } else if (typeof opts.memoize === 'object') { + PROX.obj = opts.memoize + return PROX + } else { + return null + } +} diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/pick-registry.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/pick-registry.js deleted file mode 100644 index f326950da4..0000000000 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/pick-registry.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict' - -module.exports = pickRegistry -function pickRegistry (spec, opts) { - let registry = spec.scope && opts.scopeTargets[spec.scope] - - if (!registry && opts.scope) { - const prefix = opts.scope[0] === '@' ? '' : '@' - registry = opts.scopeTargets[prefix + opts.scope] - } - - if (!registry) { - registry = opts.registry - } - - return registry -} diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/registry-key.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/registry-key.js deleted file mode 100644 index f53e9a9b48..0000000000 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/registry-key.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -const url = require('url') - -// Called a nerf dart in the main codebase. Used as a "safe" -// key when fetching registry info from config. -module.exports = registryKey -function registryKey (registry) { - const parsed = url.parse(registry) - const formatted = url.format({ - host: parsed.host, - pathname: parsed.pathname, - slashes: parsed.slashes - }) - return url.resolve(formatted, '.') -} diff --git a/deps/npm/node_modules/pacote/lib/fetchers/registry/tarball.js b/deps/npm/node_modules/pacote/lib/fetchers/registry/tarball.js index 7239981279..134153280e 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/registry/tarball.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/registry/tarball.js @@ -2,18 +2,17 @@ const BB = require('bluebird') -const fetch = require('./fetch') +const fetch = require('npm-registry-fetch') const manifest = require('./manifest') const optCheck = require('../../util/opt-check') const PassThrough = require('stream').PassThrough -const pickRegistry = require('./pick-registry') const ssri = require('ssri') const url = require('url') module.exports = tarball function tarball (spec, opts) { opts = optCheck(opts) - const registry = pickRegistry(spec, opts) + const registry = fetch.pickRegistry(spec, opts) const stream = new PassThrough() let mani if ( @@ -49,11 +48,11 @@ function tarball (spec, opts) { module.exports.fromManifest = fromManifest function fromManifest (manifest, spec, opts) { opts = optCheck(opts) - opts.scope = spec.scope || opts.scope + if (spec.scope) { opts = opts.concat({ scope: spec.scope }) } const stream = new PassThrough() - const registry = pickRegistry(spec, opts) + const registry = fetch.pickRegistry(spec, opts) const uri = getTarballUrl(spec, registry, manifest, opts) - fetch(uri, registry, Object.assign({ + fetch(uri, opts.concat({ headers: { 'pacote-req-type': 'tarball', 'pacote-pkg-id': `registry:${manifest.name}@${uri}` diff --git a/deps/npm/node_modules/pacote/lib/fetchers/remote.js b/deps/npm/node_modules/pacote/lib/fetchers/remote.js index a1e95a2e64..8941f99381 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/remote.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/remote.js @@ -8,6 +8,10 @@ const fetchRegistry = require('./registry') const fetchRemote = module.exports = Object.create(null) Fetcher.impl(fetchRemote, { + packument (spec, opts) { + return BB.reject(new Error('Not implemented yet')) + }, + manifest (spec, opts) { // We can't get the manifest for a remote tarball until // we extract the tarball itself. diff --git a/deps/npm/node_modules/pacote/lib/finalize-manifest.js b/deps/npm/node_modules/pacote/lib/finalize-manifest.js index 0f309ed6da..80b379898f 100644 --- a/deps/npm/node_modules/pacote/lib/finalize-manifest.js +++ b/deps/npm/node_modules/pacote/lib/finalize-manifest.js @@ -37,12 +37,12 @@ function finalizeManifest (pkg, spec, opts) { const key = finalKey(pkg, spec) opts = optCheck(opts) - const cachedManifest = (opts.cache && key && !opts.preferOnline && !opts.fullMetadata) + const cachedManifest = (opts.cache && key && !opts.preferOnline && !opts.fullMetadata && !opts.enjoyBy) ? cacache.get.info(opts.cache, key, opts) : BB.resolve(null) return cachedManifest.then(cached => { - if (cached && cached.metadata.manifest) { + if (cached && cached.metadata && cached.metadata.manifest) { return new Manifest(cached.metadata.manifest) } else { return tarballedProps(pkg, spec, opts).then(props => { @@ -54,13 +54,14 @@ function finalizeManifest (pkg, spec, opts) { if (!opts.cache || !cacheKey) { return manifest } else { - opts.metadata = { - id: manifest._id, - manifest, - type: 'finalized-manifest' - } return cacache.put( - opts.cache, cacheKey, '.', opts + opts.cache, cacheKey, '.', { + metadata: { + id: manifest._id, + manifest, + type: 'finalized-manifest' + } + } ).then(() => manifest) } }) @@ -155,7 +156,7 @@ function tarballedProps (pkg, spec, opts) { needsShrinkwrap && jsonFromStream('npm-shrinkwrap.json', extracted), needsManifest && jsonFromStream('package.json', extracted), needsBin && getPaths(extracted), - needsHash && ssri.fromStream(tarStream, {algorithms: ['sha1', 'sha512']}), + needsHash && ssri.fromStream(tarStream, { algorithms: ['sha1', 'sha512'] }), needsExtract && pipe(tarStream, extracted), (sr, mani, paths, hash) => { if (needsManifest && !mani) { diff --git a/deps/npm/node_modules/pacote/lib/util/git.js b/deps/npm/node_modules/pacote/lib/util/git.js index 9196212278..997404dd23 100644 --- a/deps/npm/node_modules/pacote/lib/util/git.js +++ b/deps/npm/node_modules/pacote/lib/util/git.js @@ -74,10 +74,10 @@ function fullClone (repo, committish, target, opts) { if (process.platform === 'win32') { gitArgs.push('--config', 'core.longpaths=true') } - return execGit(gitArgs, {cwd: target}).then(() => { - return execGit(['init'], {cwd: target}) + return execGit(gitArgs, { cwd: target }, opts).then(() => { + return execGit(['init'], { cwd: target }, opts) }).then(() => { - return execGit(['checkout', committish || 'HEAD'], {cwd: target}) + return execGit(['checkout', committish || 'HEAD'], { cwd: target }, opts) }).then(() => { return updateSubmodules(target, opts) }).then(() => headSha(target, opts)) @@ -110,7 +110,7 @@ function updateSubmodules (localRepo, opts) { function headSha (repo, opts) { opts = optCheck(opts) - return execGit(['rev-parse', '--revs-only', 'HEAD'], {cwd: repo}, opts).spread(stdout => { + return execGit(['rev-parse', '--revs-only', 'HEAD'], { cwd: repo }, opts).spread(stdout => { return stdout.trim() }) } @@ -139,7 +139,7 @@ function revs (repo, opts) { if (!ref) { return revs } // ??? if (ref.endsWith(CARET_BRACES)) { return revs } // refs/tags/x^{} crap const type = refType(line) - const doc = {sha, ref, type} + const doc = { sha, ref, type } revs.refs[ref] = doc // We can check out shallow clones on specific SHAs if we have a ref @@ -157,7 +157,7 @@ function revs (repo, opts) { } return revs - }, {versions: {}, 'dist-tags': {}, refs: {}, shas: {}}) + }, { versions: {}, 'dist-tags': {}, refs: {}, shas: {} }) }, err => { err.message = `Error while executing:\n${GITPATH} ls-remote -h -t ${repo}\n\n${err.stderr}\n${err.message}` throw err @@ -182,7 +182,7 @@ function revs (repo, opts) { module.exports._exec = execGit function execGit (gitArgs, gitOpts, opts) { opts = optCheck(opts) - return checkGit().then(gitPath => { + return checkGit(opts).then(gitPath => { return promiseRetry((retry, number) => { if (number !== 1) { opts.log.silly('pacote', 'Retrying git command: ' + gitArgs.join(' ') + ' attempt # ' + number) @@ -194,14 +194,19 @@ function execGit (gitArgs, gitOpts, opts) { throw err } }) - }, opts.retry) + }, opts.retry != null ? opts.retry : { + retries: opts['fetch-retries'], + factor: opts['fetch-retry-factor'], + maxTimeout: opts['fetch-retry-maxtimeout'], + minTimeout: opts['fetch-retry-mintimeout'] + }) }) } module.exports._spawn = spawnGit function spawnGit (gitArgs, gitOpts, opts) { opts = optCheck(opts) - return checkGit().then(gitPath => { + return checkGit(opts).then(gitPath => { return promiseRetry((retry, number) => { if (number !== 1) { opts.log.silly('pacote', 'Retrying git command: ' + gitArgs.join(' ') + ' attempt # ' + number) @@ -241,8 +246,10 @@ function mkOpts (_gitOpts, opts) { return gitOpts } -function checkGit () { - if (!GITPATH) { +function checkGit (opts) { + if (opts.git) { + return BB.resolve(opts.git) + } else if (!GITPATH) { const err = new Error('No git binary found in $PATH') err.code = 'ENOGIT' return BB.reject(err) diff --git a/deps/npm/node_modules/pacote/lib/util/opt-check.js b/deps/npm/node_modules/pacote/lib/util/opt-check.js index d13a69e4dc..e6afc21c84 100644 --- a/deps/npm/node_modules/pacote/lib/util/opt-check.js +++ b/deps/npm/node_modules/pacote/lib/util/opt-check.js @@ -1,64 +1,47 @@ 'use strict' -const pkg = require('../../package.json') -const silentlog = require('./silentlog') +const figgyPudding = require('figgy-pudding') +const logger = require('./proclog.js') -function PacoteOptions (opts) { - opts = opts || {} - this._isPacoteOptions = true - this.agent = opts.agent - this.annotate = opts.annotate - this.auth = opts.auth - this.scopeTargets = opts.scopeTargets || {} - this.defaultTag = opts.defaultTag || 'latest' - this.cache = opts.cache - this.ca = opts.ca - this.cert = opts.cert - this.integrity = opts.integrity - this.key = opts.key - this.localAddress = opts.localAddress - this.log = opts.log || silentlog - this.memoize = opts.memoize - this.maxSockets = opts.maxSockets || 10 - this.offline = opts.offline - this.preferOffline = opts.preferOffline - this.proxy = opts.proxy - this.noProxy = opts.noProxy - this.registry = opts.registry || 'https://registry.npmjs.org' - this.resolved = opts.resolved - this.retry = opts.retry // for npm-registry-client - this.scope = opts.scope - this.userAgent = opts.userAgent || `${pkg.name}@${pkg.version}/node@${process.version}+${process.arch} (${process.platform})` - this.where = opts.where - this.preferOnline = opts.preferOnline - this.strictSSL = !!opts.strictSSL - this.isFromCI = !!( - opts.isFromCI || - process.env['CI'] === 'true' || - process.env['TDDIUM'] || - process.env['JENKINS_URL'] || - process.env['bamboo.buildKey'] - ) - this.npmSession = opts.npmSession - this.refer = opts.referer || opts.refer - this.projectScope = opts.projectScope - this.fullMetadata = opts.fullMetadata - this.alwaysAuth = opts.alwaysAuth - this.includeDeprecated = opts.includeDeprecated == null - ? true - : opts.includeDeprecated - - this.dirPacker = opts.dirPacker || null - - this.uid = opts.uid - this.gid = opts.gid - - this.dmode = opts.dmode - this.fmode = opts.fmode - this.umask = opts.umask -} - -module.exports = optCheck -function optCheck (opts) { - return new PacoteOptions(opts) -} +const AUTH_REGEX = /^(?:.*:)?(token|_authToken|username|_password|password|email|always-auth|_auth|otp)$/ +const SCOPE_REGISTRY_REGEX = /@.*:registry$/gi +module.exports = figgyPudding({ + annotate: {}, + cache: {}, + defaultTag: 'tag', + dirPacker: {}, + dmode: {}, + 'enjoy-by': 'enjoyBy', + enjoyBy: {}, + fmode: {}, + 'fetch-retries': { default: 2 }, + 'fetch-retry-factor': { default: 10 }, + 'fetch-retry-maxtimeout': { default: 60000 }, + 'fetch-retry-mintimeout': { default: 10000 }, + fullMetadata: 'full-metadata', + 'full-metadata': { default: false }, + gid: {}, + git: {}, + includeDeprecated: { default: true }, + 'include-deprecated': 'includeDeprecated', + integrity: {}, + log: { default: logger }, + memoize: {}, + offline: {}, + preferOffline: 'prefer-offline', + 'prefer-offline': {}, + preferOnline: 'prefer-online', + 'prefer-online': {}, + registry: { default: 'https://registry.npmjs.org/' }, + resolved: {}, + retry: {}, + scope: {}, + tag: { default: 'latest' }, + uid: {}, + umask: {}, + where: {} +}, { + other (key) { + return key.match(AUTH_REGEX) || key.match(SCOPE_REGISTRY_REGEX) + } +}) diff --git a/deps/npm/node_modules/pacote/lib/util/pack-dir.js b/deps/npm/node_modules/pacote/lib/util/pack-dir.js index 62776692e1..157a9a82f8 100644 --- a/deps/npm/node_modules/pacote/lib/util/pack-dir.js +++ b/deps/npm/node_modules/pacote/lib/util/pack-dir.js @@ -33,7 +33,7 @@ function packDir (manifest, label, dir, target, opts) { } function mkPacker (dir) { - return packlist({path: dir}).then(files => { + return packlist({ path: dir }).then(files => { return tar.c({ cwd: dir, gzip: true, diff --git a/deps/npm/node_modules/pacote/lib/util/proclog.js b/deps/npm/node_modules/pacote/lib/util/proclog.js new file mode 100644 index 0000000000..e4a2bf8acf --- /dev/null +++ b/deps/npm/node_modules/pacote/lib/util/proclog.js @@ -0,0 +1,23 @@ +'use strict' + +const LEVELS = [ + 'notice', + 'error', + 'warn', + 'info', + 'verbose', + 'http', + 'silly', + 'pause', + 'resume' +] + +const logger = {} +for (const level of LEVELS) { + logger[level] = log(level) +} +module.exports = logger + +function log (level) { + return (category, ...args) => process.emit('log', level, category, ...args) +} diff --git a/deps/npm/node_modules/pacote/lib/util/silentlog.js b/deps/npm/node_modules/pacote/lib/util/silentlog.js deleted file mode 100644 index 4c9d6c57e8..0000000000 --- a/deps/npm/node_modules/pacote/lib/util/silentlog.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -const noop = Function.prototype -module.exports = { - error: noop, - warn: noop, - info: noop, - verbose: noop, - silly: noop, - http: noop, - pause: noop, - resume: noop -} diff --git a/deps/npm/node_modules/pacote/lib/with-tarball-stream.js b/deps/npm/node_modules/pacote/lib/with-tarball-stream.js index 653a4a688a..abeba738a1 100644 --- a/deps/npm/node_modules/pacote/lib/with-tarball-stream.js +++ b/deps/npm/node_modules/pacote/lib/with-tarball-stream.js @@ -36,7 +36,7 @@ function withTarballStream (spec, opts, streamHandler) { const file = path.resolve(opts.where || '.', opts.resolved.substr(5)) return statAsync(file) .then(() => { - const verifier = ssri.integrityStream({integrity: opts.integrity}) + const verifier = ssri.integrityStream({ integrity: opts.integrity }) const stream = fs.createReadStream(file) .on('error', err => verifier.emit('error', err)) .pipe(verifier) @@ -50,7 +50,7 @@ function withTarballStream (spec, opts, streamHandler) { throw err }) }) - : BB.reject(Object.assign(new Error('no file!'), {code: 'ENOENT'})) + : BB.reject(Object.assign(new Error('no file!'), { code: 'ENOENT' })) const tryDigest = tryFile .catch(err => { @@ -96,10 +96,10 @@ function withTarballStream (spec, opts, streamHandler) { const tardata = fetch.tarball(spec, opts) if (!opts.resolved) { tardata.on('manifest', m => { - opts.resolved = m._resolved + opts = opts.concat({ resolved: m._resolved }) }) tardata.on('integrity', i => { - opts.integrity = i + opts = opts.concat({ integrity: i }) }) } return BB.try(() => streamHandler(tardata)) @@ -117,7 +117,7 @@ function withTarballStream (spec, opts, streamHandler) { throw err } }) - }, {retries: 1})) + }, { retries: 1 })) } }) |