Skip to content

Commit

Permalink
feat: support patchFiles option
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 4, 2024
1 parent 16d8280 commit eafe7c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tests/vuetify.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { runInRepo } from '../utils'
import { RunOptions } from '../types'
import path from 'node:path'
import fs from 'node:fs'

export async function test(options: RunOptions) {
await runInRepo({
...options,
repo: 'vuetifyjs/vuetify',
branch: 'master',
beforeBuild: async () => {
const dir = path.resolve(options.workspace, 'vuetify')
const filePath = path.resolve(dir, 'packages/vuetify/src/globals.d.ts')
const file = fs.readFileSync(filePath, 'utf-8')
fs.writeFileSync(filePath, `import 'vue/jsx'\n` + file)
},
build: 'yarn workspace vuetify run build',
// there's also an e2e test script in vuetify,
// but it seems flaky, so I skipped it for now
test: ['yarn lerna run test:coverage -- -- -i'],
patchFiles: {
'packages/vuetify/src/globals.d.ts': (content) => {
if (!content.includes('vue/jsx')) {
return `import 'vue/jsx'\n${content}`
} else {
return content
}
},
},
})
}
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface RunOptions {
beforeInstall?: Task | Task[]
beforeBuild?: Task | Task[]
beforeTest?: Task | Task[]
patchFiles?: Record<string, (content: string) => string>
}

type Task = string | (() => Promise<any>)
Expand Down
12 changes: 12 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
beforeInstall,
beforeBuild,
beforeTest,
patchFiles,
} = options
const dir = path.resolve(
options.workspace,
Expand Down Expand Up @@ -285,6 +286,17 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
}
}
await applyPackageOverrides(dir, pkg, overrides)

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}`)
}
}

await beforeBuildCommand?.(pkg.scripts)
await buildCommand?.(pkg.scripts)
if (test) {
Expand Down

0 comments on commit eafe7c3

Please sign in to comment.