Skip to content

Commit 5fabe00

Browse files
committed
feat: add dry-run to deprecate/undeprecate commands
1 parent 434a83d commit 5fabe00

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

lib/commands/deprecate.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Deprecate extends BaseCommand {
1414
static params = [
1515
'registry',
1616
'otp',
17+
'dry-run',
1718
]
1819

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

60+
const dryRun = this.npm.config.get('dry-run')
61+
5962
if (versions.length) {
6063
for (const v of versions) {
6164
packument.versions[v].deprecated = msg
65+
if (msg) {
66+
log.notice(`deprecating ${packument.name}@${v} with message "${msg}"`)
67+
} else {
68+
log.notice(`undeprecating ${packument.name}@${v}`)
69+
}
70+
}
71+
if (!dryRun) {
72+
return otplease(this.npm, this.npm.flatOptions, opts => npmFetch(uri, {
73+
...opts,
74+
spec: p,
75+
method: 'PUT',
76+
body: packument,
77+
ignoreBody: true,
78+
}))
6279
}
63-
return otplease(this.npm, this.npm.flatOptions, opts => npmFetch(uri, {
64-
...opts,
65-
spec: p,
66-
method: 'PUT',
67-
body: packument,
68-
ignoreBody: true,
69-
}))
7080
} else {
7181
log.warn('deprecate', 'No version found for', p.rawSpec)
7282
}

test/lib/commands/deprecate.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ t.test('deprecates given range', async t => {
129129
})
130130

131131
t.test('deprecates all versions when no range is specified', async t => {
132-
const { npm, joinedOutput } = await loadMockNpm(t, { config: { ...auth } })
132+
const { npm, logs, joinedOutput } = await loadMockNpm(t, { config: { ...auth } })
133133
const registry = new MockRegistry({
134134
tap: t,
135135
registry: npm.config.get('registry'),
@@ -151,6 +151,37 @@ t.test('deprecates all versions when no range is specified', async t => {
151151
}).reply(200, {})
152152

153153
await npm.exec('deprecate', ['foo', message])
154+
t.match(logs.notice, [
155+
`deprecating [email protected] with message "${message}"`,
156+
`deprecating [email protected] with message "${message}"`,
157+
`deprecating [email protected] with message "${message}"`,
158+
])
159+
t.match(joinedOutput(), '')
160+
})
161+
162+
t.test('dry-run', async t => {
163+
const { npm, logs, joinedOutput } = await loadMockNpm(t, { config: {
164+
'dry-run': true,
165+
...auth,
166+
} })
167+
const registry = new MockRegistry({
168+
tap: t,
169+
registry: npm.config.get('registry'),
170+
authorization: token,
171+
})
172+
const manifest = registry.manifest({
173+
name: 'foo',
174+
versions,
175+
})
176+
await registry.package({ manifest, query: { write: true } })
177+
const message = 'test deprecation message'
178+
179+
await npm.exec('deprecate', ['foo', message])
180+
t.match(logs.notice, [
181+
`deprecating [email protected] with message "${message}"`,
182+
`deprecating [email protected] with message "${message}"`,
183+
`deprecating [email protected] with message "${message}"`,
184+
])
154185
t.match(joinedOutput(), '')
155186
})
156187

0 commit comments

Comments
 (0)