2025-06-04 08:11:01 +00:00
|
|
|
import fs from "node:fs";
|
2025-09-23 14:47:41 +00:00
|
|
|
import { join as pathJoin } from "node:path";
|
2025-06-04 08:11:01 +00:00
|
|
|
|
2026-08-14 11:11:20 +00:00
|
|
|
import { disableReusedWorkers } from "../../disable-reused-workers.mjs";
|
|
|
|
|
|
|
|
|
|
const packageDir = pathJoin(import.meta.dirname, "..");
|
|
|
|
|
disableReusedWorkers(pathJoin(packageDir, "transform.wasi-browser.js"));
|
|
|
|
|
|
|
|
|
|
const path = pathJoin(packageDir, "index.js");
|
2025-09-23 14:47:41 +00:00
|
|
|
|
|
|
|
|
let data = fs.readFileSync(path, "utf-8");
|
2025-06-04 08:11:01 +00:00
|
|
|
data = data.replace(
|
|
|
|
|
"\nif (!nativeBinding) {",
|
|
|
|
|
(s) =>
|
|
|
|
|
`
|
|
|
|
|
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
|
|
|
|
try {
|
2025-09-23 14:47:40 +00:00
|
|
|
nativeBinding = require('./webcontainer-fallback.cjs');
|
2025-06-04 08:11:01 +00:00
|
|
|
} catch (err) {
|
|
|
|
|
loadErrors.push(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
` + s,
|
|
|
|
|
);
|
2025-09-23 14:47:41 +00:00
|
|
|
fs.writeFileSync(path, data);
|
2026-09-23 06:54:41 +00:00
|
|
|
|
|
|
|
|
const wasip1BrowserPath = pathJoin(packageDir, "transform.wasip1-browser.js");
|
|
|
|
|
const wasip1Browser = fs.readFileSync(wasip1BrowserPath, "utf-8").replaceAll(/[ \t]+$/gmu, "");
|
|
|
|
|
fs.writeFileSync(wasip1BrowserPath, wasip1Browser);
|