import { mkdir, readFile, writeFile } from "node:fs/promises"; // BiImage and AppHeader both depend on the same processImage utility. // Rollup can otherwise move it to a shared chunk, leaving a downloadable // BiImage.js with an extra network dependency. Keep this file self-contained // while deriving the implementation DIRECTLY from the library utility source. const remoteSource = await readFile("src/remote/ui/BiImage/BiImage.remote.js", "utf8"); const utilitySource = await readFile("src/utils/images.js", "utf8"); const remoteImport = 'import { processImage } from "../../../utils/images.js";'; const utilityExport = "export const processImage ="; if (!remoteSource.includes(remoteImport) || !utilitySource.includes(utilityExport)) { throw new Error("BiImage remote or processImage signature has changed; update the standalone remote builder."); } const remoteJs = remoteSource.replace(remoteImport, utilitySource.replace(utilityExport, "const processImage =").trim()); await mkdir("dist/remote", { recursive: true }); await writeFile("dist/remote/BiImage.js", remoteJs);