From 506159823c6b455e5f3a59f310a8fc104b8fdc38 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 09:58:01 -0400 Subject: [PATCH 1/9] move declaration of changelog up with the others --- bin/npm-cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index 705aa472e7e55..d63c8d81b60a2 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -94,6 +94,7 @@ const old = notifier.update.current const latest = notifier.update.latest let type = notifier.update.type + const changelog = `https://github.com/npm/cli/releases/tag/v${latest}` if (useColor) { switch (type) { case 'major': @@ -107,7 +108,6 @@ 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 From 26f60fde3880cc5566a229c231c21bf6394e65c5 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 09:59:49 -0400 Subject: [PATCH 2/9] change from const to let so we can color them if needed --- bin/npm-cli.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index d63c8d81b60a2..0a55a41cb33db 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -91,10 +91,10 @@ 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 - const changelog = `https://github.com/npm/cli/releases/tag/v${latest}` + let changelog = `https://github.com/npm/cli/releases/tag/v${latest}` if (useColor) { switch (type) { case 'major': From 4442107b7117494b26bbb2fcef4106263faab4b4 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:02:46 -0400 Subject: [PATCH 3/9] create variables for remaining parts of output text --- bin/npm-cli.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index 0a55a41cb33db..717a419b19a0b 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -94,7 +94,9 @@ let old = notifier.update.current let latest = notifier.update.latest let type = notifier.update.type + let changelogLabel = 'Changelog:' let changelog = `https://github.com/npm/cli/releases/tag/v${latest}` + let installCommand = `npm install -g ${pkg.name}` if (useColor) { switch (type) { case 'major': @@ -115,14 +117,14 @@ useColor ? color.green(latest) : latest }\n` + `${ - useColor ? color.yellow('Changelog:') : 'Changelog:' + useColor ? color.yellow(changelogLabel) : changelogLabel } ${ useColor ? color.cyan(changelog) : changelog }\n` + `Run ${ useColor - ? color.green(`npm install -g ${pkg.name}`) - : `npm i -g ${pkg.name}` + ? color.green(installCommand) + : installCommand } to update!` }) } From a255363533df827f51e04bf892413f4ef1a5d2f1 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:05:37 -0400 Subject: [PATCH 4/9] colorize all variables inside single block --- bin/npm-cli.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index 717a419b19a0b..cd19c52597541 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -98,6 +98,11 @@ let changelog = `https://github.com/npm/cli/releases/tag/v${latest}` let installCommand = `npm install -g ${pkg.name}` if (useColor) { + 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) From 3f8e6639e5a0eb67e12324563dd98973571634df Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:12:07 -0400 Subject: [PATCH 5/9] eliminate unnecessary useColor ternary statements --- bin/npm-cli.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index cd19c52597541..5a1b16f89dc49 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -117,19 +117,17 @@ } notifier.notify({ message: `New ${type} version of ${pkg.name} available! ${ - useColor ? color.red(old) : old + old } ${useUnicode ? '→' : '->'} ${ - useColor ? color.green(latest) : latest + latest }\n` + `${ - useColor ? color.yellow(changelogLabel) : changelogLabel + changelogLabel } ${ - useColor ? color.cyan(changelog) : changelog + changelog }\n` + `Run ${ - useColor - ? color.green(installCommand) - : installCommand + installCommand } to update!` }) } From c01af1a2c16ff71dff941fd16637490acb855cb9 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:13:31 -0400 Subject: [PATCH 6/9] remove remaining ternary statement by moving it to a variable; arrow --- bin/npm-cli.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index 5a1b16f89dc49..df8724345d192 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -97,6 +97,7 @@ 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 (useColor) { old = color.red(old) latest = color.green(latest) @@ -118,7 +119,7 @@ notifier.notify({ message: `New ${type} version of ${pkg.name} available! ${ old - } ${useUnicode ? '→' : '->'} ${ + } ${arrow} ${ latest }\n` + `${ From 9dd157f659224369985f23ef718253bf63a96a08 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:15:17 -0400 Subject: [PATCH 7/9] useColor is used once now so move its value to the if statement --- bin/npm-cli.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index df8724345d192..f5ac42f563234 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -89,7 +89,6 @@ !isCI ) { const color = require('ansicolors') - const useColor = npm.config.get('color') const useUnicode = npm.config.get('unicode') let old = notifier.update.current let latest = notifier.update.latest @@ -98,7 +97,7 @@ let changelog = `https://github.com/npm/cli/releases/tag/v${latest}` let installCommand = `npm install -g ${pkg.name}` const arrow = useUnicode ? '→' : '->' - if (useColor) { + if (npm.config.get('color')) { old = color.red(old) latest = color.green(latest) changelogLabel = color.yellow(changelogLabel) From f1b1acd501fabd172a8b62a364074da8233dbb90 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:23:58 -0400 Subject: [PATCH 8/9] reformat notify message construction now that all the ternary expressions are gone --- bin/npm-cli.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index f5ac42f563234..5348be7cffa70 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -116,19 +116,10 @@ } } notifier.notify({ - message: `New ${type} version of ${pkg.name} available! ${ - old - } ${arrow} ${ - latest - }\n` + - `${ - changelogLabel - } ${ - changelog - }\n` + - `Run ${ - installCommand - } to update!` + message: + `New ${type} version of ${pkg.name} available! ${old} ${arrow} ${latest}\n` + + `${changelogLabel} ${changelog}\n` + + `Run ${installCommand} to update!` }) } } From d9008c57d3938a195b5a022728b5b931846bd640 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 15 Apr 2019 10:26:49 -0400 Subject: [PATCH 9/9] move useUnicode declaration up a scope and reuse it below --- bin/npm-cli.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/npm-cli.js b/bin/npm-cli.js index 5348be7cffa70..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,7 +90,6 @@ !isCI ) { const color = require('ansicolors') - const useUnicode = npm.config.get('unicode') let old = notifier.update.current let latest = notifier.update.latest let type = notifier.update.type @@ -134,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` ) }