Skip to content

Commit

Permalink
fix(vue-macros): override catelog
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Oct 12, 2024
1 parent 384a10f commit f848fea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions tests/vue-macros.ts
Original file line number Diff line number Diff line change
@@ -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)
},
},
})
}
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface RunOptions {
beforeInstall?: Task | Task[]
beforeBuild?: Task | Task[]
beforeTest?: Task | Task[]
patchFiles?: Record<string, (content: string) => string>
patchFiles?: Record<string, (content: string, overrides: Overrides) => string>
}

type Task = string | { script: string; args?: string[] } | (() => Promise<any>)
Expand Down
21 changes: 11 additions & 10 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f848fea

Please sign in to comment.