Share modules between a program and its Node islands through loader hooks (NI-6)

Node islands stack, part 5 of 11 (scriptc-perf/results/islands-prs/PLAN.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Malte Ubl
2026-10-22 18:49:53 -07:00
co-authored by Claude Opus 5.5
parent 2f8e8b2b92
commit 5fa44d9243
55 changed files with 1938 additions and 34 deletions
+5 -2
View File
@@ -10,6 +10,8 @@ import { fileURLToPath } from "node:url";
const srcDir = fileURLToPath(new URL("../packages/runtime/src/", import.meta.url));
const SOURCE = `${srcDir}scr_node_island_host.cjs`;
// The loader hooks of shared modules (NI-6) run in the bootstrap's scope.
const HOOKS = `${srcDir}scr_node_island_hooks.cjs`;
const HEADER = `${srcDir}scr_node_island_host.h`;
/** One C string literal per source line, every byte outside printable
@@ -28,7 +30,8 @@ export function renderHeader(source) {
const lines = source.split("\n");
if (lines.at(-1) === "") lines.pop();
const body = lines.map((line) => ` ${cLiteral(`${line}\n`)}`).join("\n");
return `/* Generated by scripts/node-island-host.mjs from scr_node_island_host.cjs.
return `/* Generated by scripts/node-island-host.mjs from scr_node_island_host.cjs
* and scr_node_island_hooks.cjs.
* Do not edit: change the .cjs file and rerun the script. */
#ifndef SCR_NODE_ISLAND_HOST_H
#define SCR_NODE_ISLAND_HOST_H
@@ -41,7 +44,7 @@ ${body};
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const expected = renderHeader(readFileSync(SOURCE, "utf8"));
const expected = renderHeader(`${readFileSync(SOURCE, "utf8")}\n${readFileSync(HOOKS, "utf8")}`);
if (process.argv.includes("--check")) {
if (readFileSync(HEADER, "utf8") !== expected) {
console.error(`${HEADER} is stale: run node scripts/node-island-host.mjs`);