diff --git a/package.json b/package.json index 62b14fe..c22848f 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "rimraf": "^5.0.10", "simple-git-hooks": "^2.11.1", "tsx": "^4.19.1", - "typescript": "^5.6.2" + "typescript": "^5.6.2", + "yaml": "^2.5.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a6c64d8..0ced061 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,6 +63,9 @@ importers: typescript: specifier: ^5.6.2 version: 5.6.2 + yaml: + specifier: ^2.5.1 + version: 2.5.1 packages: diff --git a/tests/vue-macros.ts b/tests/vue-macros.ts index 5af7c8a..2be9827 100644 --- a/tests/vue-macros.ts +++ b/tests/vue-macros.ts @@ -1,13 +1,27 @@ import { runInRepo } from '../utils.ts' -import { RunOptions } from '../types.ts' +import { Overrides, RunOptions } from '../types.ts' +import YAML from 'yaml' export async function test(options: RunOptions) { + const overrideVueVersion = '@^3' await runInRepo({ ...options, repo: 'vue-macros/vue-macros', branch: 'main', build: 'build', test: ['test:ecosystem'], - overrideVueVersion: '@^3', + overrideVueVersion, + patchFiles: { + 'pnpm-workspace.yaml': (content: string, overrides: Overrides) => { + const data = YAML.parse(content) + Object.keys(overrides).forEach((key) => { + const pkgName = key.replace(overrideVueVersion, '') + if (data.catalog[pkgName]) { + data.catalog[pkgName] = overrides[key] + } + }) + return YAML.stringify(data) + }, + }, }) } diff --git a/types.d.ts b/types.d.ts index 0b71219..298daaa 100644 --- a/types.d.ts +++ b/types.d.ts @@ -23,7 +23,7 @@ export interface RunOptions { beforeInstall?: Task | Task[] beforeBuild?: Task | Task[] beforeTest?: Task | Task[] - patchFiles?: Record string> + patchFiles?: Record string> } type Task = string | { script: string; args?: string[] } | (() => Promise) diff --git a/utils.ts b/utils.ts index 516789a..0372e1e 100644 --- a/utils.ts +++ b/utils.ts @@ -267,16 +267,6 @@ export async function runInRepo(options: RunOptions & RepoOptions) { ) } - if (patchFiles) { - for (const fileName in patchFiles) { - const filePath = path.resolve(dir, fileName) - const patchFn = patchFiles[fileName] - const content = fs.readFileSync(filePath, 'utf-8') - fs.writeFileSync(filePath, patchFn(content)) - console.log(`patched file: ${fileName}`) - } - } - const agent = options.agent const beforeInstallCommand = toCommand(beforeInstall, agent) const beforeBuildCommand = toCommand(beforeBuild, agent) @@ -325,6 +315,17 @@ export async function runInRepo(options: RunOptions & RepoOptions) { overrides[pkg.name] ||= pkg.hashedVersion } } + + if (patchFiles) { + for (const fileName in patchFiles) { + const filePath = path.resolve(dir, fileName) + const patchFn = patchFiles[fileName] + const content = fs.readFileSync(filePath, 'utf-8') + fs.writeFileSync(filePath, patchFn(content, overrides)) + console.log(`patched file: ${fileName}`) + } + } + await applyPackageOverrides(dir, pkg, overrides) await beforeBuildCommand?.(pkg.scripts)