Skip to content

Commit 43a0480

Browse files
authored
fix: respect overrides in pnpm-workspace.yaml (#402)
1 parent 40b1ce9 commit 43a0480

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,28 @@ export async function applyPackageOverrides(
572572
...pkg.pnpm.overrides,
573573
...overrides,
574574
}
575+
// check `overrides` in pnpm-workspace.yaml
576+
const pnpmWorkspaceFile = path.join(dir, 'pnpm-workspace.yaml')
577+
if (fs.existsSync(pnpmWorkspaceFile)) {
578+
const pnpmWorkspaceContent = await fs.promises.readFile(
579+
pnpmWorkspaceFile,
580+
'utf-8',
581+
)
582+
if (/^overrides:/m.test(pnpmWorkspaceContent)) {
583+
delete pkg.pnpm.overrides // remove pnpm.overrides from package.json so that pnpm-workspace.yaml's one is used
584+
const newContent = pnpmWorkspaceContent.replace(
585+
/^overrides:\n/m,
586+
() =>
587+
`overrides:\n${Object.entries(overrides)
588+
.map(
589+
([name, version]) =>
590+
` ${JSON.stringify(name)}: ${JSON.stringify(version)}\n`,
591+
)
592+
.join('')}`,
593+
)
594+
await fs.promises.writeFile(pnpmWorkspaceFile, newContent, 'utf-8')
595+
}
596+
}
575597
} else if (pm === 'yarn') {
576598
pkg.resolutions = {
577599
...pkg.resolutions,

0 commit comments

Comments
 (0)