diff --git a/bin/npm-cli.js b/bin/npm-cli.js index 705aa472e7e55..b7f2af1ab2391 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -75,6 +75,7 @@ conf._exit = true npm.load(conf, function (er) { if (er) return errorHandler(er) + const useUnicode = npm.config.get('unicode') if ( !isGlobalNpmUpdate && npm.config.get('update-notifier') && @@ -89,12 +90,19 @@ !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 old = notifier.update.current + let latest = notifier.update.latest let type = notifier.update.type - if (useColor) { + let changelogLabel = 'Changelog:' + let changelog = `https://github.com/npm/cli/releases/tag/v${latest}` + let installCommand = `npm install -g ${pkg.name}` + const arrow = useUnicode ? '→' : '->' + if (npm.config.get('color')) { + old = color.red(old) + latest = color.green(latest) + changelogLabel = color.yellow(changelogLabel) + changelog = color.cyan(changelog) + installCommand = color.green(installCommand) switch (type) { case 'major': type = color.red(type) @@ -107,23 +115,11 @@ 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!` + message: + `New ${type} version of ${pkg.name} available! ${old} ${arrow} ${latest}\n` + + `${changelogLabel} ${changelog}\n` + + `Run ${installCommand} to update!` }) } } @@ -138,11 +134,11 @@ ) { console.error( `\n ${ - npm.config.get('unicode') ? '🎵 ' : '' + useUnicode ? '🎵 ' : '' } I Have the Honour to Be Your Obedient Servant,${ - npm.config.get('unicode') ? '🎵 ' : '' + useUnicode ? '🎵 ' : '' } ~ npm ${ - npm.config.get('unicode') ? '📜🖋 ' : '' + useUnicode ? '📜🖋 ' : '' }\n` ) }