| 38 | }); |
| 39 | |
| 40 | const readToken = async (dataDir: string): Promise<string> => { |
| 41 | const path = join(dataDir, "server-control", "auth.json"); |
| 42 | const deadline = Date.now() + 30_000; |
| 43 | while (Date.now() < deadline) { |
| 44 | if (existsSync(path)) { |
| 45 | const parsed = JSON.parse(readFileSync(path, "utf8")) as { readonly token?: unknown }; |
| 46 | if (typeof parsed.token === "string") return parsed.token; |
| 47 | } |
| 48 | await new Promise((resolve) => setTimeout(resolve, 100)); |
| 49 | } |
| 50 | throw new Error(`Vite dev did not mint ${path}`); |
| 51 | }; |
| 52 | |
| 53 | const stopTree = async (child: ChildProcess): Promise<void> => { |
| 54 | if (child.pid === undefined || child.exitCode !== null) return; |