Skip to content

Commit

Permalink
fix: log if npm deprecate does not match any version (#7474)
Browse files Browse the repository at this point in the history
If the package specification does not match any
existing version, a warning message is added to the log.

## References

Ref #7472
Closes #7180
  • Loading branch information
mbtools committed May 6, 2024
1 parent e39d422 commit ca1a68d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/commands/deprecate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fetch = require('npm-registry-fetch')
const { otplease } = require('../utils/auth.js')
const npa = require('npm-package-arg')
const { log } = require('proc-log')
const semver = require('semver')
const getIdentity = require('../utils/get-identity.js')
const libaccess = require('libnpmaccess')
Expand Down Expand Up @@ -66,6 +67,8 @@ class Deprecate extends BaseCommand {
body: packument,
ignoreBody: true,
}))
} else {
log.warn('deprecate', 'No version found for', p.rawSpec)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/lib/commands/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ t.test('deprecates all versions when no range is specified', async t => {
})

t.test('does nothing if version does not actually exist', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, { config: { ...auth } })
const { npm, logs, joinedOutput } = await loadMockNpm(t, { config: { ...auth } })
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
Expand All @@ -168,4 +168,5 @@ t.test('does nothing if version does not actually exist', async t => {
await registry.package({ manifest, query: { write: true } })
await npm.exec('deprecate', ['foo@1.0.99', 'this should be ignored'])
t.match(joinedOutput(), '')
t.equal(logs.warn[0], 'deprecate No version found for 1.0.99')
})

0 comments on commit ca1a68d

Please sign in to comment.