0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/deps/npm/bin/npm-cli.js
isaacs f76903433f deps: update npm to 6.10.3
BUGFIXES

* [`27cccfbda`](27cccfbdac)
  [#223](https://github.com/npm/cli/pull/223) vulns → vulnerabilities in
  npm audit output ([@sapegin](https://github.com/sapegin))
* [`d5e865eb7`](d5e865eb79)
  [#222](https://github.com/npm/cli/pull/222)
  [#226](https://github.com/npm/cli/pull/226) install, doctor: don't crash
  if registry unset ([@dmitrydvorkin](https://github.com/dmitrydvorkin),
  [@isaacs](https://github.com/isaacs))
* [`5b3890226`](5b38902265)
  [#227](https://github.com/npm/cli/pull/227)
  [npm.community#9167](https://npm.community/t/npm-err-cb-never-called-permission-denied/9167/5)
  Handle unhandledRejections, tell user what to do when encountering an
  `EACCES` error in the cache.  ([@isaacs](https://github.com/isaacs))

DEPENDENCIES

* [`77516df6e`](77516df6ea)
  `licensee@7.0.3` ([@isaacs](https://github.com/isaacs))
* [`ceb993590`](ceb993590e)
  `query-string@6.8.2` ([@isaacs](https://github.com/isaacs))
* [`4050b9189`](4050b91898)
  `hosted-git-info@2.8.2`
    * [#46](https://github.com/npm/hosted-git-info/issues/46)
      [#43](https://github.com/npm/hosted-git-info/issues/43)
      [#47](https://github.com/npm/hosted-git-info/pull/47)
      [#44](https://github.com/npm/hosted-git-info/pull/44) Add support for
      GitLab subgroups ([@mterrel](https://github.com/mterrel),
      [@isaacs](https://github.com/isaacs),
      [@ybiquitous](https://github.com/ybiquitous))
    * [`3b1d629`](https://github.com/npm/hosted-git-info/commit/3b1d629)
      [#48](https://github.com/npm/hosted-git-info/issues/48) fix http
      protocol using sshurl by default
      ([@fengmk2](https://github.com/fengmk2))
    * [`5d4a8d7`](https://github.com/npm/hosted-git-info/commit/5d4a8d7)
      ignore noCommittish on tarball url generation
      ([@isaacs](https://github.com/isaacs))
    * [`1692435`](https://github.com/npm/hosted-git-info/commit/1692435)
      use gist tarball url that works for anonymous gists
      ([@isaacs](https://github.com/isaacs))
    * [`d5cf830`](d5cf8309be)
      Do not allow invalid gist urls ([@isaacs](https://github.com/isaacs))
    * [`e518222`](e518222435)
      Use LRU cache to prevent unbounded memory consumption
      ([@iarna](https://github.com/iarna))

PR-URL: https://github.com/nodejs/node/pull/29023
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-08-20 13:40:44 -07:00

154 lines
4.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode
// windows: running "npm blah" in this folder will invoke WSH, not node.
/* global WScript */
if (typeof WScript !== 'undefined') {
WScript.echo(
'npm does not work when run\n' +
'with the Windows Scripting Host\n\n' +
"'cd' to a different directory,\n" +
"or type 'npm.cmd <args>',\n" +
"or type 'node npm <args>'."
)
WScript.quit(1)
return
}
process.title = 'npm'
var unsupported = require('../lib/utils/unsupported.js')
unsupported.checkForBrokenNode()
var log = require('npmlog')
log.pause() // will be unpaused when config is loaded.
log.info('it worked if it ends with', 'ok')
unsupported.checkForUnsupportedNode()
var npm = require('../lib/npm.js')
var npmconf = require('../lib/config/core.js')
var errorHandler = require('../lib/utils/error-handler.js')
var configDefs = npmconf.defs
var shorthands = configDefs.shorthands
var types = configDefs.types
var nopt = require('nopt')
// if npm is called as "npmg" or "npm_g", then
// run in global mode.
if (process.argv[1][process.argv[1].length - 1] === 'g') {
process.argv.splice(1, 1, 'npm', '-g')
}
log.verbose('cli', process.argv)
var conf = nopt(types, shorthands)
npm.argv = conf.argv.remain
if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
else conf.usage = true
if (conf.version) {
console.log(npm.version)
return errorHandler.exit(0)
}
if (conf.versions) {
npm.command = 'version'
conf.usage = false
npm.argv = []
}
log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)
process.on('uncaughtException', errorHandler)
process.on('unhandledRejection', errorHandler)
if (conf.usage && npm.command !== 'help') {
npm.argv.unshift(npm.command)
npm.command = 'help'
}
var isGlobalNpmUpdate = conf.global && ['install', 'update'].includes(npm.command) && npm.argv.includes('npm')
// now actually fire up npm and run the command.
// this is how to use npm programmatically:
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
if (
!isGlobalNpmUpdate &&
npm.config.get('update-notifier') &&
!unsupported.checkVersion(process.version).unsupported
) {
const pkg = require('../package.json')
let notifier = require('update-notifier')({pkg})
const isCI = require('ci-info').isCI
if (
notifier.update &&
notifier.update.latest !== pkg.version &&
!isCI
) {
const color = require('ansicolors')
const useColor = npm.config.get('color')
const useUnicode = npm.config.get('unicode')
const old = notifier.update.current
const latest = notifier.update.latest
let type = notifier.update.type
if (useColor) {
switch (type) {
case 'major':
type = color.red(type)
break
case 'minor':
type = color.yellow(type)
break
case 'patch':
type = color.green(type)
break
}
}
const changelog = `https://github.com/npm/cli/releases/tag/v${latest}`
notifier.notify({
message: `New ${type} version of ${pkg.name} available! ${
useColor ? color.red(old) : old
} ${useUnicode ? '→' : '->'} ${
useColor ? color.green(latest) : latest
}\n` +
`${
useColor ? color.yellow('Changelog:') : 'Changelog:'
} ${
useColor ? color.cyan(changelog) : changelog
}\n` +
`Run ${
useColor
? color.green(`npm install -g ${pkg.name}`)
: `npm i -g ${pkg.name}`
} to update!`
})
}
}
npm.commands[npm.command](npm.argv, function (err) {
// https://genius.com/Lin-manuel-miranda-your-obedient-servant-lyrics
if (
!err &&
npm.config.get('ham-it-up') &&
!npm.config.get('json') &&
!npm.config.get('parseable') &&
npm.command !== 'completion'
) {
console.error(
`\n ${
npm.config.get('unicode') ? '🎵 ' : ''
} I Have the Honour to Be Your Obedient Servant,${
npm.config.get('unicode') ? '🎵 ' : ''
} ~ npm ${
npm.config.get('unicode') ? '📜🖋 ' : ''
}\n`
)
}
errorHandler.apply(this, arguments)
})
})
})()