Skip to content

Commit

Permalink
fix: do not update notify when installing npm@spec
Browse files Browse the repository at this point in the history
PR-URL: #3345
Credit: @isaacs
Close: #3345
Reviewed-by: @wraithgar
  • Loading branch information
isaacs committed Jun 2, 2021
1 parent c4ef78b commit e864bd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/lib/utils/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e864bd3

Please sign in to comment.