diff --git a/README.md b/README.md
index 6507d25f..e9e5d250 100644
--- a/README.md
+++ b/README.md
@@ -198,7 +198,7 @@ Options that take no arguments can be negated by prefixing them with `--no-`, e.
--dep <value> |
- Check one or more sections of dependencies only: dev, optional, peer, prod, or packageManager (comma-delimited). (default: ["prod","dev","optional"]) |
+ Check one or more sections of dependencies only: dev, optional, peer, prod, or packageManager (comma-delimited). (default: ["prod","dev","optional","packageManager"]) |
--deprecated |
diff --git a/src/cli-options.ts b/src/cli-options.ts
index 1b1915ac..d2a94bc9 100755
--- a/src/cli-options.ts
+++ b/src/cli-options.ts
@@ -585,7 +585,7 @@ const cliOptions: CLIOption[] = [
arg: 'value',
description:
'Check one or more sections of dependencies only: dev, optional, peer, prod, or packageManager (comma-delimited).',
- default: ['prod', 'dev', 'optional'],
+ default: ['prod', 'dev', 'optional', 'packageManager'],
parse: value => (value && typeof value === 'string' ? value.split(',') : value),
type: 'string | string[]',
},
diff --git a/src/types/RunOptions.json b/src/types/RunOptions.json
index 698eebdb..16c9cbcc 100644
--- a/src/types/RunOptions.json
+++ b/src/types/RunOptions.json
@@ -214,7 +214,7 @@
"type": "string"
}
],
- "default": ["prod", "dev", "optional"],
+ "default": ["prod", "dev", "optional", "packageManager"],
"description": "Check one or more sections of dependencies only: dev, optional, peer, prod, or packageManager (comma-delimited)."
},
"deprecated": {
diff --git a/src/types/RunOptions.ts b/src/types/RunOptions.ts
index 17a7cc30..e4565233 100644
--- a/src/types/RunOptions.ts
+++ b/src/types/RunOptions.ts
@@ -48,7 +48,7 @@ export interface RunOptions {
/** Check one or more sections of dependencies only: dev, optional, peer, prod, or packageManager (comma-delimited).
*
- * @default ["prod","dev","optional"]
+ * @default ["prod","dev","optional","packageManager"]
*/
dep?: string | string[]
diff --git a/test/dep.test.ts b/test/dep.test.ts
index 7bf2bf6a..bc008065 100644
--- a/test/dep.test.ts
+++ b/test/dep.test.ts
@@ -199,7 +199,7 @@ describe('--dep', () => {
})
describe('packageManager field', () => {
- it('support packageManager field', async () => {
+ it('upgrade packageManager field by default', async () => {
const stub = stubVersions({
'ncu-test-tag': '1.0.0',
npm: '9.0.0',
@@ -224,7 +224,6 @@ describe('--dep', () => {
packageFile: pkgFile,
jsonUpgraded: false,
upgrade: true,
- dep: 'prod,packageManager',
})
const pkgDataNew = await fs.readFile(pkgFile, 'utf-8')
const pkgNew = JSON.parse(pkgDataNew)
@@ -241,6 +240,48 @@ describe('--dep', () => {
}
})
+ it('do not upgrade packageManager field if missing from --dep', async () => {
+ const stub = stubVersions({
+ 'ncu-test-tag': '1.0.0',
+ npm: '9.0.0',
+ })
+ const packageData = JSON.stringify(
+ {
+ packageManager: 'npm@6.0.0',
+ dependencies: {
+ 'ncu-test-tag': '0.1.0',
+ },
+ },
+ null,
+ 2,
+ )
+
+ const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
+ const pkgFile = path.join(tempDir, 'package.json')
+ await fs.writeFile(pkgFile, packageData)
+
+ try {
+ await ncu({
+ packageFile: pkgFile,
+ jsonUpgraded: false,
+ upgrade: true,
+ dep: ['prod'],
+ })
+ const pkgDataNew = await fs.readFile(pkgFile, 'utf-8')
+ const pkgNew = JSON.parse(pkgDataNew)
+
+ pkgNew.should.deep.equal({
+ packageManager: 'npm@6.0.0',
+ dependencies: {
+ 'ncu-test-tag': '1.0.0',
+ },
+ })
+ } finally {
+ await fs.rm(tempDir, { recursive: true, force: true })
+ stub.restore()
+ }
+ })
+
it('do nothing if no packageManager field is present', async () => {
const stub = stubVersions({
'ncu-test-tag': '1.0.0',
@@ -265,7 +306,6 @@ describe('--dep', () => {
packageFile: pkgFile,
jsonUpgraded: false,
upgrade: true,
- dep: 'prod,packageManager',
})
const pkgDataNew = await fs.readFile(pkgFile, 'utf-8')
const pkgNew = JSON.parse(pkgDataNew)
@@ -281,6 +321,48 @@ describe('--dep', () => {
}
})
+ it('upgrade packageManager field if specified in --dep', async () => {
+ const stub = stubVersions({
+ 'ncu-test-tag': '1.0.0',
+ npm: '9.0.0',
+ })
+ const packageData = JSON.stringify(
+ {
+ packageManager: 'npm@6.0.0',
+ dependencies: {
+ 'ncu-test-tag': '0.1.0',
+ },
+ },
+ null,
+ 2,
+ )
+
+ const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
+ const pkgFile = path.join(tempDir, 'package.json')
+ await fs.writeFile(pkgFile, packageData)
+
+ try {
+ await ncu({
+ packageFile: pkgFile,
+ jsonUpgraded: false,
+ upgrade: true,
+ dep: ['prod', 'packageManager'],
+ })
+ const pkgDataNew = await fs.readFile(pkgFile, 'utf-8')
+ const pkgNew = JSON.parse(pkgDataNew)
+
+ pkgNew.should.deep.equal({
+ packageManager: 'npm@9.0.0',
+ dependencies: {
+ 'ncu-test-tag': '1.0.0',
+ },
+ })
+ } finally {
+ await fs.rm(tempDir, { recursive: true, force: true })
+ stub.restore()
+ }
+ })
+
it('do nothing if packageManager is up-to-date', async () => {
const stub = stubVersions({
'ncu-test-tag': '1.0.0',
@@ -306,7 +388,6 @@ describe('--dep', () => {
packageFile: pkgFile,
jsonUpgraded: false,
upgrade: true,
- dep: 'prod,packageManager',
})
const pkgDataNew = await fs.readFile(pkgFile, 'utf-8')
const pkgNew = JSON.parse(pkgDataNew)