-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade packageManager field by default (#1390).
- Loading branch information
1 parent
1d13783
commit 4a9a34f
Showing
5 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]', | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
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) | ||
|