mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
A byte write to a replaced process.stdout.write or process.stderr.write
was boxed with the 'data' chunk helper, which answers a string while a
listener of a socket or HTTP response with setEncoding("utf8") runs. A
`process.stdout.write(buffer)` from such a listener reached the
replacement as a string. Node passes the Buffer it was given.
The stdio hook now boxes a byte write as a Buffer whatever listener is
running.
9 lines
380 B
JavaScript
9 lines
380 B
JavaScript
// Replaces process.stdout.write with a recorder; an exit handler prints what it saw.
|
|
const seen = [];
|
|
process.stdout.write = function (chunk) {
|
|
const kind = typeof chunk === "string" ? "string" : Buffer.isBuffer(chunk) ? "Buffer" : typeof chunk;
|
|
seen.push(`${kind}:${String(chunk)}`);
|
|
return true;
|
|
};
|
|
process.on("exit", () => process.stderr.write(`${seen.join("\n")}\n`));
|