waygraph 0.12.21 → 0.12.22

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/bin/waygraph CHANGED
@@ -1,13 +1,48 @@
1
- #!/bin/sh
2
- # Two cwd/symlink pitfalls this resolves, both real, both hit in practice:
3
- # - `--import tsx/esm` is a bare specifier - Node resolves it as if from an
4
- # unnamed module at the CALLER's cwd, not this script's install
5
- # directory, so it broke when invoked from anywhere else.
6
- # - `npm link` makes this script reachable via a SYMLINK (e.g.
7
- # ~/.nvm/.../bin/waygraph) - `dirname "$0"` alone follows argv[0], not the
8
- # symlink target, so it resolved to the nvm bin dir instead of this
9
- # package. `readlink -f` follows the symlink to the real file first.
10
- SOURCE="$(readlink -f "$0")"
11
- DIR="$(cd "$(dirname "$SOURCE")/.." && pwd)"
12
- TSX_ESM="$(cd "$DIR" && node -e "console.log(require.resolve('tsx/esm'))")"
13
- exec node --import "$TSX_ESM" "$DIR/dist/cli.js" "$@"
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Cross-platform CLI launcher.
4
+ *
5
+ * Why Node (not #!/bin/sh + readlink -f):
6
+ * - macOS BSD `readlink` has no `-f` (GNU) -> "illegal option -- f" / broken bin
7
+ * - Windows npm expects a Node shebang for `.cmd` shims
8
+ *
9
+ * Still registers `tsx/esm` before `dist/cli.js` so consumer `.block.ts` /
10
+ * `.flow.ts` dynamic imports resolve the same as the old shell wrapper.
11
+ */
12
+ import { spawn } from "node:child_process";
13
+ import { createRequire } from "node:module";
14
+ import { dirname, join } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
18
+ const require = createRequire(join(pkgRoot, "package.json"));
19
+ let tsxEsm;
20
+ try {
21
+ tsxEsm = require.resolve("tsx/esm");
22
+ } catch (err) {
23
+ console.error(
24
+ "waygraph: cannot resolve dependency \"tsx\" (required to load .ts Blocks).\n" +
25
+ " Reinstall: npm install waygraph\n" +
26
+ ` Detail: ${err instanceof Error ? err.message : String(err)}`,
27
+ );
28
+ process.exit(1);
29
+ }
30
+
31
+ const cli = join(pkgRoot, "dist", "cli.js");
32
+ const child = spawn(
33
+ process.execPath,
34
+ ["--import", tsxEsm, cli, ...process.argv.slice(2)],
35
+ { stdio: "inherit", env: process.env, windowsHide: true },
36
+ );
37
+
38
+ child.on("error", (err) => {
39
+ console.error(`waygraph: failed to start CLI: ${err.message}`);
40
+ process.exit(1);
41
+ });
42
+ child.on("exit", (code, signal) => {
43
+ if (signal) {
44
+ process.kill(process.pid, signal);
45
+ return;
46
+ }
47
+ process.exit(code ?? 1);
48
+ });
@@ -468,22 +468,16 @@ function printCliMenu(menu, library) {
468
468
  console.log(" [q] quit");
469
469
  console.log("");
470
470
  }
471
- async function cliPick(menu) {
472
- const rl = createInterface({ input, output });
473
- try {
474
- while (true) {
475
- const ans = (await rl.question("Choose: ")).trim().toLowerCase();
476
- if (ans === "q" || ans === "quit")
477
- return { type: "quit" };
478
- const n = Number(ans);
479
- if (Number.isInteger(n) && n >= 1 && n <= menu.flat.length) {
480
- return { type: "pick", index: n - 1 };
481
- }
482
- console.log("Enter a number from the list, or q to quit.");
471
+ async function cliPick(menu, rl) {
472
+ while (true) {
473
+ const ans = (await rl.question("Choose: ")).trim().toLowerCase();
474
+ if (ans === "q" || ans === "quit")
475
+ return { type: "quit" };
476
+ const n = Number(ans);
477
+ if (Number.isInteger(n) && n >= 1 && n <= menu.flat.length) {
478
+ return { type: "pick", index: n - 1 };
483
479
  }
484
- }
485
- finally {
486
- rl.close();
480
+ console.log("Enter a number from the list, or q to quit.");
487
481
  }
488
482
  }
489
483
  /**
@@ -544,6 +538,7 @@ export async function runAutoExplore(projectDir, options = {}) {
544
538
  wiredPage = target;
545
539
  }
546
540
  let here = null;
541
+ const cliRl = cli ? createInterface({ input, output }) : null;
547
542
  try {
548
543
  for (;;) {
549
544
  page = await ensureLivePage(context, page, startUrl);
@@ -572,9 +567,9 @@ export async function runAutoExplore(projectDir, options = {}) {
572
567
  break;
573
568
  }
574
569
  let pick;
575
- if (cli) {
570
+ if (cli && cliRl) {
576
571
  printCliMenu(menu, library.byName);
577
- pick = await cliPick(menu);
572
+ pick = await cliPick(menu, cliRl);
578
573
  }
579
574
  else {
580
575
  pick = await headfulPick(page, menu, library.byName, mem, () => pickWait.promise);
@@ -614,6 +609,7 @@ export async function runAutoExplore(projectDir, options = {}) {
614
609
  }
615
610
  }
616
611
  finally {
612
+ cliRl?.close();
617
613
  await context.close();
618
614
  await browser.close();
619
615
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waygraph",
3
- "version": "0.12.21",
3
+ "version": "0.12.22",
4
4
  "type": "module",
5
5
  "description": "A typed graph of reusable Blocks for driving a browser through E2E flows.",
6
6
  "license": "MIT",