From 34ab1f87de4f0c9c88e7f8e7d34c6edb97e64adc Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 30 Jun 2021 09:26:57 -0700 Subject: [PATCH] fix(deprecate): add undeprecate support 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. --- lib/deprecate.js | 3 ++- test/lib/deprecate.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/deprecate.js b/lib/deprecate.js index ece55e1f40243..156bbf875ea42 100644 --- a/lib/deprecate.js +++ b/lib/deprecate.js @@ -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. diff --git a/test/lib/deprecate.js b/test/lib/deprecate.js index c358fde247955..a69ef6c7796fc 100644 --- a/test/lib/deprecate.js +++ b/test/lib/deprecate.js @@ -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