mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
Reading `process.stdout.write` as a value, `write.bind(stream)`, and `process.stdout.write = fn` now reach the runtime stream object's write slot in TypeScript, and a program that replaces an output write method calls its typed writes through that slot (SC8020 refuses the combination with Node islands until H2 shares the stream object with them). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21 lines
778 B
TypeScript
21 lines
778 B
TypeScript
// Patching a NATIVE host object: Node lets a library swap
|
|
// `process.stdout.write`, hand out `process.stdout.write.bind(...)`, or
|
|
// redefine a module member with Object.defineProperty. The process output
|
|
// stream's write slot is the runtime stream object's, so the assignment and
|
|
// the bind compile. A builtin module's exports are direct calls, so those
|
|
// forms keep an explicit refusal instead of silently patching nothing. The
|
|
// working split: use the module's functions directly.
|
|
|
|
import * as fs from "node:fs";
|
|
|
|
export function bindReadFileSync(): typeof fs.readFileSync {
|
|
return fs.readFileSync.bind(fs);
|
|
}
|
|
|
|
export function defineReadFileSync(): void {
|
|
Object.defineProperty(fs, "readFileSync", { value: () => "" });
|
|
}
|
|
|
|
bindReadFileSync();
|
|
defineReadFileSync();
|