From f848feadc8024513de9e29538fd829c60471bbf5 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 12 Oct 2024 19:41:05 +0800 Subject: [PATCH 1/4] fix(vue-macros): override catelog --- package.json | 3 ++- pnpm-lock.yaml | 3 +++ tests/vue-macros.ts | 18 ++++++++++++++++-- types.d.ts | 2 +- utils.ts | 21 +++++++++++---------- 5 files changed, 33 insertions(+), 14 deletions(-) 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) From a1fd4185cafca89b32b9571baa8ce2e34f5f5e46 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 12 Oct 2024 21:28:07 +0800 Subject: [PATCH 2/4] chore: fix pnpm audit failure --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index c22848f..3b630f3 100644 --- a/package.json +++ b/package.json @@ -65,5 +65,10 @@ "tsx": "^4.19.1", "typescript": "^5.6.2", "yaml": "^2.5.1" + }, + "pnpm": { + "overrides": { + "cookie@<0.7.0": ">=0.7.0" + } } } From dc4d84505a1a305c55abeb19d38e3028205bd525 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 12 Oct 2024 21:29:24 +0800 Subject: [PATCH 3/4] chore: update lockfile --- pnpm-lock.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0ced061..ebcb290 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + cookie@<0.7.0: '>=0.7.0' + importers: .: @@ -655,9 +658,9 @@ packages: cookie-signature@1.0.6: resolution: {integrity: sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==} - cookie@0.6.0: - resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==} - engines: {node: '>= 0.6'} + cookie@1.0.1: + resolution: {integrity: sha512-Xd8lFX4LM9QEEwxQpF9J9NTUh8pmdJO0cyRJhFiDoLTk2eH8FXlRv2IFGYVadZpqI3j8fhNrSdKCeYPxiAhLXw==} + engines: {node: '>=18'} core-js@3.37.1: resolution: {integrity: sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw==} @@ -2717,7 +2720,7 @@ snapshots: cookie-signature@1.0.6: {} - cookie@0.6.0: {} + cookie@1.0.1: {} core-js@3.37.1: {} @@ -3003,7 +3006,7 @@ snapshots: body-parser: 1.20.3 content-disposition: 0.5.4 content-type: 1.0.5 - cookie: 0.6.0 + cookie: 1.0.1 cookie-signature: 1.0.6 debug: 2.6.9 depd: 2.0.0 From a58cbbc7f35a028ea6dca0ff61d4dd5ebe624104 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 12 Oct 2024 22:15:24 +0800 Subject: [PATCH 4/4] chore: update --- utils.ts | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/utils.ts b/utils.ts index 0372e1e..0942609 100644 --- a/utils.ts +++ b/utils.ts @@ -267,28 +267,7 @@ export async function runInRepo(options: RunOptions & RepoOptions) { ) } - const agent = options.agent - const beforeInstallCommand = toCommand(beforeInstall, agent) - const beforeBuildCommand = toCommand(beforeBuild, agent) - const beforeTestCommand = toCommand(beforeTest, agent) - const buildCommand = toCommand(build, agent) - const testCommand = toCommand(test, agent) - - const pkgFile = path.join(dir, 'package.json') - const pkg = JSON.parse(await fs.promises.readFile(pkgFile, 'utf-8')) - - await beforeInstallCommand?.(pkg.scripts) - - if (verify && test) { - const frozenInstall = getCommand(agent, 'frozen') - await $`${frozenInstall}` - await beforeBuildCommand?.(pkg.scripts) - await buildCommand?.(pkg.scripts) - await beforeTestCommand?.(pkg.scripts) - await testCommand?.(pkg.scripts) - } const overrides = options.overrides || {} - const vuePackages = await getVuePackages() if (options.release) { @@ -326,8 +305,28 @@ export async function runInRepo(options: RunOptions & RepoOptions) { } } - await applyPackageOverrides(dir, pkg, overrides) + const agent = options.agent + const beforeInstallCommand = toCommand(beforeInstall, agent) + const beforeBuildCommand = toCommand(beforeBuild, agent) + const beforeTestCommand = toCommand(beforeTest, agent) + const buildCommand = toCommand(build, agent) + const testCommand = toCommand(test, agent) + + const pkgFile = path.join(dir, 'package.json') + const pkg = JSON.parse(await fs.promises.readFile(pkgFile, 'utf-8')) + + await beforeInstallCommand?.(pkg.scripts) + if (verify && test) { + const frozenInstall = getCommand(agent, 'frozen') + await $`${frozenInstall}` + await beforeBuildCommand?.(pkg.scripts) + await buildCommand?.(pkg.scripts) + await beforeTestCommand?.(pkg.scripts) + await testCommand?.(pkg.scripts) + } + + await applyPackageOverrides(dir, pkg, overrides) await beforeBuildCommand?.(pkg.scripts) await buildCommand?.(pkg.scripts) if (test) {