Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2018-03-21 14:53:54 +0300
committerRebecca Turner <me@re-becca.org>2018-04-11 04:17:48 +0300
commit834b46ff48ade4ab4e557566c10e83199d8778c6 (patch)
treead2694b2c525b708652416ff98b6aafaa981b90d /bin/npm-cli.js
parent429498a8c8d4414bf242be6a3f3a08f9a2adcdf9 (diff)
cli: shinier update-notifier
This message is based on the one pnpm uses, which I think takes care of all the false update messages and missing -g that happens with the default notifier message. It also tells people what "level" the update is. Credit: @zkat PR-URL: https://github.com/npm/npm/pull/20122 Reviewed-By: @iarna
Diffstat (limited to 'bin/npm-cli.js')
-rwxr-xr-xbin/npm-cli.js50
1 files changed, 44 insertions, 6 deletions
diff --git a/bin/npm-cli.js b/bin/npm-cli.js
index 6e66cbd69..f8fd106d2 100755
--- a/bin/npm-cli.js
+++ b/bin/npm-cli.js
@@ -25,12 +25,6 @@
unsupported.checkForUnsupportedNode()
- if (!unsupported.checkVersion(process.version).unsupported) {
- var updater = require('update-notifier')
- var pkg = require('../package.json')
- updater({pkg: pkg}).notify({defer: true})
- }
-
var path = require('path')
var npm = require('../lib/npm.js')
var npmconf = require('../lib/config/core.js')
@@ -80,6 +74,50 @@
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
+ if (!unsupported.checkVersion(process.version).unsupported) {
+ const pkg = require('../package.json')
+ let notifier = require('update-notifier')({pkg})
+ if (
+ notifier.update &&
+ notifier.update.latest !== pkg.version
+ ) {
+ 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/npm/releases/tag/v${latest}`
+ notifier.notify({
+ message: `New ${type} version of npm 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 npm') : 'npm i -g npm'
+ } to update!`
+ })
+ }
+ }
npm.commands[npm.command](npm.argv, function (err) {
// https://genius.com/Lin-manuel-miranda-your-obedient-servant-lyrics
if (