import { register } from "node:module"; import { dirname, join, normalize } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { MessageChannel } from "node:worker_threads"; import { CHILD_PROCESS_MESSAGES } from "../constants.js"; import { uniqID } from "../utils/index.js"; export const { port1, port2 } = new MessageChannel(); const __dirname = dirname(fileURLToPath(import.meta.url)); const apiURL = pathToFileURL(normalize(join(__dirname, "..", "exposed", "max-api.js"))).href; const runnerURL = pathToFileURL(normalize(join(__dirname, "..", "nsRunner.js"))).href; port1.on("message", (url) => { // every file we load gets registered here as a url so we can decide whether to consider it // as part of file watching // Node-internals are not considered if (!url || !url.startsWith("file://")) return; // Max API import and the nsRunner itself are not considered if (url === apiURL || url === runnerURL) return; const fPath = fileURLToPath(url); // console.log("loaded", fPath); process.send({ type: CHILD_PROCESS_MESSAGES.WATCH_PATH, id: uniqID(), payload: { filePath: fPath } }); }); register("./nsLoader.mjs", { parentURL: import.meta.url, data: { apiURL, port: port2 }, transferList: [port2] });