mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
- Statically resolve stable let/var createRequire bindings while rejecting mutation, escape, and early use. - Compile node:console output methods to native process streams and retain explicit custom Console refusals.
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
import { createRequire as createLoader, isBuiltin } from "node:module";
|
|
import output, { Console, log as print } from "node:console";
|
|
|
|
const load = createLoader(import.meta.url);
|
|
const path = load("node:path");
|
|
const config = load("./config.json");
|
|
const inline = createLoader(import.meta.url)("./config.json");
|
|
// Bundlers lower immutable source bindings to var. Uses inside hoisted
|
|
// functions still resolve statically after the declaration has executed.
|
|
var bundledLoad = createLoader(import.meta.url);
|
|
let stableLoad = createLoader(import.meta.url);
|
|
const loaded = readConfig();
|
|
|
|
function readConfig() {
|
|
return bundledLoad("./config.json");
|
|
}
|
|
|
|
function shadowBundled(bundledLoad) {
|
|
bundledLoad = "shadow";
|
|
return bundledLoad;
|
|
}
|
|
|
|
function shadow(load) {
|
|
return load + "!";
|
|
}
|
|
|
|
export function describe() {
|
|
output.info("default console", { enabled: true });
|
|
print("named console %s", "static");
|
|
return [path.join("a", "b"), config.port, inline.port, isBuiltin("node:path"), load.resolve("node:path"), load.resolve.paths("node:path") === null, shadow("local"), loaded.port, stableLoad("./config.json").port, bundledLoad.resolve("node:path"), stableLoad.resolve.paths("node:path") === null, shadowBundled("local")].join(":");
|
|
}
|