From e70bd4575676209536c5eba2c22082ed6f7581b8 Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Wed, 20 Oct 2021 11:15:03 -0600 Subject: [PATCH] Do not upgrade peerDependencies by default. Closes #951. --- README.md | 5 +++-- lib/cli-options.js | 3 ++- lib/doctor.js | 1 - lib/index.d.ts | 2 +- lib/versionmanager.js | 4 +++- test/index.test.js | 14 +++++++++++++- test/versionmanager.test.js | 10 +--------- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 48484e59..70d24634 100644 --- a/README.md +++ b/README.md @@ -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 @@ -136,7 +136,8 @@ ncu "/^(?!react-).*$/" # windows Alias of (--packageFile '**/package.json'). --dep 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" diff --git a/lib/cli-options.js b/lib/cli-options.js index 52f432cf..f01998fd 100644 --- a/lib/cli-options.js +++ b/lib/cli-options.js @@ -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', diff --git a/lib/doctor.js b/lib/doctor.js index 7aa92809..d18ddb75 100644 --- a/lib/doctor.js +++ b/lib/doctor.js @@ -65,7 +65,6 @@ const doctor = async (run, options) => { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.optionalDependencies, - ...pkg.peerDependencies, ...pkg.bundleDependencies, } diff --git a/lib/index.d.ts b/lib/index.d.ts index dbfc19f9..97f915fc 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -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; diff --git a/lib/versionmanager.js b/lib/versionmanager.js index a199cd3a..88620def 100644 --- a/lib/versionmanager.js +++ b/lib/versionmanager.js @@ -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') diff --git a/test/index.test.js b/test/index.test.js index 918c85e2..be81c418 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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' diff --git a/test/versionmanager.test.js b/test/versionmanager.test.js index 13af04c7..ae3718f7 100644 --- a/test/versionmanager.test.js +++ b/test/versionmanager.test.js @@ -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' }) }) @@ -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' }) }) @@ -228,7 +225,6 @@ describe('versionmanager', () => { mocha: '1.2', lodash: '^3.9.3', bluebird: '^1.0.0', - moment: '^1.0.0' }) }) @@ -238,7 +234,6 @@ describe('versionmanager', () => { lodash: '^3.9.3', chalk: '^1.1.0', bluebird: '^1.0.0', - moment: '^1.0.0' }) }) @@ -246,17 +241,14 @@ describe('versionmanager', () => { 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' }) })