@beryl-so/cli 0.34.2 → 0.34.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/local-run.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
- import { bundledRunnerCli, installHint, PLAYWRIGHT_INSTALL_COMMANDS, } from "./playwright-install.js";
5
- // We invoke @playwright/test as an external rather than bundling it — the CLI's zero-runtime-dep
6
- // rule. In a node_modules install `playwright` is on PATH; otherwise fall back to `npx playwright`,
7
- // exactly as the cloud runner does. The install commands come from playwright-install.ts so the
8
- // hint text and the actual installer never drift apart.
4
+ import { installHint, PLAYWRIGHT_INSTALL_COMMANDS, resolvePlaywrightRunner, } from "./playwright-install.js";
5
+ // @playwright/test is invoked as an external, never bundled — the CLI's zero-runtime-dep rule.
6
+ // The install commands come from playwright-install.ts so hint and installer never drift apart.
9
7
  export const PLAYWRIGHT_INSTALL_HINT = "Local Playwright not found. Install it in this project, then re-run:\n" +
10
8
  ` ${PLAYWRIGHT_INSTALL_COMMANDS}`;
11
9
  // Isolate the run from any playwright.config.ts in the customer's repo: a stray `testMatch`
@@ -51,20 +49,20 @@ function runProcess(command, args, cwd, env) {
51
49
  child.on("close", (code) => resolve({ code, stdout, stderr }));
52
50
  });
53
51
  }
54
- // The repo's own runner first; else the one bundled with the CLI; `npx playwright` is the
55
- // last resort for a CLI install that somehow lost its dependencies.
56
- function playwrightBase(cwd) {
57
- const binName = process.platform === "win32" ? "playwright.cmd" : "playwright";
58
- const local = path.join(cwd, "node_modules", ".bin", binName);
59
- if (fs.existsSync(local))
60
- return { command: local, args: ["test"], label: "playwright test" };
61
- const bundled = bundledRunnerCli();
62
- if (bundled) {
52
+ // Resolved from the run dir the exact place the spec imports from so the process we
53
+ // spawn and the module the spec loads are the same copy. `npx playwright` is the last
54
+ // resort for a CLI install that somehow lost its dependencies.
55
+ export function playwrightBase(runDir) {
56
+ const runner = resolvePlaywrightRunner(runDir);
57
+ if (runner?.source === "project") {
58
+ return { command: process.execPath, args: [runner.cli, "test"], label: "playwright test" };
59
+ }
60
+ if (runner) {
63
61
  return {
64
62
  command: process.execPath,
65
- args: [bundled, "test"],
63
+ args: [runner.cli, "test"],
66
64
  label: "playwright test (bundled with the CLI)",
67
- nodePath: path.resolve(path.dirname(bundled), "..", ".."),
65
+ nodePath: path.resolve(path.dirname(runner.cli), "..", ".."),
68
66
  };
69
67
  }
70
68
  const npx = process.platform === "win32" ? "npx.cmd" : "npx";
@@ -260,7 +258,7 @@ export async function runSpecLocally(opts) {
260
258
  fs.writeFileSync(configPath, ISOLATING_CONFIG(runDir, artifactsDir));
261
259
  const reportPath = path.join(runDir, "report.json");
262
260
  const cleanup = () => fs.rmSync(runDir, { recursive: true, force: true });
263
- const { command, args: base, label, nodePath } = playwrightBase(cwd);
261
+ const { command, args: base, label, nodePath } = playwrightBase(runDir);
264
262
  const args = [...base, `--config=${configPath}`, "--reporter=json"];
265
263
  opts.onProgress?.(`Running ${label} on ${opts.testName}…`);
266
264
  await opts.setup?.(runDir);
@@ -17,16 +17,32 @@ const projectRequire = (cwd) => createRequire(path.join(cwd, "package.json"));
17
17
  // A repo's own @playwright/test still wins when present (its version, its browser revision).
18
18
  const cliRequire = createRequire(import.meta.url);
19
19
  // cli.js is the package's bin, not an export, so it is located via package.json.
20
+ function runnerAt(pkgPath, source) {
21
+ const { version } = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
22
+ return { cli: path.join(path.dirname(pkgPath), "cli.js"), version, source };
23
+ }
24
+ function projectRunner(dir) {
25
+ try {
26
+ return runnerAt(projectRequire(dir).resolve("@playwright/test/package.json"), "project");
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
20
32
  function bundledRunner() {
21
33
  try {
22
- const pkgPath = cliRequire.resolve("@playwright/test/package.json");
23
- const { version } = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
24
- return { cli: path.join(path.dirname(pkgPath), "cli.js"), version };
34
+ return runnerAt(cliRequire.resolve("@playwright/test/package.json"), "bundled");
25
35
  }
26
36
  catch {
27
37
  return undefined;
28
38
  }
29
39
  }
40
+ // The single answer to "which @playwright/test": what `import "@playwright/test"` from `dir`
41
+ // resolves to (any ancestor's node_modules), else the bundled copy. Runner and spec must load
42
+ // the same one or Playwright refuses to run ("did not expect test.use() to be called here").
43
+ export function resolvePlaywrightRunner(dir) {
44
+ return projectRunner(dir) ?? bundledRunner();
45
+ }
30
46
  export const bundledRunnerCli = () => bundledRunner()?.cli;
31
47
  // By hand, the browser must be fetched for the runner that will launch it: the repo's own
32
48
  // (`npx playwright` resolves it) or, in a bare repo, the CLI's pinned version. An unpinned
@@ -46,15 +62,7 @@ function bundledCoreDir() {
46
62
  return undefined;
47
63
  }
48
64
  }
49
- export function hasPlaywrightTest(cwd) {
50
- try {
51
- projectRequire(cwd).resolve("@playwright/test");
52
- return true;
53
- }
54
- catch {
55
- return false;
56
- }
57
- }
65
+ export const hasPlaywrightTest = (cwd) => projectRunner(cwd) !== undefined;
58
66
  // A local run launches chromium headless, which Playwright serves from a separate
59
67
  // `chromium_headless_shell` build (`playwright install chromium` fetches both). That is the
60
68
  // only engine a run ever launches, so it is the only one we install or check for.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beryl-so/cli",
3
- "version": "0.34.2",
3
+ "version": "0.34.3",
4
4
  "description": "Beryl on the command line — projects, runs, the exploring agent, and an MCP server over the same commands.",
5
5
  "license": "MIT",
6
6
  "type": "module",