@solidrt/cli 0.0.5 → 0.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "type": "module",
@@ -15,16 +15,16 @@
15
15
  "dependencies": {
16
16
  "@babel/core": "^7.28.5",
17
17
  "@babel/preset-typescript": "^7.28.5",
18
- "babel-preset-solid": "2.0.0-beta.13",
18
+ "babel-preset-solid": "2.0.0-beta.14",
19
19
  "qrcode-generator": "^2.0.4"
20
20
  },
21
21
  "optionalDependencies": {
22
- "@solidrt/darwin-arm64": "0.0.5",
23
- "@solidrt/linux-x64-gnu": "0.0.5",
24
- "@solidrt/win32-x64-msvc": "0.0.5"
22
+ "@solidrt/darwin-arm64": "0.0.7",
23
+ "@solidrt/linux-x64-gnu": "0.0.7",
24
+ "@solidrt/win32-x64-msvc": "0.0.7"
25
25
  },
26
26
  "peerDependencies": {
27
- "@solidrt/core": "0.0.5",
27
+ "@solidrt/core": "0.0.7",
28
28
  "typescript": "^5"
29
29
  },
30
30
  "devDependencies": {
package/src/args.ts CHANGED
@@ -2,14 +2,13 @@ import { parseArgs } from "node:util"
2
2
 
3
3
  export let { values, positionals } = parseArgs({
4
4
  options: {
5
+ dev: { type: "boolean", short: "d", default: false },
5
6
  minify: { type: "boolean", short: "m", default: false },
6
7
  compile: { type: "boolean", short: "c", default: false },
7
8
  stdout: { type: "boolean", default: false },
8
9
  output: { type: "string", short: "o" },
9
- client: { type: "boolean", default: false },
10
- server: { type: "boolean", default: false },
11
- cache: { type: "boolean", default: false },
12
- proxy: { type: "boolean", default: false },
10
+ "proxy-files": { type: "boolean", default: false },
11
+ "proxy-http": { type: "boolean", default: false },
13
12
  fps: { type: "string" },
14
13
  duration: { type: "string" },
15
14
  size: { type: "string" },
@@ -19,34 +18,37 @@ export let { values, positionals } = parseArgs({
19
18
 
20
19
  export let command = positionals[0]
21
20
  export let source = positionals[1]
22
- export let isTsx = source?.endsWith(".tsx")
21
+ export let isTsx = source?.endsWith(".tsx") || source?.endsWith(".jsx")
22
+ export let isTs = source?.endsWith(".ts") || source?.endsWith(".js")
23
23
  export let isPrebuilt = source?.endsWith(".srt.js") || source?.endsWith(".srt.bin")
24
24
 
25
25
  export function printUsage() {
26
26
  console.error(`Usage: srt <command> [options] [file]
27
27
 
28
28
  Commands:
29
- run [file.tsx] Start dev server + local solidrt-go client
30
- run --client Start solidrt-go client only
31
- run --server [file.tsx] Start dev server only
32
- build <file.tsx> Bundle
33
- record <file.tsx> Capture frames for video generation
34
-
35
- run options:
36
- --client Run client only
37
- --server Run server only
38
- --cache Enable HTTP cache
39
- --proxy Tell connected clients to route file/dir/fetch through the dev server
40
- --size <WxH> Window size (default: 1280x720)
41
-
42
- build options:
43
- -m, --minify Minify the output
44
- -c, --compile Compile to bytecode
45
- -o, --output <name> Output filename
46
- --stdout Write bundle to stdout
29
+ run [file.tsx|jsx] Start dev server + local solidrt-go client
30
+ server [file.tsx|jsx] Start dev server only
31
+ client Start solidrt-go client only
32
+ bundle <file.tsx|jsx> Transpile TSX/JSX to JS or bytecode
33
+ record <file.tsx|jsx> Capture frames for video generation
34
+ pack <file.ts|js> Bundle + compile to a standalone executable (experimental, Flux only)
35
+
36
+ run/server options:
37
+ --proxy-files Route file/dir access through the dev server
38
+ --proxy-http Route fetch calls through the dev server (HTTP cache enabled)
39
+
40
+ run/client options:
41
+ --size <WxH> Window size (default: 1280x720)
42
+
43
+ bundle options:
44
+ -d, --dev Use development build of SolidJS (default: production)
45
+ -m, --minify Minify the output
46
+ -c, --compile Compile to bytecode
47
+ -o, --output <name> Output filename
48
+ --stdout Write bundle to stdout
47
49
 
48
50
  record options:
49
- --fps <N> Frames per second (default: 60)
50
- --duration <N> Duration in seconds (default: 1)
51
- --size <WxH> Frame size (default: 1280x720)`)
52
- }
51
+ --fps <N> Frames per second (default: 60)
52
+ --duration <N> Duration in seconds (default: 1)
53
+ --size <WxH> Frame size (default: 1280x720)`)
54
+ }
@@ -1,14 +1,18 @@
1
1
  import { solidPlugin } from "./bun-plugin-solid"
2
2
  import { values, source, isPrebuilt } from "./args"
3
- import { requireBinary, state } from "./util"
3
+ import { requireBinary, state, print } from "./util"
4
4
  import { resolve } from "path"
5
5
 
6
6
  export async function bundle(entry = source) {
7
7
  let result = null
8
8
 
9
9
  let devBase = state.serverUrl ?? undefined
10
- let define: Record<string, string> = { "process.env.NODE_ENV": "production" }
11
- if (devBase) define.__SRT_DEV_BASE__ = JSON.stringify(devBase)
10
+ let dev = !!devBase || values.dev
11
+ print(`[cli] Bundling (${dev ? "development" : "production"})`)
12
+ let define: Record<string, string> = {
13
+ "process.env.NODE_ENV": dev ? "development" : "production",
14
+ }
15
+ if (devBase) define.__SRT_DEV_BASE__ = devBase
12
16
 
13
17
  try {
14
18
  result = await Bun.build({
@@ -16,9 +20,9 @@ export async function bundle(entry = source) {
16
20
  target: "browser",
17
21
  format: "esm",
18
22
  minify: values.minify,
19
- external: ["qjs:*"],
23
+ external: ["qjs:*", "flux:*"],
20
24
  define,
21
- plugins: [solidPlugin({ devBase })],
25
+ plugins: [solidPlugin()],
22
26
  })
23
27
  } catch (e) {
24
28
  console.error("[cli] compile error:\n", e)
@@ -70,17 +74,19 @@ async function compileFromStdin(jsCode: string, outfile: string) {
70
74
  return compileJs(jsCode, outfile)
71
75
  }
72
76
 
73
- export async function runBuildCommand() {
77
+ export async function runBundleCommand() {
74
78
  if (isPrebuilt) {
75
79
  if (!source!.endsWith(".srt.js")) {
76
80
  console.error("Can only compile .srt.js files. .srt.bin is already compiled.")
77
81
  process.exit(1)
78
82
  }
79
- await compileToBytecode(resolve(source!))
83
+ let binOut = await compileToBytecode(resolve(source!))
84
+ let binSize = (await Bun.file(binOut).stat()).size
85
+ console.log(`>> wrote ${binSize} bytes to ${binOut}`)
80
86
  process.exit()
81
87
  }
82
88
 
83
- let baseName = values.output ?? source!.replace(/\.tsx$/, "")
89
+ let baseName = values.output ?? source!.replace(/\.[jt]sx$/, "")
84
90
 
85
91
  if (values.stdout) {
86
92
  let result = await bundle()
@@ -106,6 +112,8 @@ export async function runBuildCommand() {
106
112
  }
107
113
  let binOutfile = baseName + ".srt.bin"
108
114
  await compileFromStdin(jsCode, binOutfile)
115
+ let binSize = (await Bun.file(binOutfile).stat()).size
116
+ console.log(`>> wrote ${binSize} bytes to ${binOutfile}`)
109
117
  process.exit()
110
118
  }
111
119
 
@@ -115,4 +123,4 @@ export async function runBuildCommand() {
115
123
  console.log(`>> wrote ${output.size} bytes to ${jsOutfile}`)
116
124
  }
117
125
  process.exit()
118
- }
126
+ }
package/src/cache.ts CHANGED
@@ -1,19 +1,17 @@
1
1
  // SQLite-backed HTTP response cache for the dev server's /__proxy__ endpoint.
2
2
  //
3
- // Project-local: stored at <cwd>/.srt-cache/cache.db. Opt-in via the --cache
4
- // flag. Entries live forever; delete the .srt-cache directory to drop them.
3
+ // Project-local: stored at <cwd>/.srt-cache.db. Opt-in via the --cache
4
+ // flag. Entries live forever; delete .srt-cache.db to drop them.
5
5
  //
6
6
  // Cached: GET (and HEAD) 2xx responses with no Authorization on the request
7
7
  // and no Cache-Control: no-store on either side. The cache key is
8
8
  // sha256(method + "\n" + url); headers are intentionally not part of the key.
9
9
 
10
10
  import { Database } from "bun:sqlite"
11
- import { resolve, join } from "path"
12
- import { mkdirSync } from "node:fs"
11
+ import { resolve } from "path"
13
12
  import { createHash } from "node:crypto"
14
13
 
15
- const CACHE_DIR = ".srt-cache"
16
- const CACHE_DB = "cache.db"
14
+ const CACHE_FILE = ".srt-cache.db"
17
15
 
18
16
  export type Decision = "hit" | "miss" | "bypass" | "skip"
19
17
 
@@ -30,8 +28,7 @@ let db: Database | null = null
30
28
  let enabled = false
31
29
 
32
30
  export function initCache(opts: { dir: string }) {
33
- mkdirSync(resolve(opts.dir, CACHE_DIR), { recursive: true })
34
- let d = new Database(join(resolve(opts.dir, CACHE_DIR), CACHE_DB), { create: true })
31
+ let d = new Database(resolve(opts.dir, CACHE_FILE), { create: true })
35
32
  d.run(`CREATE TABLE IF NOT EXISTS entries (
36
33
  key TEXT PRIMARY KEY,
37
34
  method TEXT NOT NULL,
package/src/main.ts CHANGED
@@ -5,17 +5,18 @@
5
5
  // Usage:
6
6
  // srt run - start dev server + client
7
7
  // srt run examples/hello.tsx - start dev server + client, bundle + push via WS
8
- // srt run --client - start dev client only (connects to WS server)
9
- // srt run --server examples/hello.tsx - start dev server only, no client
10
- // srt build examples/hello.tsx - bundle TSX to .srt.js
11
- // srt build -c examples/hello.tsx - bundle TSX to .srt.js + compile to .srt.bin
12
- // srt build examples/hello.srt.js - compile .srt.js to .srt.bin
8
+ // srt server examples/hello.tsx - start dev server only, no client
9
+ // srt client - start dev client only (connects to WS server)
10
+ // srt bundle examples/hello.tsx - bundle TSX to .srt.js
11
+ // srt bundle -c examples/hello.tsx - bundle TSX to .srt.js + compile to .srt.bin
12
+ // srt bundle examples/hello.srt.js - compile .srt.js to .srt.bin
13
13
  // srt record examples/hello.tsx - bundle TSX and run with frame capture
14
14
 
15
15
  import pkg from "../package.json"
16
- import { values, command, source, isTsx, isPrebuilt, printUsage } from "./args"
16
+ import { values, command, source, isTsx, isTs, isPrebuilt, printUsage } from "./args"
17
17
  import { state, requireBinary, run, shutdown } from "./util"
18
- import { bundle, bundleTo, runBuildCommand } from "./build"
18
+ import { bundle, bundleTo, runBundleCommand } from "./bundle"
19
+ import { runPackCommand } from "./pack"
19
20
  import { startServer } from "./server"
20
21
  import { spawnClient } from "./client"
21
22
  import { startRepl } from "./repl"
@@ -25,31 +26,63 @@ import { resolve, dirname } from "path"
25
26
 
26
27
  // -- Validate args --
27
28
 
28
- if (!command || (command !== "build" && command !== "run" && command !== "record")) {
29
+ let COMMANDS = ["run", "server", "client", "bundle", "record", "pack"]
30
+
31
+ if (!command || !COMMANDS.includes(command)) {
29
32
  printUsage()
30
33
  process.exit(1)
31
34
  }
32
35
 
33
- if (command === "build" && (!source || (!isTsx && !isPrebuilt))) {
34
- console.error("Usage: srt build [options] <entry.tsx|.srt.js|.srt.bin>")
36
+ if (command === "bundle" && (!source || (!isTsx && !isPrebuilt))) {
37
+ console.error("Usage: srt bundle [options] <entry.[tsx|jsx|srt.js|srt.bin]>")
35
38
  process.exit(1)
36
39
  }
37
40
 
38
41
  if (command === "record" && (!source || !isTsx)) {
39
- console.error("Usage: srt record <entry.tsx>")
42
+ console.error("Usage: srt record <entry.[tsx|jsx]>")
40
43
  process.exit(1)
41
44
  }
42
45
 
43
- // -- Build command --
46
+ if (command === "pack" && (!source || !isTs)) {
47
+ console.error("Usage: srt pack [options] <entry.[ts|js]>")
48
+ process.exit(1)
49
+ }
44
50
 
45
- if (command === "build") {
46
- await runBuildCommand()
51
+ // Force the production export condition for prod bundles. Bun auto-activates the
52
+ // "development" condition whenever NODE_ENV != "production" (read once at startup),
53
+ // and an auto-active condition cannot be turned off via Bun.build({ conditions }).
54
+ // Our deps (@solidjs/signals, solid-js) only expose a "development" branch + a
55
+ // default fallback - no "production" key - so adding conditions does nothing; the
56
+ // only way to reach the default (smaller, no extra invariants) build is to stop
57
+ // the auto-activation by setting NODE_ENV=production. Since that is read at startup,
58
+ // we re-exec rather than mutate process.env. Assumes srt runs via bun (argv is
59
+ // [bun, script, ...]); would need rework if ever shipped as a compiled binary.
60
+ let isProdBuild = (command === "bundle" || command === "record" || command === "pack") && !values.dev
61
+ if (isProdBuild && process.env.NODE_ENV !== "production") {
62
+ let proc = Bun.spawnSync({
63
+ cmd: [process.execPath, ...process.argv.slice(1)],
64
+ env: { ...process.env, NODE_ENV: "production" },
65
+ stdin: "inherit",
66
+ stdout: "inherit",
67
+ stderr: "inherit",
68
+ })
69
+ process.exit(proc.exitCode ?? 0)
70
+ }
71
+
72
+ // -- Bundle command --
73
+
74
+ if (command === "bundle") {
75
+ await runBundleCommand()
76
+ }
77
+
78
+ if (command === "pack") {
79
+ await runPackCommand()
47
80
  }
48
81
 
49
82
  // -- Record command --
50
83
 
51
84
  if (command === "record") {
52
- let jsOutfile = source!.replace(/\.tsx$/, "") + ".srt.js"
85
+ let jsOutfile = source!.replace(/\.[jt]sx$/, "") + ".srt.js"
53
86
  await bundleTo(jsOutfile)
54
87
  let runner = requireBinary("solidrt-go")
55
88
  let recordArgs = ["--record", resolve(jsOutfile)]
@@ -60,9 +93,9 @@ if (command === "record") {
60
93
  process.exit(exit)
61
94
  }
62
95
 
63
- // -- Run command --
96
+ // -- Client command --
64
97
 
65
- if (values.client) {
98
+ if (command === "client") {
66
99
  let runner = requireBinary("solidrt-go")
67
100
  let args: string[] = []
68
101
  if (values.size) args.push("--size", values.size)
@@ -72,11 +105,13 @@ if (values.client) {
72
105
  process.exit(exit)
73
106
  }
74
107
 
108
+ // -- Server / Run command --
109
+
75
110
  // Initialize state from args
76
111
  state.source = source
77
112
  state.sourceDir = source ? dirname(resolve(source)) : process.cwd()
78
113
 
79
- if (values.cache) {
114
+ if (values["proxy-http"]) {
80
115
  cache.initCache({ dir: process.cwd() })
81
116
  console.log("[cli] HTTP cache enabled")
82
117
  }
@@ -92,9 +127,11 @@ if (source && isTsx) {
92
127
  state.currentCode = await output.text()
93
128
  }
94
129
  }
130
+ } else if (source && isPrebuilt && source.endsWith(".srt.js")) {
131
+ state.currentCode = await Bun.file(resolve(source)).text()
95
132
  }
96
133
 
97
- if (!values.server) {
134
+ if (command === "run") {
98
135
  spawnClient()
99
136
  }
100
137
 
package/src/pack.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { values, source } from "./args"
2
+ import { requireBinary } from "./util"
3
+
4
+ const MAGIC = Buffer.from([0x46, 0x4c, 0x55, 0x58, 0x52, 0x54, 0x00, 0x01]) // "FLUXRT\x00\x01"
5
+
6
+ async function bundleFlux(entry: string): Promise<string> {
7
+ let result = await Bun.build({
8
+ entrypoints: [entry],
9
+ target: "browser",
10
+ format: "esm",
11
+ minify: values.minify,
12
+ external: ["qjs:*", "flux:*"],
13
+ })
14
+ if (!result.success) {
15
+ for (let msg of result.logs) console.error(msg)
16
+ console.error("Build failed")
17
+ process.exit(1)
18
+ }
19
+ let jsCode = ""
20
+ for (let output of result.outputs) jsCode += await output.text()
21
+ return jsCode
22
+ }
23
+
24
+ async function compileToBytecode(jsCode: string): Promise<Buffer> {
25
+ let compiler = requireBinary("fluxc")
26
+ let proc = Bun.spawn([compiler], {
27
+ stdin: new Blob([jsCode]),
28
+ stdout: "pipe",
29
+ stderr: "inherit",
30
+ })
31
+ let [bytecode, code] = await Promise.all([new Response(proc.stdout).arrayBuffer(), proc.exited])
32
+ if (code !== 0) process.exit(code)
33
+ return Buffer.from(bytecode)
34
+ }
35
+
36
+ export async function runPackCommand() {
37
+ let outfile = values.output ?? source!.replace(/\.[jt]s$/, "")
38
+
39
+ let jsCode = await bundleFlux(source!)
40
+
41
+ let bytecode = await compileToBytecode(jsCode)
42
+
43
+ let runner = requireBinary("fluxrt")
44
+ let runnerBytes = Buffer.from(await Bun.file(runner).arrayBuffer())
45
+
46
+ let offsetBuf = Buffer.allocUnsafe(8)
47
+ offsetBuf.writeBigUInt64LE(BigInt(runnerBytes.length))
48
+
49
+ let packed = Buffer.concat([runnerBytes, bytecode, offsetBuf, MAGIC])
50
+ await Bun.write(outfile, packed)
51
+
52
+ if (process.platform !== "win32") {
53
+ Bun.spawnSync(["chmod", "+x", outfile])
54
+ }
55
+
56
+ console.log(`>> wrote ${packed.length} bytes to ${outfile}`)
57
+ process.exit()
58
+ }
package/src/repl.ts CHANGED
@@ -2,7 +2,7 @@ import { createInterface } from "node:readline"
2
2
  import { resolve, dirname } from "path"
3
3
  import { readdirSync } from "node:fs"
4
4
  import { state, print, printErr, broadcastStop, buildReload, shutdown } from "./util"
5
- import { bundle } from "./build"
5
+ import { bundle } from "./bundle"
6
6
  import { startWatcher, stopWatcher } from "./watcher"
7
7
 
8
8
  function cmdStop(args: string) {
package/src/util.ts CHANGED
@@ -43,7 +43,7 @@ export function printErr(...args: any[]) {
43
43
  }
44
44
 
45
45
  export function buildReload(payload: { code?: string | null; bytecode?: string }) {
46
- return JSON.stringify({ type: "reload", proxy: values.proxy, ...payload })
46
+ return JSON.stringify({ type: "reload", proxyFiles: values["proxy-files"], proxyHttp: values["proxy-http"], ...payload })
47
47
  }
48
48
 
49
49
  export function broadcastStop() {
package/src/watcher.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { watch } from "node:fs"
2
2
  import { resolve, dirname } from "path"
3
3
  import { state, print, printErr, buildReload } from "./util"
4
- import { bundle } from "./build"
4
+ import { bundle } from "./bundle"
5
5
 
6
6
  let currentWatcher: ReturnType<typeof watch> | null = null
7
7