Skip to content

Commit

Permalink
Do not upgrade peerDependencies by default. Closes #951.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Oct 20, 2021
1 parent f773263 commit e70bd45
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ npx npm-check-updates

## Usage

Show any new dependencies for the project in the current directory:
Show all new dependencies ([excluding peerDependencies](https://github.com/raineorshine/npm-check-updates/issues/951)) for the project in the current directory:

```sh
$ ncu
Expand Down Expand Up @@ -136,7 +136,8 @@ ncu "/^(?!react-).*$/" # windows
Alias of (--packageFile '**/package.json').
--dep <value> Check one or more sections of dependencies only:
dev, optional, peer, prod, bundle
(comma-delimited).
(comma-delimited). (default:
"prod,dev,bundle,optional")
--deprecated Include deprecated packages.
--doctor Iteratively installs upgrades and runs tests to
identify breaking upgrades. Run "ncu --doctor"
Expand Down
3 changes: 2 additions & 1 deletion lib/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ As a comparison: without using the --peer option, ncu will suggest the latest ve
{
long: 'dep',
arg: 'value',
description: 'Check one or more sections of dependencies only: dev, optional, peer, prod, bundle (comma-delimited).'
description: 'Check one or more sections of dependencies only: dev, optional, peer, prod, bundle (comma-delimited).',
default: 'prod,dev,bundle,optional'
},
{
long: 'deprecated',
Expand Down
1 change: 0 additions & 1 deletion lib/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const doctor = async (run, options) => {
...pkg.dependencies,
...pkg.devDependencies,
...pkg.optionalDependencies,
...pkg.peerDependencies,
...pkg.bundleDependencies,
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare namespace ncu {
deep?: boolean;

/**
* Check one or more sections of dependencies only: dev, optional, peer, prod, bundle (comma-delimited).
* Check one or more sections of dependencies only: dev, optional, peer, prod, bundle (comma-delimited). (default: "prod,dev,bundle,optional")
*/
dep?: string;

Expand Down
4 changes: 3 additions & 1 deletion lib/versionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ function getCurrentDependencies(pkgData = {}, options = {}) {

const depOptions = options.dep
? (options.dep || '').split(',')
: ['dev', 'optional', 'peer', 'prod', 'bundle']
// exclude peerDependencies
// https://github.com/raineorshine/npm-check-updates/issues/951
: ['dev', 'optional', 'prod', 'bundle']

// map the dependency section option to a full dependency section name
const depSections = depOptions.map(short => short === 'prod' ? 'dependencies' : short + 'Dependencies')
Expand Down
14 changes: 13 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ describe('run', function () {
return upgraded.should.eventually.not.have.property('juggernaut')
})

it('only upgrade devDependencies and peerDependencies with --dep dev', () => {
it('do not upgrade peerDependencies by default', () => {
const upgraded = ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package-dep.json'), 'utf-8')
})

return Promise.all([
upgraded.should.eventually.have.property('express'),
upgraded.should.eventually.have.property('chalk'),
upgraded.should.eventually.not.have.property('mocha')
])
})

it('only upgrade devDependencies with --dep dev', () => {
const upgraded = ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package-dep.json'), 'utf-8'),
dep: 'dev'
Expand Down
10 changes: 1 addition & 9 deletions test/versionmanager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ describe('versionmanager', () => {
vm.getCurrentDependencies({}, {}).should.eql({})
})

it('get dependencies, devDependencies, and optionalDependencies by default', () => {
it('get dependencies, devDependencies, bundleDegendencies, and optionalDependencies by default', () => {
vm.getCurrentDependencies(deps).should.eql({
mocha: '1.2',
lodash: '^3.9.3',
chalk: '^1.1.0',
bluebird: '^1.0.0',
moment: '^1.0.0'
})
})

Expand Down Expand Up @@ -205,12 +204,10 @@ describe('versionmanager', () => {
vm.getCurrentDependencies(deps, { filter: /o/ }).should.eql({
lodash: '^3.9.3',
mocha: '1.2',
moment: '^1.0.0'
})
vm.getCurrentDependencies(deps, { filter: '/o/' }).should.eql({
lodash: '^3.9.3',
mocha: '1.2',
moment: '^1.0.0'
})
})

Expand All @@ -228,7 +225,6 @@ describe('versionmanager', () => {
mocha: '1.2',
lodash: '^3.9.3',
bluebird: '^1.0.0',
moment: '^1.0.0'
})
})

Expand All @@ -238,25 +234,21 @@ describe('versionmanager', () => {
lodash: '^3.9.3',
chalk: '^1.1.0',
bluebird: '^1.0.0',
moment: '^1.0.0'
})
})

it('reject dependencies by multiple packages', () => {
vm.getCurrentDependencies(deps, { reject: 'mocha lodash' }).should.eql({
chalk: '^1.1.0',
bluebird: '^1.0.0',
moment: '^1.0.0'
})
vm.getCurrentDependencies(deps, { reject: 'mocha,lodash' }).should.eql({
chalk: '^1.1.0',
bluebird: '^1.0.0',
moment: '^1.0.0'
})
vm.getCurrentDependencies(deps, { reject: ['mocha', 'lodash'] }).should.eql({
chalk: '^1.1.0',
bluebird: '^1.0.0',
moment: '^1.0.0'
})
})

Expand Down

0 comments on commit e70bd45

Please sign in to comment.