@solidrt/cli 0.0.25 → 0.0.26

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/src/util.ts CHANGED
@@ -2,31 +2,26 @@ import { resolveBinary } from "./artifacts"
2
2
  import { existsSync } from "node:fs"
3
3
  import { resolve } from "node:path"
4
4
  import type { Interface as ReadlineInterface } from "node:readline"
5
- import type { Server as BunServer } from "bun"
6
- import type { Bonjour } from "bonjour-service"
5
+ // import type { Bonjour } from "bonjour-service" (mDNS advertise, kept - see dev-server.ts)
7
6
 
8
7
  export let state = {
9
- clients: new Map<any, { platform: string; version: string; id: number; capabilities: string[] }>(),
10
- nextClientId: 0,
8
+ // What srt believes the current bundle is; the server process keeps its own
9
+ // latched copy for late-joining clients (see packages/cli/server/).
11
10
  currentCode: null as string | null,
12
11
  source: undefined as string | undefined,
13
12
  sourceDir: process.cwd(),
14
13
  child: null as ReturnType<typeof Bun.spawn> | null,
15
- server: null as BunServer<undefined> | null,
14
+ // The spawned flux dev-server process (see dev-server.ts startServer).
15
+ serverProc: null as ReturnType<typeof Bun.spawn> | null,
16
+ shuttingDown: false,
16
17
  serverUrl: null as string | null,
17
18
  rl: null as ReadlineInterface | null,
18
- bonjour: null as Bonjour | null,
19
+ // bonjour: null as Bonjour | null, (mDNS advertise, kept - see dev-server.ts)
19
20
  stats: false,
20
21
  // --capture <file>: destination for captured key events, or undefined when
21
- // off. Clients only report kind/key; the server stamps `after` itself (one
22
- // shared clock from captureStartMs, integer milliseconds) so events from
23
- // several connected clients merge into one coherent timeline, tagged by
24
- // `device` (see dev-server.ts) so they can be told apart. Streamed to disk
25
- // as JSON Lines (one event object per line) as each arrives - see
26
- // dev-server.ts's "capture" message handling.
22
+ // off; the server process owns the capture file and clock (see
23
+ // packages/cli/server/main.ts's "capture" message handling).
27
24
  capture: undefined as string | undefined,
28
- captureStartMs: 0,
29
- captureLastAt: 0, // ms, same clock as captureStartMs
30
25
  }
31
26
 
32
27
  // Build target per binary, for the "not found" hint. Run from the repo root.
@@ -93,9 +88,25 @@ export function printErr(...args: any[]) {
93
88
  state.rl?.prompt(true)
94
89
  }
95
90
 
91
+ // Pipe a child stream to `out` without mangling the repl prompt: clear the
92
+ // prompt line, write the chunk, redraw the prompt.
93
+ export function pipeAbovePrompt(stream: ReadableStream<Uint8Array>, out: NodeJS.WriteStream) {
94
+ let reader = stream.getReader()
95
+ ;(async () => {
96
+ while (true) {
97
+ let { done, value } = await reader.read()
98
+ if (done || !value) break
99
+ process.stdout.write("\r\x1b[K")
100
+ out.write(value)
101
+ state.rl?.prompt(true)
102
+ }
103
+ })()
104
+ }
105
+
96
106
  export function shutdown() {
107
+ state.shuttingDown = true
97
108
  if (state.child) state.child.kill()
98
- if (state.server) state.server.stop()
99
- if (state.bonjour) state.bonjour.destroy()
109
+ if (state.serverProc) state.serverProc.kill()
110
+ // if (state.bonjour) state.bonjour.destroy() (mDNS advertise, kept - see dev-server.ts)
100
111
  process.exit(0)
101
112
  }
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 } from "./util"
4
- import { buildReload, showBuildFailure } from "./dev-server"
4
+ import { buildReload, sendReload, showBuildFailure } from "./dev-server"
5
5
  import { bundle, codeFromOutputs } from "./bundler"
6
6
 
7
7
  let currentWatcher: ReturnType<typeof watch> | null = null
@@ -28,13 +28,10 @@ export function startWatcher() {
28
28
  let result = await bundle(state.source)
29
29
  if (!result) {
30
30
  printErr("[cli] Build failed, waiting for changes...")
31
- showBuildFailure()
31
+ await showBuildFailure()
32
32
  return
33
33
  }
34
34
  state.currentCode = await codeFromOutputs(result.outputs)
35
- let msg = buildReload({ code: state.currentCode })
36
- for (let ws of state.clients.keys()) {
37
- ws.send(msg)
38
- }
35
+ await sendReload(buildReload({ code: state.currentCode }), { latch: true })
39
36
  })
40
37
  }