Skip to content

Commit

Permalink
Include prerelease versions when deprecating
Browse files Browse the repository at this point in the history
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
`foo@1.0.0-beta`, then presumably `foo@1.x` has the same expectation.
  • Loading branch information
tiegz authored and isaacs committed Dec 18, 2020
1 parent a9b8bf2 commit 44d4331
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions docs/content/commands/npm-deprecate.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Deprecate a version of a package
### Synopsis

```bash
npm deprecate <pkg>[@<version>] <message>
npm deprecate <pkg>[@<version range>] <message>
```

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

Note that you must be the package owner to deprecate something. See the
`owner` and `adduser` help topics.
SemVer ranges passed to this command are interpreted such that they *do*
include prerelease versions. For example:

```bash
npm deprecate my-thing@1.x "1.x is no longer supported"
```

In this case, a version `my-thing@1.0.0-beta.0` will also be deprecated.

You must be the package owner to deprecate something. See the `owner` and
`adduser` help topics.

To un-deprecate a package, specify an empty string (`""`) for the `message`
argument. Note that you must use double quotes with no space between them to
Expand Down
2 changes: 1 addition & 1 deletion lib/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const deprecate = async ([pkg, msg]) => {
})

Object.keys(packument.versions)
.filter(v => semver.satisfies(v, spec))
.filter(v => semver.satisfies(v, spec, { includePrerelease: true }))
.forEach(v => {
packument.versions[v].deprecated = msg
})
Expand Down
4 changes: 4 additions & 0 deletions test/lib/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ npmFetch.json = async (uri, opts) => {
versions: {
'1.0.0': {},
'1.0.1': {},
'1.0.1-pre': {},
},
}
}
Expand Down Expand Up @@ -126,6 +127,9 @@ test('deprecates all versions when no range is specified', t => {
'1.0.1': {
deprecated: 'this version is deprecated',
},
'1.0.1-pre': {
deprecated: 'this version is deprecated',
},
},
})

Expand Down

0 comments on commit 44d4331

Please sign in to comment.