Skip to content

Commit e7e3d07

Browse files
authored
fix(vue-macros): override catalog (#17)
* fix(vue-macros): override catelog
1 parent 384a10f commit e7e3d07

File tree

5 files changed

+64
-38
lines changed

5 files changed

+64
-38
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
"rimraf": "^5.0.10",
6464
"simple-git-hooks": "^2.11.1",
6565
"tsx": "^4.19.1",
66-
"typescript": "^5.6.2"
66+
"typescript": "^5.6.2",
67+
"yaml": "^2.5.1"
68+
},
69+
"pnpm": {
70+
"overrides": {
71+
"cookie@<0.7.0": ">=0.7.0"
72+
}
6773
}
6874
}

pnpm-lock.yaml

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/vue-macros.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import { runInRepo } from '../utils.ts'
2-
import { RunOptions } from '../types.ts'
2+
import { Overrides, RunOptions } from '../types.ts'
3+
import YAML from 'yaml'
34

45
export async function test(options: RunOptions) {
6+
const overrideVueVersion = '@^3'
57
await runInRepo({
68
...options,
79
repo: 'vue-macros/vue-macros',
810
branch: 'main',
911
build: 'build',
1012
test: ['test:ecosystem'],
11-
overrideVueVersion: '@^3',
13+
overrideVueVersion,
14+
patchFiles: {
15+
'pnpm-workspace.yaml': (content: string, overrides: Overrides) => {
16+
const data = YAML.parse(content)
17+
Object.keys(overrides).forEach((key) => {
18+
const pkgName = key.replace(overrideVueVersion, '')
19+
if (data.catalog[pkgName]) {
20+
data.catalog[pkgName] = overrides[key]
21+
}
22+
})
23+
return YAML.stringify(data)
24+
},
25+
},
1226
})
1327
}

types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface RunOptions {
2323
beforeInstall?: Task | Task[]
2424
beforeBuild?: Task | Task[]
2525
beforeTest?: Task | Task[]
26-
patchFiles?: Record<string, (content: string) => string>
26+
patchFiles?: Record<string, (content: string, overrides: Overrides) => string>
2727
}
2828

2929
type Task = string | { script: string; args?: string[] } | (() => Promise<any>)

utils.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,40 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
267267
)
268268
}
269269

270+
const overrides = options.overrides || {}
271+
const vuePackages = await getVuePackages()
272+
273+
if (options.release) {
274+
// pkg.pr.new support
275+
for (const pkg of vuePackages) {
276+
let version = options.release
277+
if (options.release.startsWith('@')) {
278+
version = `https://pkg.pr.new/${pkg.name}@${options.release.slice(1)}`
279+
}
280+
if (overrides[pkg.name] && overrides[pkg.name] !== version) {
281+
throw new Error(
282+
`conflicting overrides[${pkg.name}]=${
283+
overrides[pkg.name]
284+
} and --release=${
285+
options.release
286+
} config. Use either one or the other`,
287+
)
288+
} else {
289+
overrides[`${pkg.name}${overrideVueVersion}`] = version
290+
}
291+
}
292+
} else {
293+
for (const pkg of vuePackages) {
294+
overrides[pkg.name] ||= pkg.hashedVersion
295+
}
296+
}
297+
270298
if (patchFiles) {
271299
for (const fileName in patchFiles) {
272300
const filePath = path.resolve(dir, fileName)
273301
const patchFn = patchFiles[fileName]
274302
const content = fs.readFileSync(filePath, 'utf-8')
275-
fs.writeFileSync(filePath, patchFn(content))
303+
fs.writeFileSync(filePath, patchFn(content, overrides))
276304
console.log(`patched file: ${fileName}`)
277305
}
278306
}
@@ -297,36 +325,8 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
297325
await beforeTestCommand?.(pkg.scripts)
298326
await testCommand?.(pkg.scripts)
299327
}
300-
const overrides = options.overrides || {}
301-
302-
const vuePackages = await getVuePackages()
303328

304-
if (options.release) {
305-
// pkg.pr.new support
306-
for (const pkg of vuePackages) {
307-
let version = options.release
308-
if (options.release.startsWith('@')) {
309-
version = `https://pkg.pr.new/${pkg.name}@${options.release.slice(1)}`
310-
}
311-
if (overrides[pkg.name] && overrides[pkg.name] !== version) {
312-
throw new Error(
313-
`conflicting overrides[${pkg.name}]=${
314-
overrides[pkg.name]
315-
} and --release=${
316-
options.release
317-
} config. Use either one or the other`,
318-
)
319-
} else {
320-
overrides[`${pkg.name}${overrideVueVersion}`] = version
321-
}
322-
}
323-
} else {
324-
for (const pkg of vuePackages) {
325-
overrides[pkg.name] ||= pkg.hashedVersion
326-
}
327-
}
328329
await applyPackageOverrides(dir, pkg, overrides)
329-
330330
await beforeBuildCommand?.(pkg.scripts)
331331
await buildCommand?.(pkg.scripts)
332332
if (test) {

0 commit comments

Comments
 (0)