Skip to content

Commit

Permalink
feat: add npm undeprecate command
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jan 6, 2025
1 parent ab9ddc0 commit 1764a37
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 27 deletions.
6 changes: 3 additions & 3 deletions docs/lib/check-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ function ensureNavigationComplete (nav, fsPaths, ext) {
const errors = []

if (missingNav.length) {
errors.push('The following path(s) exist on disk but are not present in nav.yml:')
errors.push('The following path(s) exist on disk but are not present in /lib/content/nav.yml:')
errors.push(...missingNav.map(n => ` ${n}`))
}

if (missingFs.length) {
errors.push('The following path(s) exist in nav.yml but are not present on disk:')
errors.push('The following path(s) exist in lib/content/nav.yml but are not present on disk:')
errors.push(...missingFs.map(n => ` ${n}`))
}

if (errors.length) {
errors.unshift('Documentation navigation (nav.yml) does not match filesystem.')
errors.unshift('Documentation navigation (lib/content/nav.yml) does not match filesystem.')
errors.push('Update nav.yml to ensure that all files are listed in the appropriate place.')
throw new Error(errors.join('\n'))
}
Expand Down
24 changes: 24 additions & 0 deletions docs/lib/content/commands/npm-undeprecate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: npm-undeprecate
section: 1
description: Undeprecate a version of a package
---

### Synopsis

<!-- AUTOGENERATED USAGE DESCRIPTIONS -->

### Description

This command will update the npm registry entry for a package, removing any
deprecation warnings that currently exist.

It works in the same way as [npm deprecate](/commands/npm-deprecate), except
that this command removes deprecation warnings instead of adding them.

### Configuration

<!-- AUTOGENERATED CONFIG DESCRIPTIONS -->
### See Also

* [npm deprecate](/commands/npm-deprecate)
3 changes: 3 additions & 0 deletions docs/lib/content/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
- title: npm token
url: /commands/npm-token
description: Manage your authentication tokens
- title: npm undeprecate
url: /commands/npm-undeprecate
description: Undeprecate a version of a package
- title: npm uninstall
url: /commands/npm-uninstall
description: Remove a package
Expand Down
13 changes: 13 additions & 0 deletions lib/commands/undeprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Deprecate = require('./deprecate.js')

class Undeprecate extends Deprecate {
static description = 'Undeprecate a version of a package'
static name = 'undeprecate'
static usage = ['<package-spec>']

async exec ([pkg]) {
return super.exec([pkg, ''])
}
}

module.exports = Undeprecate
1 change: 1 addition & 0 deletions lib/utils/cmd-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const commands = [
'team',
'test',
'token',
'undeprecate',
'uninstall',
'unpublish',
'unstar',
Expand Down
3 changes: 2 additions & 1 deletion smoke-tests/tap-snapshots/test/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ All commands:
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{NPM}/{TESTDIR}/home/.npmrc
Expand Down
1 change: 1 addition & 0 deletions tap-snapshots/test/lib/commands/completion.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Array [
team
test
token
undeprecate
uninstall
unpublish
unstar
Expand Down
1 change: 1 addition & 0 deletions tap-snapshots/test/lib/commands/publish.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ Object {
"man/man1/npm-team.1",
"man/man1/npm-test.1",
"man/man1/npm-token.1",
"man/man1/npm-undeprecate.1",
"man/man1/npm-uninstall.1",
"man/man1/npm-unpublish.1",
"man/man1/npm-unstar.1",
Expand Down
26 changes: 25 additions & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Array [
"team",
"test",
"token",
"undeprecate",
"uninstall",
"unpublish",
"unstar",
Expand Down Expand Up @@ -2850,7 +2851,7 @@ Usage:
npm deprecate <package-spec> <message>
Options:
[--registry <registry>] [--otp <otp>]
[--registry <registry>] [--otp <otp>] [--dry-run]
Run "npm help deprecate" for more info
Expand All @@ -2862,6 +2863,7 @@ Note: This command is unaware of workspaces.
#### \`registry\`
#### \`otp\`
#### \`dry-run\`
`

exports[`test/lib/docs.js TAP usage diff > must match snapshot 1`] = `
Expand Down Expand Up @@ -4274,6 +4276,28 @@ Note: This command is unaware of workspaces.
#### \`otp\`
`

exports[`test/lib/docs.js TAP usage undeprecate > must match snapshot 1`] = `
Undeprecate a version of a package
Usage:
npm undeprecate <package-spec>
Options:
[--registry <registry>] [--otp <otp>] [--dry-run]
Run "npm help undeprecate" for more info
\`\`\`bash
npm undeprecate <package-spec>
\`\`\`
Note: This command is unaware of workspaces.
#### \`registry\`
#### \`otp\`
#### \`dry-run\`
`

exports[`test/lib/docs.js TAP usage uninstall > must match snapshot 1`] = `
Remove a package
Expand Down
52 changes: 30 additions & 22 deletions tap-snapshots/test/lib/npm.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ All commands:
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -89,9 +90,10 @@ All commands:
search, set, shrinkwrap,
star, stars, start,
stop, team, test, token,
uninstall, unpublish,
unstar, update, version,
view, whoami
undeprecate, uninstall,
unpublish, unstar,
update, version, view,
whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -141,9 +143,10 @@ All commands:
search, set, shrinkwrap,
star, stars, start,
stop, team, test, token,
uninstall, unpublish,
unstar, update, version,
view, whoami
undeprecate, uninstall,
unpublish, unstar,
update, version, view,
whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -179,7 +182,8 @@ All commands:
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -229,9 +233,10 @@ All commands:
search, set, shrinkwrap,
star, stars, start,
stop, team, test, token,
uninstall, unpublish,
unstar, update, version,
view, whoami
undeprecate, uninstall,
unpublish, unstar,
update, version, view,
whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -281,9 +286,10 @@ All commands:
search, set, shrinkwrap,
star, stars, start,
stop, team, test, token,
uninstall, unpublish,
unstar, update, version,
view, whoami
undeprecate, uninstall,
unpublish, unstar,
update, version, view,
whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -331,10 +337,10 @@ All commands:
run-script, sbom, search,
set, shrinkwrap, star,
stars, start, stop, team,
test, token, uninstall,
unpublish, unstar,
update, version, view,
whoami
test, token, undeprecate,
uninstall, unpublish,
unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -370,8 +376,8 @@ All commands:
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view,
whoami
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -407,7 +413,8 @@ All commands:
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down Expand Up @@ -443,7 +450,8 @@ All commands:
ping, pkg, prefix, profile, prune, publish, query, rebuild,
repo, restart, root, run-script, sbom, search, set,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
undeprecate, uninstall, unpublish, unstar, update, version,
view, whoami
Specify configs in the ini-formatted file:
{USERCONFIG}
Expand Down
72 changes: 72 additions & 0 deletions test/lib/commands/undeprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')

const MockRegistry = require('@npmcli/mock-registry')

const token = 'test-auth-token'
const auth = { '//registry.npmjs.org/:_authToken': token }
const versions = ['1.0.0', '1.0.1', '1.0.1-pre']

t.test('no args', async t => {
const { npm } = await loadMockNpm(t)
await t.rejects(
npm.exec('undeprecate', []),
{ code: 'EUSAGE' },
'logs usage'
)
})

t.test('undeprecate', async t => {
const { npm, logs, 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 } })
registry.nock.put('/foo', body => {
for (const version of versions) {
if (body.versions[version].deprecated !== '') {
return false
}
}
return true
}).reply(200, {})

await npm.exec('undeprecate', ['foo'])
t.match(logs.notice, [
'undeprecating [email protected]',
'undeprecating [email protected]',
'undeprecating [email protected]',
])
t.match(joinedOutput(), '')
})

t.test('dry-run', async t => {
const { npm, logs, joinedOutput } = await loadMockNpm(t, { config: {
'dry-run': true,
...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('undeprecate', ['foo'])
t.match(logs.notice, [
'undeprecating [email protected]',
'undeprecating [email protected]',
'undeprecating [email protected]',
])
t.match(joinedOutput(), '')
})

0 comments on commit 1764a37

Please sign in to comment.