@tscircuit/cli 0.1.2429 → 0.1.2431

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/cli/entrypoint.js CHANGED
@@ -4,6 +4,7 @@ import { existsSync } from "node:fs"
4
4
  import { createRequire } from "node:module"
5
5
  import { dirname, join } from "node:path"
6
6
  import { fileURLToPath } from "node:url"
7
+ import { getNodeRuntime } from "./node-runtime.js"
7
8
 
8
9
  function commandExists(cmd) {
9
10
  try {
@@ -14,7 +15,10 @@ function commandExists(cmd) {
14
15
  }
15
16
  }
16
17
 
17
- const runner = commandExists("bun") ? "bun" : "tsx"
18
+ const runtime = process.env.TSCIRCUIT_NODE_RUNTIME
19
+ ? getNodeRuntime()
20
+ : undefined
21
+ const runner = runtime?.executable ?? (commandExists("bun") ? "bun" : "tsx")
18
22
 
19
23
  const __dirname = dirname(fileURLToPath(import.meta.url))
20
24
  const packageRoot = join(__dirname, "..")
@@ -46,8 +50,14 @@ if (!useGlobal) {
46
50
  } catch {}
47
51
  }
48
52
 
49
- const { status } = spawnSync(runner, [mainPath, ...args], {
50
- stdio: "inherit",
51
- })
52
-
53
- process.exit(status ?? 0)
53
+ const { status, error } = spawnSync(
54
+ runner,
55
+ [...(runtime?.args ?? []), mainPath, ...args],
56
+ {
57
+ stdio: "inherit",
58
+ ...(runtime ? { env: runtime.env } : {}),
59
+ },
60
+ )
61
+
62
+ if (error) console.error(`Unable to start runtime ${runner}: ${error.message}`)
63
+ process.exit(status ?? 1)
@@ -0,0 +1,16 @@
1
+ /** Select a Bun-compatible runtime without changing PATH or the parent environment. */
2
+ export function getNodeRuntime() {
3
+ const configured = process.env.TSCIRCUIT_NODE_RUNTIME
4
+ const args = JSON.parse(process.env.TSCIRCUIT_NODE_RUNTIME_ARGS || "[]")
5
+ if (!Array.isArray(args) || args.some((arg) => typeof arg !== "string")) {
6
+ throw new Error(
7
+ "TSCIRCUIT_NODE_RUNTIME_ARGS must be a JSON array of strings",
8
+ )
9
+ }
10
+ return {
11
+ executable: configured || "bun",
12
+ args,
13
+ // A compiled Bun executable can also serve as the ordinary Bun runtime.
14
+ env: { ...process.env, ...(configured ? { BUN_BE_BUN: "1" } : {}) },
15
+ }
16
+ }