mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
- Reuse decoded AST nodes, parent references, and recursive class type analysis during compilation. - Split expression and library validation into smaller functions while preserving diagnostics. - Shorten sanitizer bootstrap and reuse verified CI toolchains.
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { spawn } from "node:child_process";
|
|
|
|
const child = spawn("node", ["-e", "process.stdin.on('data', b => process.stdout.write(b));"]);
|
|
const input = child.stdin;
|
|
const output = child.stdout;
|
|
const errors = child.stderr;
|
|
if (input === null || output === null || errors === null) throw new Error("missing pipe");
|
|
|
|
let echoed = "";
|
|
let outputEnded = false;
|
|
let exited = false;
|
|
let exitCode: number | null = null;
|
|
output.on("data", (chunk) => { echoed += chunk.toString(); });
|
|
output.on("end", () => { outputEnded = true; });
|
|
errors.on("data", (chunk) => { process.stderr.write(chunk); });
|
|
input.on("finish", () => { console.log("finish", input.writable); });
|
|
input.on("error", (err) => { console.log("error", err.message); });
|
|
console.log("initial", input.writable);
|
|
console.log("writes", input.write("hé"), input.write(new Uint8Array([108, 108, 111, 10])));
|
|
input.end();
|
|
console.log("ended", input.writable);
|
|
child.on("exit", (code) => { exited = true; exitCode = code; });
|
|
// Exit and stdout EOF can arrive in either order. Close follows both.
|
|
child.on("close", () => {
|
|
if (!exited || !outputEnded) throw new Error("close before exit or stdout end");
|
|
console.log("exit", exitCode);
|
|
console.log("echo", JSON.stringify(echoed));
|
|
});
|