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

undeprecate / dry-run #8009

Merged
merged 2 commits into from
Jan 6, 2025
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
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
24 changes: 17 additions & 7 deletions lib/commands/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Deprecate extends BaseCommand {
static params = [
'registry',
'otp',
'dry-run',
]

static ignoreImplicitWorkspace = true
Expand Down Expand Up @@ -56,17 +57,26 @@ class Deprecate extends BaseCommand {
const versions = Object.keys(packument.versions)
.filter(v => semver.satisfies(v, spec, { includePrerelease: true }))

const dryRun = this.npm.config.get('dry-run')

if (versions.length) {
for (const v of versions) {
packument.versions[v].deprecated = msg
if (msg) {
log.notice(`deprecating ${packument.name}@${v} with message "${msg}"`)
} else {
log.notice(`undeprecating ${packument.name}@${v}`)
}
}
if (!dryRun) {
return otplease(this.npm, this.npm.flatOptions, opts => npmFetch(uri, {
...opts,
spec: p,
method: 'PUT',
body: packument,
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
ignoreBody: true,
}))
}
return otplease(this.npm, this.npm.flatOptions, opts => npmFetch(uri, {
...opts,
spec: p,
method: 'PUT',
body: packument,
ignoreBody: true,
}))
} else {
log.warn('deprecate', 'No version found for', p.rawSpec)
}
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
33 changes: 32 additions & 1 deletion test/lib/commands/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ t.test('deprecates given range', async t => {
})

t.test('deprecates all versions when no range is specified', 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 @@ -151,6 +151,37 @@ t.test('deprecates all versions when no range is specified', async t => {
}).reply(200, {})

await npm.exec('deprecate', ['foo', message])
t.match(logs.notice, [
`deprecating foo@1.0.0 with message "${message}"`,
`deprecating foo@1.0.1 with message "${message}"`,
`deprecating foo@1.0.1-pre with message "${message}"`,
])
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 } })
const message = 'test deprecation message'

await npm.exec('deprecate', ['foo', message])
t.match(logs.notice, [
`deprecating foo@1.0.0 with message "${message}"`,
`deprecating foo@1.0.1 with message "${message}"`,
`deprecating foo@1.0.1-pre with message "${message}"`,
])
t.match(joinedOutput(), '')
})

Expand Down
Loading
Loading