





















@@ -0,0 +1,82 @@
1+#!/usr/bin/env node
2+import { spawnSync as spawnSyncImpl } from "node:child_process";
3+import { existsSync as existsSyncImpl, realpathSync } from "node:fs";
4+import { dirname, resolve } from "node:path";
5+import { fileURLToPath } from "node:url";
6+import { chromium } from "playwright";
7+import { resolvePnpmRunner } from "./pnpm-runner.mjs";
8+9+const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
10+const playwrightInstallArgs = ["--dir", "ui", "exec", "playwright", "install", "chromium"];
11+12+export function resolvePlaywrightInstallRunner(options = {}) {
13+const env = options.env ?? process.env;
14+return resolvePnpmRunner({
15+comSpec: options.comSpec ?? env.ComSpec ?? env.COMSPEC,
16+npmExecPath: env.npm_execpath,
17+platform: options.platform,
18+pnpmArgs: playwrightInstallArgs,
19+});
20+}
21+22+export function isDirectScriptExecution(
23+argvEntry = process.argv[1],
24+modulePath = fileURLToPath(import.meta.url),
25+realpath = realpathSync.native,
26+) {
27+if (!argvEntry) {
28+return false;
29+}
30+try {
31+return realpath(argvEntry) === realpath(modulePath);
32+} catch {
33+return resolve(argvEntry) === resolve(modulePath);
34+}
35+}
36+37+export function ensurePlaywrightChromium(options = {}) {
38+const env = options.env ?? process.env;
39+const executablePath = options.executablePath ?? chromium.executablePath();
40+const existsSync = options.existsSync ?? existsSyncImpl;
41+const log = options.log ?? console.error;
42+const spawnSync = options.spawnSync ?? spawnSyncImpl;
43+44+if (existsSync(executablePath)) {
45+return 0;
46+}
47+48+if (env.OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM === "1") {
49+log(
50+`[ui-e2e] Playwright Chromium is missing at ${executablePath}; OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM=1 leaves the lane skipped.`,
51+);
52+return 0;
53+}
54+55+log(`[ui-e2e] Playwright Chromium is missing at ${executablePath}; installing chromium.`);
56+const runner = resolvePlaywrightInstallRunner({
57+comSpec: options.comSpec,
58+ env,
59+platform: options.platform,
60+});
61+const result = spawnSync(runner.command, runner.args, {
62+cwd: options.cwd ?? repoRoot,
63+ env,
64+shell: runner.shell,
65+stdio: options.stdio ?? "inherit",
66+windowsVerbatimArguments: runner.windowsVerbatimArguments,
67+});
68+const status = result.status ?? 1;
69+if (status !== 0) {
70+return status;
71+}
72+73+if (!existsSync(executablePath)) {
74+log(`[ui-e2e] Playwright install completed but Chromium is still missing at ${executablePath}.`);
75+return 1;
76+}
77+return 0;
78+}
79+80+if (isDirectScriptExecution()) {
81+process.exitCode = ensurePlaywrightChromium();
82+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。