Files
Chris Tate 37a25ebf7f Support stable bundled loaders and native console imports
- 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.
2026-09-27 22:20:25 -05:00

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(":");
}