Skip to content

Commit 44d4331

Browse files
tiegzisaacs
authored andcommitted
Include prerelease versions when deprecating
PR-URL: #2366 Credit: @tiegz Close: #2366 Reviewed-by: @isaacs EDIT(@isaacs): updated to make _all_ deprecation ranges include prereleases. If `foo@*` would be expected to deprecate `[email protected]`, then presumably `[email protected]` has the same expectation.
1 parent a9b8bf2 commit 44d4331

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

docs/content/commands/npm-deprecate.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Deprecate a version of a package
77
### Synopsis
88

99
```bash
10-
npm deprecate <pkg>[@<version>] <message>
10+
npm deprecate <pkg>[@<version range>] <message>
1111
```
1212

1313
### Description
@@ -22,8 +22,17 @@ versions, so you can do something like this:
2222
npm deprecate my-thing@"< 0.2.3" "critical bug fixed in v0.2.3"
2323
```
2424

25-
Note that you must be the package owner to deprecate something. See the
26-
`owner` and `adduser` help topics.
25+
SemVer ranges passed to this command are interpreted such that they *do*
26+
include prerelease versions. For example:
27+
28+
```bash
29+
npm deprecate [email protected] "1.x is no longer supported"
30+
```
31+
32+
In this case, a version `[email protected]` will also be deprecated.
33+
34+
You must be the package owner to deprecate something. See the `owner` and
35+
`adduser` help topics.
2736

2837
To un-deprecate a package, specify an empty string (`""`) for the `message`
2938
argument. Note that you must use double quotes with no space between them to

lib/deprecate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const deprecate = async ([pkg, msg]) => {
5858
})
5959

6060
Object.keys(packument.versions)
61-
.filter(v => semver.satisfies(v, spec))
61+
.filter(v => semver.satisfies(v, spec, { includePrerelease: true }))
6262
.forEach(v => {
6363
packument.versions[v].deprecated = msg
6464
})

test/lib/deprecate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ npmFetch.json = async (uri, opts) => {
1313
versions: {
1414
'1.0.0': {},
1515
'1.0.1': {},
16+
'1.0.1-pre': {},
1617
},
1718
}
1819
}
@@ -126,6 +127,9 @@ test('deprecates all versions when no range is specified', t => {
126127
'1.0.1': {
127128
deprecated: 'this version is deprecated',
128129
},
130+
'1.0.1-pre': {
131+
deprecated: 'this version is deprecated',
132+
},
129133
},
130134
})
131135

0 commit comments

Comments
 (0)