-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(templates): install browsers on postinstall for playwright (#2104)
- Loading branch information
1 parent
85d2341
commit 323768b
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/cli/src/commands/InstallPlaywrightBrowsersCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { execSync } from 'node:child_process'; | ||
|
||
import ansiColors from 'ansi-colors'; | ||
import type { ArgumentsCamelCase, Argv, CommandModule } from 'yargs'; | ||
|
||
const envVariable = 'CRAWLEE_SKIP_BROWSER_INSTALL'; | ||
|
||
interface InstallPlaywrightBrowsersArgs { | ||
force?: boolean; | ||
} | ||
|
||
export class InstallPlaywrightBrowsersCommand<T> implements CommandModule<T, InstallPlaywrightBrowsersArgs> { | ||
command = 'install-playwright-browsers'; | ||
describe = 'Installs browsers needed by Playwright for local testing'; | ||
|
||
builder = async (args: Argv<T>) => { | ||
args.options('force', { | ||
alias: 'f', | ||
default: false, | ||
type: 'boolean', | ||
describe: 'Use `--force` to force installation of browsers even if the environment is marked as having them.', | ||
}); | ||
|
||
return args as Argv<InstallPlaywrightBrowsersArgs>; | ||
}; | ||
|
||
handler = (args: ArgumentsCamelCase<InstallPlaywrightBrowsersArgs>) => { | ||
if (process.env[envVariable]) { | ||
if (!args.force) { | ||
console.log(ansiColors.green('Browsers are already installed!')); | ||
return; | ||
} | ||
|
||
console.warn(ansiColors.yellow('Installing Playwright browsers in an environment where browsers have already been installed...')); | ||
} else { | ||
console.log(ansiColors.green('Installing Playwright browsers...')); | ||
} | ||
|
||
// TODO: detect package manager | ||
execSync(`npx playwright install`, { stdio: 'inherit' }); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters