From e864bd3ce8e8467e0f8ebb499dc2daf06143bc33 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 1 Jun 2021 16:21:23 -0700 Subject: [PATCH] fix: do not update notify when installing npm@spec PR-URL: https://github.com/npm/cli/pull/3345 Credit: @isaacs Close: #3345 Reviewed-by: @wraithgar --- lib/utils/update-notifier.js | 2 +- test/lib/utils/update-notifier.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils/update-notifier.js b/lib/utils/update-notifier.js index 0a19be94e62a4..1af948a2db45a 100644 --- a/lib/utils/update-notifier.js +++ b/lib/utils/update-notifier.js @@ -14,7 +14,7 @@ const { resolve } = require('path') const isGlobalNpmUpdate = npm => { return npm.flatOptions.global && ['install', 'update'].includes(npm.command) && - npm.argv.includes('npm') + npm.argv.some(arg => /^npm(@|$)/.test(arg)) } // update check frequency diff --git a/test/lib/utils/update-notifier.js b/test/lib/utils/update-notifier.js index ad4d407728f93..9748a92a8ae7b 100644 --- a/test/lib/utils/update-notifier.js +++ b/test/lib/utils/update-notifier.js @@ -105,6 +105,16 @@ t.test('situations in which we do not notify', t => { t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests') }) + t.test('do not suggest update if already updating with spec', async t => { + t.equal(await updateNotifier({ + ...npm, + flatOptions: { ...flatOptions, global: true }, + command: 'install', + argv: ['npm@latest'], + }), null) + t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests') + }) + t.test('do not update if same as latest', async t => { t.equal(await updateNotifier(npm), null) t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')