From 8583a1738a0793716c60b69c227892db814ff01b Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Wed, 13 Sep 2023 14:09:54 +0000 Subject: [PATCH] Upgrade overrides (#1332). --- src/lib/resolveDepSections.ts | 4 +++- src/types/PackageFile.ts | 1 + test/index.test.ts | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/lib/resolveDepSections.ts b/src/lib/resolveDepSections.ts index 6076918a2..880795a55 100644 --- a/src/lib/resolveDepSections.ts +++ b/src/lib/resolveDepSections.ts @@ -18,7 +18,9 @@ const resolveDepSections = (dep?: string | string[]): (keyof PackageFile)[] => { // map the dependency section option to a full dependency section name const depSections = depOptions.map(name => depAliases[name] || name) - return depSections + // Always include overrides since any upgraded dependencies needed to be upgraded in overrides as well. + // https://github.com/raineorshine/npm-check-updates/issues/1332 + return [...depSections, 'overrides'] } export default resolveDepSections diff --git a/src/types/PackageFile.ts b/src/types/PackageFile.ts index 326bae83e..65d1fcfd3 100644 --- a/src/types/PackageFile.ts +++ b/src/types/PackageFile.ts @@ -13,6 +13,7 @@ export interface PackageFile { // https://nodejs.org/api/packages.html#packagemanager packageManager?: string optionalDependencies?: Index + overrides?: Index peerDependencies?: Index repository?: string | PackageFileRepository scripts?: Index diff --git a/test/index.test.ts b/test/index.test.ts index 71e5fbbcf..bbaa5c714 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -241,4 +241,45 @@ describe('run', function () { }) output!.should.deep.equal({}) }) + + describe('overrides', () => { + it('upgrade overrides', async () => { + const stub = stubNpmView('99.9.9') + const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) + const packageFile = path.join(tempDir, 'package.json') + await fs.writeFile( + packageFile, + JSON.stringify( + { + dependencies: { + 'ncu-test-v2': '^1.0.0', + }, + overrides: { + 'ncu-test-v2': '^1.0.0', + }, + }, + null, + 2, + ), + 'utf-8', + ) + + try { + await ncu({ packageFile, upgrade: true }) + + const upgradedPkg = JSON.parse(await fs.readFile(packageFile, 'utf-8')) + upgradedPkg.should.deep.equal({ + dependencies: { + 'ncu-test-v2': '^99.9.9', + }, + overrides: { + 'ncu-test-v2': '^99.9.9', + }, + }) + } finally { + await fs.rm(tempDir, { recursive: true, force: true }) + stub.restore() + } + }) + }) })