mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 11:51:13 +01:00
Add .oxfmtignore to skip generated bindings and wasm-pack output. Add npm format script, update DEVELOPMENT.md for Vite+ toolchain, and format all non-generated files with oxfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30 lines
1022 B
TypeScript
30 lines
1022 B
TypeScript
/* oxlint-disable unbound-method */
|
|
import process from "node:process";
|
|
|
|
export function interceptStdout(intercept: (text: string) => string) {
|
|
const old_stdout_write = process.stdout.write;
|
|
const old_stderr_write = process.stderr.write;
|
|
|
|
process.stdout.write = ((write) =>
|
|
((text: string, ...args: never[]) => {
|
|
write.call(process.stdout, interceptor(text, intercept), ...args);
|
|
return true;
|
|
}) as typeof process.stdout.write)(process.stdout.write);
|
|
|
|
process.stderr.write = ((write) =>
|
|
((text: string, ...args: never[]) => {
|
|
write.call(process.stderr, interceptor(text, intercept), ...args);
|
|
return true;
|
|
}) as typeof process.stderr.write)(process.stderr.write);
|
|
|
|
// puts back to original
|
|
return function unhook() {
|
|
process.stdout.write = old_stdout_write;
|
|
process.stderr.write = old_stderr_write;
|
|
};
|
|
}
|
|
|
|
function interceptor(text: string, fn: (text: string) => string) {
|
|
return fn(text).replace(/\n$/, "") + (fn(text) && text.endsWith("\n") ? "\n" : "");
|
|
}
|