Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit f8fb4d8

Browse files
polmzkat
authored andcommitted
deprecate: default to * instead of latest
When a semver spec is not supplied, npa supplies a default spec of 'latest'. This is usually correct, but for deprecation the default has been to apply to all versions of a package. This patch just checks the raw spec and if it's empty it overrides with with the '*' version range, which is what people in the issue discussion were doing anyway. Fixes: #10974 PR-URL: #12079 Credit: @polm Reviewed-By: @zkat
1 parent af30c37 commit f8fb4d8

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/deprecate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function deprecate (args, cb) {
3737
// fetch the data and make sure it exists.
3838
var p = npa(pkg)
3939

40+
// npa makes the default spec "latest", but for deprecation
41+
// "*" is the appropriate default.
42+
if (p.rawSpec === '') p.spec = '*'
43+
4044
mapToRegistry(p.name, npm.config, function (er, uri, auth) {
4145
if (er) return cb(er)
4246

test/tap/deprecate.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ test('npm deprecate bad semver range', function (t) {
126126
})
127127
})
128128

129+
test('npm deprecate a package with no semver range', function (t) {
130+
var deprecated = JSON.parse(JSON.stringify(cache))
131+
deprecated.versions = {
132+
'0.0.0': { deprecated: 'make it dead' },
133+
'0.0.1': { deprecated: 'make it dead' },
134+
'0.0.2': { deprecated: 'make it dead' }
135+
}
136+
server.get('/cond?write=true').reply(200, cache)
137+
server.put('/cond', deprecated).reply(201, { deprecated: true })
138+
common.npm([
139+
'deprecate',
140+
'cond',
141+
'make it dead',
142+
'--registry', common.registry,
143+
'--loglevel', 'silent'
144+
], {},
145+
function (er, code, stdout, stderr) {
146+
t.ifError(er, 'npm deprecate')
147+
t.equal(stderr, '', 'no error output')
148+
t.equal(code, 0, 'exited OK')
149+
t.end()
150+
})
151+
})
152+
129153
test('cleanup', function (t) {
130154
server.close()
131155
t.ok(true)

0 commit comments

Comments
 (0)