diff options
author | isaacs <i@izs.me> | 2021-06-02 02:21:23 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2021-06-02 18:36:48 +0300 |
commit | e864bd3ce8e8467e0f8ebb499dc2daf06143bc33 (patch) | |
tree | fe085eeb285c248a28ab7da5287b07c1fddf88db | |
parent | c4ef78b08e6859fc191cabbe58c8d88c070e0612 (diff) |
fix: do not update notify when installing npm@specisaacs/no-notifier-for-installing-npm-at-latest
PR-URL: https://github.com/npm/cli/pull/3345
Credit: @isaacs
Close: #3345
Reviewed-by: @wraithgar
-rw-r--r-- | lib/utils/update-notifier.js | 2 | ||||
-rw-r--r-- | test/lib/utils/update-notifier.js | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/utils/update-notifier.js b/lib/utils/update-notifier.js index 0a19be94e..1af948a2d 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 ad4d40772..9748a92a8 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') |