Skip to content

Commit

Permalink
Upgrade overrides (#1332).
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Sep 13, 2023
1 parent 7b5a879 commit 8583a17
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/resolveDepSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/types/PackageFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface PackageFile {
// https://nodejs.org/api/packages.html#packagemanager
packageManager?: string
optionalDependencies?: Index<VersionSpec>
overrides?: Index<VersionSpec>
peerDependencies?: Index<VersionSpec>
repository?: string | PackageFileRepository
scripts?: Index<string>
Expand Down
41 changes: 41 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
})
})

0 comments on commit 8583a17

Please sign in to comment.