Skip to content

Commit

Permalink
fix: add new Task type for scripts with args so that we can pass them…
Browse files Browse the repository at this point in the history
… to ni

cherry-picked from vitejs/vite-ecosystem-ci#235
  • Loading branch information
dominikg authored and haoqunjiang committed Mar 29, 2024
1 parent 5178568 commit 2da058b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion tests/vue-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export async function test(options: RunOptions) {
...options,
repo: 'intlify/vue-i18n-next',
branch: 'master',
build: 'build --all -t',
build: {
script: 'build',
args: ['--all', '-t'],
},
beforeTest: 'pnpm playwright install chromium',
test: ['test:cover', 'test:type', 'test:e2e'],
})
Expand Down
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface RunOptions {
patchFiles?: Record<string, (content: string) => string>
}

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

export interface CommandOptions {
suites?: string[]
Expand Down
15 changes: 13 additions & 2 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,26 @@ function toCommand(
if (task == null || task === '') {
continue
} else if (typeof task === 'string') {
const scriptOrBin = task.trim().split(/\s+/)[0]
if (scripts?.[scriptOrBin] != null) {
if (scripts[task] != null) {
const runTaskWithAgent = getCommand(agent, 'run', [task])
await $`${runTaskWithAgent}`
} else {
await $`${task}`
}
} else if (typeof task === 'function') {
await task()
} else if (task?.script) {
if (scripts[task.script] != null) {
const runTaskWithAgent = getCommand(agent, 'run', [
task.script,
...(task.args ?? []),
])
await $`${runTaskWithAgent}`
} else {
throw new Error(
`invalid task, script "${task.script}" does not exist in package.json`,
)
}
} else {
throw new Error(
`invalid task, expected string or function but got ${typeof task}: ${task}`,
Expand Down

0 comments on commit 2da058b

Please sign in to comment.