summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/utils')
-rw-r--r--deps/npm/lib/utils/depr-check.js32
-rw-r--r--deps/npm/lib/utils/error-handler.js76
-rw-r--r--deps/npm/lib/utils/error-message.js43
-rw-r--r--deps/npm/lib/utils/gently-rm.js15
-rw-r--r--deps/npm/lib/utils/get-publish-config.js4
-rw-r--r--deps/npm/lib/utils/lifecycle.js4
-rw-r--r--deps/npm/lib/utils/map-to-registry.js2
-rw-r--r--deps/npm/lib/utils/package-integrity.js21
-rw-r--r--deps/npm/lib/utils/perf.js27
-rw-r--r--deps/npm/lib/utils/rename.js9
-rw-r--r--deps/npm/lib/utils/tar.js34
11 files changed, 168 insertions, 99 deletions
diff --git a/deps/npm/lib/utils/depr-check.js b/deps/npm/lib/utils/depr-check.js
index 89cf402739..97023ddda1 100644
--- a/deps/npm/lib/utils/depr-check.js
+++ b/deps/npm/lib/utils/depr-check.js
@@ -1,13 +1,23 @@
-var log = require('npmlog')
-
-var deprecated = {}
-var deprWarned = {}
-module.exports = function deprCheck (data) {
- if (deprecated[data._id]) data.deprecated = deprecated[data._id]
- if (data.deprecated) deprecated[data._id] = data.deprecated
- else return
- if (!deprWarned[data._id]) {
- deprWarned[data._id] = true
- log.warn('deprecated', '%s: %s', data._id, data.deprecated)
+'use strict'
+
+const log = require('npmlog')
+
+const deprecated = {}
+const deprWarned = {}
+
+module.exports = deprCheck
+function deprCheck (data) {
+ if (deprecated[data._id]) {
+ data.deprecated = deprecated[data._id]
}
+
+ if (data.deprecated) {
+ deprecated[data._id] = data.deprecated
+ if (!deprWarned[data._id]) {
+ deprWarned[data._id] = true
+ log.warn('deprecated', '%s: %s', data._id, data.deprecated)
+ }
+ }
+
+ return data
}
diff --git a/deps/npm/lib/utils/error-handler.js b/deps/npm/lib/utils/error-handler.js
index 1213902886..8365f39d9d 100644
--- a/deps/npm/lib/utils/error-handler.js
+++ b/deps/npm/lib/utils/error-handler.js
@@ -1,5 +1,6 @@
module.exports = errorHandler
+module.exports.exit = exit
var cbCalled = false
var log = require('npmlog')
@@ -14,6 +15,7 @@ var writeFileAtomic = require('write-file-atomic')
var errorMessage = require('./error-message.js')
var stopMetrics = require('./metrics.js').stop
var mkdirp = require('mkdirp')
+var fs = require('graceful-fs')
var logFileName
function getLogFile () {
@@ -23,9 +25,26 @@ function getLogFile () {
return logFileName
}
+var timings = {
+ version: npm.version,
+ command: process.argv.slice(2),
+ logfile: null
+}
+process.on('timing', function (name, value) {
+ if (timings[name]) { timings[name] += value } else { timings[name] = value }
+})
+
process.on('exit', function (code) {
+ process.emit('timeEnd', 'npm')
log.disableProgress()
- if (!npm.config || !npm.config.loaded) return
+ if (npm.config.loaded && npm.config.get('timing')) {
+ try {
+ timings.logfile = getLogFile()
+ fs.appendFileSync(path.join(npm.config.get('cache'), '_timing.json'), JSON.stringify(timings) + '\n')
+ } catch (_) {
+ // ignore
+ }
+ }
// kill any outstanding stats reporter if it hasn't finished yet
stopMetrics()
@@ -42,25 +61,26 @@ process.on('exit', function (code) {
writeLogFile()
}
- if (wroteLogFile) {
- // just a line break
- if (log.levels[log.level] <= log.levels.error) console.error('')
-
- log.error(
- '',
- [
- 'A complete log of this run can be found in:',
- ' ' + getLogFile()
- ].join('\n')
- )
- wroteLogFile = false
- }
if (code) {
log.verbose('code', code)
}
}
+ if (npm.config.loaded && npm.config.get('timing') && !wroteLogFile) writeLogFile()
+ if (wroteLogFile) {
+ // just a line break
+ if (log.levels[log.level] <= log.levels.error) console.error('')
+
+ log.error(
+ '',
+ [
+ 'A complete log of this run can be found in:',
+ ' ' + getLogFile()
+ ].join('\n')
+ )
+ wroteLogFile = false
+ }
- var doExit = npm.config.get('_exit')
+ var doExit = npm.config.loaded && npm.config.get('_exit')
if (doExit) {
// actually exit.
if (exitCode === 0 && !itWorked) {
@@ -75,7 +95,7 @@ process.on('exit', function (code) {
function exit (code, noLog) {
exitCode = exitCode || process.exitCode || code
- var doExit = npm.config ? npm.config.get('_exit') : true
+ var doExit = npm.config.loaded ? npm.config.get('_exit') : true
log.verbose('exit', [code, doExit])
if (log.level === 'silent') noLog = true
@@ -108,9 +128,6 @@ function exit (code, noLog) {
function reallyExit (er) {
if (er && !code) code = typeof er.errno === 'number' ? er.errno : 1
- // truncate once it's been written.
- log.record.length = 0
-
itWorked = !code
// just emit a fake exit event.
@@ -189,13 +206,28 @@ function errorHandler (er) {
msg.summary.concat(msg.detail).forEach(function (errline) {
log.error.apply(log, errline)
})
+ if (npm.config.get('json')) {
+ var error = {
+ error: {
+ code: er.code,
+ summary: messageText(msg.summary),
+ detail: messageText(msg.detail)
+ }
+ }
+ console.log(JSON.stringify(error, null, 2))
+ }
exit(typeof er.errno === 'number' ? er.errno : 1)
}
+function messageText (msg) {
+ return msg.map(function (line) {
+ return line.slice(1).join(' ')
+ }).join('\n')
+}
+
function writeLogFile () {
if (wroteLogFile) return
- wroteLogFile = true
var os = require('os')
@@ -214,6 +246,10 @@ function writeLogFile () {
})
})
writeFileAtomic.sync(getLogFile(), logOutput)
+
+ // truncate once it's been written.
+ log.record.length = 0
+ wroteLogFile = true
} catch (ex) {
return
}
diff --git a/deps/npm/lib/utils/error-message.js b/deps/npm/lib/utils/error-message.js
index f19d0bf6d3..49aa9124ec 100644
--- a/deps/npm/lib/utils/error-message.js
+++ b/deps/npm/lib/utils/error-message.js
@@ -33,17 +33,8 @@ function errorMessage (er) {
'',
[
'',
- 'Failed at the ' + er.pkgid + ' ' + er.stage + " script '" + er.script + "'.",
- 'Make sure you have the latest version of node.js and npm installed.',
- 'If you do, this is most likely a problem with the ' + er.pkgname + ' package,',
- 'not with npm itself.',
- 'Tell the author that this fails on your system:',
- ' ' + er.script,
- 'You can get information on how to open an issue for this project with:',
- ' npm bugs ' + er.pkgname,
- 'Or if that isn\'t available, you can get their info via:',
- ' npm owner ls ' + er.pkgname,
- 'There is likely additional logging output above.'
+ 'Failed at the ' + er.pkgid + ' ' + er.stage + ' script.',
+ 'This is probably not a problem with npm. There is likely additional logging output above.'
].join('\n')]
)
break
@@ -55,7 +46,6 @@ function errorMessage (er) {
[
'',
'Failed using git.',
- 'This is most likely not a problem with npm itself.',
'Please check if you have git installed and in your PATH.'
].join('\n')
])
@@ -70,7 +60,6 @@ function errorMessage (er) {
'Failed to parse package.json data.',
'package.json must be actual JSON, not just JavaScript.',
'',
- 'This is not a bug in npm.',
'Tell the package author to fix their package.json file.'
].join('\n'),
'JSON.parse'
@@ -187,8 +176,7 @@ function errorMessage (er) {
detail.push([
'network',
[
- 'This is most likely not a problem with npm itself',
- 'and is related to network connectivity.',
+ 'This is a problem related to network connectivity.',
'In most cases you are behind a proxy or have bad network settings.',
'\nIf you are behind a proxy, please make sure that the',
"'proxy' config is set properly. See: 'npm help config'"
@@ -201,7 +189,6 @@ function errorMessage (er) {
detail.push([
'package.json',
[
- 'This is most likely not a problem with npm itself.',
"npm can't find a package.json file in your current directory."
].join('\n')
])
@@ -210,7 +197,6 @@ function errorMessage (er) {
case 'ETARGET':
short.push(['notarget', er.message])
msg = [
- 'This is most likely not a problem with npm itself.',
'In most cases you or one of your dependencies are requesting',
"a package version that doesn't exist."
]
@@ -244,8 +230,8 @@ function errorMessage (er) {
detail.push([
'nospc',
[
- 'This is most likely not a problem with npm itself',
- 'and is related to insufficient space on your system.'
+ 'There appears to be insufficient space on your system to finish.',
+ 'Clear up some disk space and try again.'
].join('\n')
])
break
@@ -255,9 +241,7 @@ function errorMessage (er) {
detail.push([
'rofs',
[
- 'This is most likely not a problem with npm itself',
- 'and is related to the file system being read-only.',
- '\nOften virtualized file systems, or other file systems',
+ 'Often virtualized file systems, or other file systems',
"that don't support symlinks, give this error."
].join('\n')
])
@@ -268,8 +252,7 @@ function errorMessage (er) {
detail.push([
'enoent',
[
- 'This is most likely not a problem with npm itself',
- 'and is related to npm not being able to find a file.',
+ 'This is related to npm not being able to find a file.',
er.file ? "\nCheck if the file '" + er.file + "' is present." : ''
].join('\n')
])
@@ -289,18 +272,6 @@ function errorMessage (er) {
])
break
- case 'EISDIR':
- short.push(['eisdir', er.message])
- detail.push([
- 'eisdir',
- [
- 'This is most likely not a problem with npm itself',
- 'and is related to npm not being able to find a package.json in',
- 'a package you are trying to install.'
- ].join('\n')
- ])
- break
-
default:
short.push(['', er.message || er])
break
diff --git a/deps/npm/lib/utils/gently-rm.js b/deps/npm/lib/utils/gently-rm.js
index 634bf94fcc..7253e873c6 100644
--- a/deps/npm/lib/utils/gently-rm.js
+++ b/deps/npm/lib/utils/gently-rm.js
@@ -29,13 +29,6 @@ function gentlyRm (target, gently, base, cb) {
gently = false
}
- log.silly(
- 'gentlyRm',
- target,
- 'is being', gently ? 'gently removed' : 'purged',
- base ? 'from base ' + base : ''
- )
-
// never rm the root, prefix, or bin dirs
//
// globals included because of `npm link` -- as far as the package
@@ -53,15 +46,13 @@ function gentlyRm (target, gently, base, cb) {
var targetPath = normalize(resolve(npm.prefix, target))
if (prefixes.indexOf(targetPath) !== -1) {
- log.verbose('gentlyRm', targetPath, "is part of npm and can't be removed")
return cb(new Error('May not delete: ' + targetPath))
}
- var options = { log: log.silly.bind(log, 'vacuum-fs') }
+ var options = { }
if (npm.config.get('force') || !gently) options.purge = true
if (base) options.base = normalize(resolve(npm.prefix, base))
if (!gently) {
- log.verbose('gentlyRm', "don't care about contents; nuking", targetPath)
return vacuum(targetPath, options, cb)
}
@@ -95,8 +86,6 @@ function gentlyRm (target, gently, base, cb) {
function thenRemove (toRemove, removeBase) {
if (!toRemove) return cb()
if (removeBase) options.base = removeBase
- log.verbose('gentlyRm', options.purge ? 'Purging' : 'Vacuuming',
- toRemove, 'up to', options.base)
return vacuum(toRemove, options, cb)
}
})
@@ -116,7 +105,7 @@ function isSafeToRm (parent, target, cb) {
// The parent directory or something it symlinks to must eventually be in
// a folder that npm maintains.
if (!parent.managed) {
- log.verbose('gentlyRm', parent.path,
+ log.info('gentlyRm', parent.path,
'is not contained in any diretory npm is known to control or ' +
'any place they link to')
return cb(clobberFail(target.path, 'containing path ' + parent.path +
diff --git a/deps/npm/lib/utils/get-publish-config.js b/deps/npm/lib/utils/get-publish-config.js
index dcbb7b9c0c..fa475434ff 100644
--- a/deps/npm/lib/utils/get-publish-config.js
+++ b/deps/npm/lib/utils/get-publish-config.js
@@ -1,5 +1,5 @@
var Conf = require('../config/core.js').Conf
-var CachingRegClient = require('../cache/caching-client.js')
+var RegClient = require('npm-registry-client')
var log = require('npmlog')
module.exports = getPublishConfig
@@ -18,7 +18,7 @@ function getPublishConfig (publishConfig, defaultConfig, defaultClient) {
s[k] = publishConfig[k]
return s
}, {}))
- client = new CachingRegClient(config)
+ client = new RegClient(config)
}
return { config: config, client: client }
diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js
index 4ab5e0979a..f8b34d7bef 100644
--- a/deps/npm/lib/utils/lifecycle.js
+++ b/deps/npm/lib/utils/lifecycle.js
@@ -55,6 +55,10 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {
log.info('lifecycle', logid(pkg, stage), 'ignored because ignore-scripts is set to true', pkg._id)
pkg.scripts = {}
}
+ if (stage === 'prepublish' && npm.config.get('ignore-prepublish')) {
+ log.info('lifecycle', logid(pkg, stage), 'ignored because ignore-prepublish is set to true', pkg._id)
+ delete pkg.scripts.prepublish
+ }
validWd(wd || path.resolve(npm.dir, pkg.name), function (er, wd) {
if (er) return cb(er)
diff --git a/deps/npm/lib/utils/map-to-registry.js b/deps/npm/lib/utils/map-to-registry.js
index 9e7ce67490..1f9798c09f 100644
--- a/deps/npm/lib/utils/map-to-registry.js
+++ b/deps/npm/lib/utils/map-to-registry.js
@@ -52,7 +52,7 @@ function mapToRegistry (name, config, cb) {
var uri
log.silly('mapToRegistry', 'data', data)
if (data.type === 'remote') {
- uri = data.spec
+ uri = data.fetchSpec
} else {
uri = url.resolve(normalized, name)
}
diff --git a/deps/npm/lib/utils/package-integrity.js b/deps/npm/lib/utils/package-integrity.js
new file mode 100644
index 0000000000..f9560d660e
--- /dev/null
+++ b/deps/npm/lib/utils/package-integrity.js
@@ -0,0 +1,21 @@
+'use strict'
+
+// Utilities for generating and verifying the packageIntegrity field for
+// package-lock
+//
+// Spec: https://github.com/npm/npm/pull/16441
+
+const ssri = require('ssri')
+const SSRI_OPTS = {
+ algorithms: ['sha512']
+}
+
+module.exports.check = check
+function check (pkg, integrity) {
+ return ssri.checkData(JSON.stringify(pkg), integrity, SSRI_OPTS)
+}
+
+module.exports.hash = hash
+function hash (pkg) {
+ return ssri.fromData(JSON.stringify(pkg), SSRI_OPTS).toString()
+}
diff --git a/deps/npm/lib/utils/perf.js b/deps/npm/lib/utils/perf.js
new file mode 100644
index 0000000000..0423263225
--- /dev/null
+++ b/deps/npm/lib/utils/perf.js
@@ -0,0 +1,27 @@
+'use strict'
+var log = require('npmlog')
+var EventEmitter = require('events').EventEmitter
+var perf = new EventEmitter()
+module.exports = perf
+
+var timings = {}
+
+process.on('time', time)
+process.on('timeEnd', timeEnd)
+
+perf.on('time', time)
+perf.on('timeEnd', timeEnd)
+
+function time (name) {
+ timings[name] = Date.now()
+}
+
+function timeEnd (name) {
+ if (name in timings) {
+ process.emit('timing', name, Date.now() - timings[name])
+ delete timings[name]
+ } else {
+ log.silly('timing', "Tried to end timer that doesn't exist:", name)
+ return
+ }
+}
diff --git a/deps/npm/lib/utils/rename.js b/deps/npm/lib/utils/rename.js
deleted file mode 100644
index 43a2f7e104..0000000000
--- a/deps/npm/lib/utils/rename.js
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
-
-This is a stub file to ensure that the following hack doesn't break. This can be removed w/ npm@5.
-
-# Fix bug https://github.com/npm/npm/issues/9863
-RUN cd $(npm root -g)/npm \
- && npm install fs-extra \
- && sed -i -e s/graceful-fs/fs-extra/ -e s/fs\.rename/fs.move/ ./lib/utils/rename.js
-*/
diff --git a/deps/npm/lib/utils/tar.js b/deps/npm/lib/utils/tar.js
index 88cfc6b805..7ebc9d6875 100644
--- a/deps/npm/lib/utils/tar.js
+++ b/deps/npm/lib/utils/tar.js
@@ -1,6 +1,10 @@
+'use strict'
+
// commands for packing and unpacking tarballs
// this file is used by lib/cache.js
+const BB = require('bluebird')
+
var fs = require('graceful-fs')
var path = require('path')
var writeFileAtomic = require('write-file-atomic')
@@ -24,6 +28,11 @@ var moduleName = require('./module-name.js')
var packageId = require('./package-id.js')
var pulseTillDone = require('../utils/pulse-till-done.js')
+const cacache = require('cacache')
+const packAsync = BB.promisify(pack)
+const PassThrough = require('stream').PassThrough
+const pipe = BB.promisify(require('mississippi').pipe)
+
if (process.env.SUDO_UID && myUid === 0) {
if (!isNaN(process.env.SUDO_UID)) myUid = +process.env.SUDO_UID
if (!isNaN(process.env.SUDO_GID)) myGid = +process.env.SUDO_GID
@@ -32,6 +41,18 @@ if (process.env.SUDO_UID && myUid === 0) {
exports.pack = pack
exports.unpack = unpack
+module.exports.packToStream = packToStream
+function packToStream (mani, dir) {
+ const stream = new PassThrough()
+ cacache.tmp.withTmp(npm.tmp, (tmp) => {
+ const tmpTarget = path.join(tmp, 'package.tgz')
+ return packAsync(tmpTarget, dir, mani).then(() => {
+ return pipe(fs.createReadStream(tmpTarget), stream)
+ })
+ }).catch((err) => stream.emit('error', err))
+ return stream
+}
+
function pack (tarball, folder, pkg, cb) {
log.verbose('tar pack', [tarball, folder])
@@ -45,14 +66,11 @@ function pack (tarball, folder, pkg, cb) {
// we require this at runtime due to load-order issues, because recursive
// requires fail if you replace the exports object, and we do, not in deps, but
// in a dep of it.
- var recalculateMetadata = require('../install/deps.js').recalculateMetadata
+ var computeMetadata = require('../install/deps.js').computeMetadata
readPackageTree(folder, pulseTillDone('pack:readTree:' + packageId(pkg), iferr(cb, function (tree) {
- var recalcGroup = log.newGroup('pack:recalc:' + packageId(pkg))
- recalculateMetadata(tree, recalcGroup, iferr(cb, function () {
- recalcGroup.finish()
- pack_(tarball, folder, tree, pkg, pulseTillDone('pack:' + packageId(pkg), cb))
- }))
+ computeMetadata(tree)
+ pack_(tarball, folder, tree, pkg, pulseTillDone('pack:' + packageId(pkg), cb))
})))
}
})
@@ -103,7 +121,9 @@ BundledPacker.prototype.applyIgnores = function (entry, partial, entryObj) {
entry.match(/^\..*\.swp$/) ||
entry === '.DS_Store' ||
entry.match(/^\._/) ||
- entry.match(/^.*\.orig$/)
+ entry.match(/^.*\.orig$/) ||
+ // Package locks are never allowed in tarballs -- use shrinkwrap instead
+ entry === 'package-lock.json'
) {
return false
}