Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't try to deprecate nonexistant versions #6050

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/commands/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ class Deprecate extends BaseCommand {
query: { write: true },
})

Object.keys(packument.versions)
const versions = Object.keys(packument.versions)
.filter(v => semver.satisfies(v, spec, { includePrerelease: true }))
.forEach(v => {
packument.versions[v].deprecated = msg
})

return otplease(this.npm, this.npm.flatOptions, opts => fetch(uri, {
...opts,
spec: p,
method: 'PUT',
body: packument,
ignoreBody: true,
}))
if (versions.length) {
for (const v of versions) {
packument.versions[v].deprecated = msg
}
return otplease(this.npm, this.npm.flatOptions, opts => fetch(uri, {
...opts,
spec: p,
method: 'PUT',
body: packument,
ignoreBody: true,
}))
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/lib/commands/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ t.test('deprecates all versions when no range is specified', async t => {
await npm.exec('deprecate', ['foo', message])
t.match(joinedOutput(), '')
})

t.test('does nothing if version does not actually exist', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, { config: { ...auth } })
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
authorization: token,
})
const manifest = registry.manifest({
name: 'foo',
versions,
})
await registry.package({ manifest, query: { write: true } })
await npm.exec('deprecate', ['foo@1.0.99', 'this should be ignored'])
t.match(joinedOutput(), '')
})