mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-24 06:14:01 +08:00
- Share program creation, checker queries, virtual files, and snapshot lifetimes between Node and native compiler clients. - Preserve typed async-context results and opaque compiler objects through checked native boundaries. - Support native realpath and Unicode Windows filesystem operations needed by the compiler host.
20 lines
1017 B
TypeScript
20 lines
1017 B
TypeScript
import { appendFileSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
const directory = process.argv[2]!;
|
|
process.chdir(directory);
|
|
console.log("cwd", process.cwd() === realpathSync.native(directory));
|
|
const name = "源-🌍.ts";
|
|
const file = join(directory, name);
|
|
writeFileSync(file, "héllo");
|
|
appendFileSync(file, " 世界");
|
|
console.log("read", readFileSync(file, "utf8"));
|
|
console.log("stat", statSync(file).isFile(), statSync(directory).isDirectory());
|
|
console.log("names", readdirSync(directory).includes(name));
|
|
const entries = readdirSync(directory, { withFileTypes: true });
|
|
console.log("dirent", entries.some((entry) => entry.name === name && entry.isFile()));
|
|
console.log("realpath", realpathSync.native(file).endsWith(name));
|
|
for (const target of [file, join(directory, "missing")]) {
|
|
try { readdirSync(target); console.log("unexpected"); }
|
|
catch (error) { console.log("scan error", (error as NodeJS.ErrnoException).code); }
|
|
}
|