This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import path from 'node:path'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
export interface BrowserInstallCommand {
|
||||
command: string
|
||||
args: string[]
|
||||
}
|
||||
|
||||
export function createBrowserInstallCommand(args: string[]): BrowserInstallCommand {
|
||||
const unsupported = args.filter(argument => argument !== '--with-deps')
|
||||
const withDepsCount = args.filter(argument => argument === '--with-deps').length
|
||||
|
||||
if (unsupported.length > 0)
|
||||
throw new Error(`install-browser 不支持参数:${unsupported.join(' ')}`)
|
||||
if (withDepsCount > 1)
|
||||
throw new Error('install-browser 的 --with-deps 只能指定一次')
|
||||
|
||||
const packageJson = require.resolve('playwright-chromium/package.json')
|
||||
const playwrightCli = path.join(path.dirname(packageJson), 'cli.js')
|
||||
|
||||
return {
|
||||
command: process.execPath,
|
||||
args: [
|
||||
playwrightCli,
|
||||
'install',
|
||||
...(withDepsCount === 1 ? ['--with-deps'] : []),
|
||||
'chromium',
|
||||
],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user