Skip to content

Commit 2107fc3

Browse files
authored
fix: apply overrides to pnpm-workspace.yaml if exists (#33)
1 parent edc077b commit 2107fc3

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

tests/vue-macros.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ export async function test(options: RunOptions) {
1414
test: ['test:ecosystem'],
1515
overrideVueVersion,
1616

17-
// It's already overridden in pnpm-workspace.yaml in the original repo
18-
// but somehow it doesn't take effect when we also have overrides in package.json
19-
// So we have to override it here again
20-
// TODO: should handle such cases in the codebase rather than patching manually in each repo
21-
overrides: {
22-
vite: '^7.1.3',
23-
},
2417
patchFiles: {
2518
'pnpm-workspace.yaml': (content: string, overrides: Overrides) => {
2619
const data = YAML.parse(content)

utils.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { REGISTRY_ADDRESS, startRegistry } from './registry.ts'
1414
import { detect, AGENTS, getCommand, serializeCommand } from '@antfu/ni'
1515
import actionsCore from '@actions/core'
16+
import YAML from 'yaml'
1617

1718
const isGitHubActions = !!process.env.GITHUB_ACTIONS
1819

@@ -601,15 +602,46 @@ export async function applyPackageOverrides(
601602
// ...pkg.devDependencies,
602603
// ...overrides, // overrides must be present in devDependencies or dependencies otherwise they may not work
603604
// }
604-
pkg.pnpm ||= {}
605-
pkg.pnpm.overrides = {
606-
...pkg.pnpm.overrides,
607-
...overrides,
608-
}
609-
pkg.pnpm.peerDependencyRules ||= {}
610-
pkg.pnpm.peerDependencyRules.allowedVersions = {
611-
...pkg.pnpm.peerDependencyRules.allowedVersions,
612-
...overrides,
605+
const workspacePath = path.join(dir, 'pnpm-workspace.yaml')
606+
if (fs.existsSync(workspacePath)) {
607+
const data = YAML.parse(fs.readFileSync(workspacePath, 'utf-8'))
608+
if (data.overrides) {
609+
data.overrides = {
610+
...data.overrides,
611+
...overrides,
612+
}
613+
} else {
614+
pkg.pnpm ||= {}
615+
pkg.pnpm.overrides = {
616+
...pkg.pnpm.overrides,
617+
...overrides,
618+
}
619+
}
620+
if (data.peerDependencyRules?.allowedVersions) {
621+
data.peerDependencyRules.allowedVersions = {
622+
...data.peerDependencyRules.allowedVersions,
623+
...overrides,
624+
}
625+
} else {
626+
pkg.pnpm ||= {}
627+
pkg.pnpm.peerDependencyRules ||= {}
628+
pkg.pnpm.peerDependencyRules.allowedVersions = {
629+
...pkg.pnpm.peerDependencyRules.allowedVersions,
630+
...overrides,
631+
}
632+
}
633+
fs.writeFileSync(workspacePath, YAML.stringify(data))
634+
} else {
635+
pkg.pnpm ||= {}
636+
pkg.pnpm.overrides = {
637+
...pkg.pnpm.overrides,
638+
...overrides,
639+
}
640+
pkg.pnpm.peerDependencyRules ||= {}
641+
pkg.pnpm.peerDependencyRules.allowedVersions = {
642+
...pkg.pnpm.peerDependencyRules.allowedVersions,
643+
...overrides,
644+
}
613645
}
614646
} else if (pm === 'yarn') {
615647
pkg.resolutions = {

0 commit comments

Comments
 (0)