Skip to content

Commit

Permalink
Exclude deprecated packages by default. Add --deprecated to include. F…
Browse files Browse the repository at this point in the history
…ixes #624.
  • Loading branch information
raineorshine committed Sep 10, 2020
1 parent a2b2917 commit 3ba1523
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog
This file documents all **major version** releases. For other releases, you'll have to read the [commit history](https://github.com/raineorshine/npm-check-updates/).

## [9.0.0] - 2020-09-10

### Breaking

- Versions marked as `deprecated` in npm are now ignored by default. If the latest version is deprecated, the next highest non-deprecated version will be suggested. Use `--deprecated` to include deprecated versions (old behavior).

https://github.com/raineorshine/npm-check-updates/compare/v8.1.1...v9.0.0

## [8.0.0] - 2020-08-29

### Breaking
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ $ ncu "/^(?!gulp-).*$/" # windows
--dep <dep> Check one or more sections of dependencies only:
prod, dev, peer, optional, bundle
(comma-delimited).
--deprecated Include deprecated packages.
--doctor Iteratively installs upgrades and runs tests to
identify breaking upgrades. Run "ncu --doctor"
for detailed help. Add "-u" to execute.
Expand Down
4 changes: 4 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const cliOptions = [
name: '--dep <dep>',
description: 'Check one or more sections of dependencies only: prod, dev, peer, optional, bundle (comma-delimited).'
},
{
name: '--deprecated',
description: 'Include deprecated packages.'
},
{
name: '--doctor',
description: 'Iteratively installs upgrades and runs tests to identify breaking upgrades. Run "ncu --doctor" for detailed help. Add "-u" to execute.',
Expand Down
3 changes: 3 additions & 0 deletions lib/npm-check-updates.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ declare namespace ncu {
/** Check one or more sections of dependencies only: prod, dev, peer, optional, bundle (comma-delimited). */
dep?: string;

/** Include deprecated packages. */
deprecated?: boolean;

/** Iteratively installs upgrades and runs tests to identify breaking upgrades. Run "ncu --doctor" for detailed help. Add "-u" to execute. */
doctor?: boolean;

Expand Down
5 changes: 4 additions & 1 deletion lib/package-managers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ function satisfiesNodeEngine(versionResult, nodeEngine) {
return versionNodeEngine && semver.satisfies(minVersion, versionNodeEngine)
}

/** Returns a composite predicate that filters out prerelease, and node engine incompatibilies from version objects returns by pacote.packument. */
/** Returns a composite predicate that filters out deprecated, prerelease, and node engine incompatibilies from version objects returns by pacote.packument. */
function filterPredicate(options) {
return _.overEvery([
options.deprecated ? null : o => !o.deprecated,
options.pre ? null : o => !versionUtil.isPre(o.version),
options.enginesNode ? o => satisfiesNodeEngine(o, options.enginesNode) : null,
])
Expand Down Expand Up @@ -267,12 +268,14 @@ module.exports = {

const latest = await viewOne(packageName, 'dist-tags.latest', currentVersion, { timeout: options.timeout })

// latest should not be deprecated
// if latest exists and latest is not a prerelease version, return it
// if latest exists and latest is a prerelease version and --pre is specified, return it
// if latest exists and latest not satisfies min version of engines.node
if (latest && filterPredicate(options)(latest)) return latest.version

// if latest is a prerelease version and --pre is not specified
// or latest is deprecated
// find the next valid version
const versions = await viewOne(packageName, 'versions', currentVersion)
const validVersions = _.filter(versions, filterPredicate(options))
Expand Down
10 changes: 10 additions & 0 deletions test/package-managers/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ describe('npm', function () {
parseInt(version, 10).should.be.above(1)
})

it('deprecated excluded by default', async () => {
const latest = await packageManagers.npm.latest('ncu-test-deprecated', null, { cwd: __dirname })
latest.should.equal('1.0.0')
})

it('deprecated included with option', async () => {
const latest = await packageManagers.npm.latest('ncu-test-deprecated', null, { deprecated: true, cwd: __dirname })
latest.should.equal('2.0.0')
})

it('greatest', async () => {
const version = await packageManagers.npm.greatest('ncu-test-greatest-not-newest', null, { pre: true, cwd: __dirname })
version.should.equal('2.0.0-beta')
Expand Down

0 comments on commit 3ba1523

Please sign in to comment.