33 lines
980 B
TypeScript
33 lines
980 B
TypeScript
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',
|
|
],
|
|
}
|
|
}
|