Skip to content

Commit

Permalink
fix(deprecate): add undeprecate support
Browse files Browse the repository at this point in the history
Setting a deprecation of an empty string is the way to un-deprecate a
package, this was accidentally broken in a past refactoring, and is now
re-added with a test to ensure it is allowed.

PR-URL: #3484
Credit: @wraithgar
Close: #3484
Reviewed-by: @isaacs
  • Loading branch information
wraithgar committed Jun 30, 2021
1 parent 0dd0341 commit d2e298f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Deprecate extends BaseCommand {
}

async deprecate ([pkg, msg]) {
if (!pkg || !msg)
// msg == null becase '' is a valid value, it indicates undeprecate
if (!pkg || msg == null)
throw this.usageError()

// fetch the data and make sure it exists.
Expand Down
15 changes: 15 additions & 0 deletions test/lib/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ t.test('invalid semver range', t => {
})
})

t.test('undeprecate', t => {
deprecate.exec(['foo', ''], (err) => {
if (err)
throw err
t.match(npmFetchBody, {
versions: {
'1.0.0': { deprecated: '' },
'1.0.1': { deprecated: '' },
'1.0.1-pre': { deprecated: '' },
},
}, 'undeprecates everything')
t.end()
})
})

t.test('deprecates given range', t => {
t.teardown(() => {
npmFetchBody = null
Expand Down

0 comments on commit d2e298f

Please sign in to comment.