Skip to content

Commit

Permalink
fix(manager/npm): support modern pnpm overrides syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Oct 7, 2024
1 parent 53e6622 commit 32dd0da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/modules/manager/npm/__fixtures__/inputs/02.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"@babel/core": "7.0.0",
"config": "1.21.0"
},
"pnpm": {
"overrides": {
"express>cookie": "0.7.0"
}
},
"homepage": "https://keylocation.sg",
"keywords": [
"Key Location",
Expand Down
9 changes: 8 additions & 1 deletion lib/modules/manager/npm/extract/common/package-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,26 @@ export function extractPackageJson(
),
);
} else if (depType === 'pnpm' && depName === 'overrides') {
// pnpm overrides
// https://pnpm.io/package_json#pnpmoverrides
for (const [overridesKey, overridesVal] of Object.entries(
val as unknown as NpmPackageDependency,
)) {
if (is.string(overridesVal)) {
// Newer flat syntax: `parent>parent>child`
const packageName = overridesKey.split('>').pop()!;
dep = {
depName: overridesKey,
packageName,
depType: 'pnpm.overrides',
...extractDependency(depName, overridesKey, overridesVal),
...extractDependency(depName, packageName, overridesVal),
};
setNodeCommitTopic(dep);
// TODO: Is this expected? It's always 'overrides'.
dep.prettyDepType = depTypes[depName];
deps.push(dep);
} else if (is.object(overridesVal)) {
// Older nested object syntax: `parent: { parent: { child: version } }`
deps.push(
...extractOverrideDepsRec(
[overridesKey],
Expand Down
8 changes: 8 additions & 0 deletions lib/modules/manager/npm/extract/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,14 @@ describe('modules/manager/npm/extract/index', () => {
depType: 'dependencies',
prettyDepType: 'dependency',
},
{
currentValue: '0.7.0',
datasource: 'npm',
depName: 'express>cookie',
packageName: 'cookie',
depType: 'pnpm.overrides',
prettyDepType: 'overrides',
},
],
extractedConstraints: {},
managerData: {
Expand Down

0 comments on commit 32dd0da

Please sign in to comment.