Files
leaysgur db446518ca fix(napi): disable reuseWorker in browser bindings (#25640)
Fixes #25610

AI assistance: Codex was used to implement this change.
2026-08-14 11:11:20 +00:00

30 lines
867 B
JavaScript

import fs from "node:fs";
import { join as pathJoin } from "node:path";
import { disableReusedWorkers } from "../../disable-reused-workers.mjs";
const packageDir = pathJoin(import.meta.dirname, "..");
disableReusedWorkers(pathJoin(packageDir, "transform-react.wasi-browser.js"));
const path = pathJoin(packageDir, "index.js");
let data = fs.readFileSync(path, "utf-8");
data = data.replace(
"\nif (!nativeBinding) {",
(source) =>
`
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
try {
nativeBinding = require('./webcontainer-fallback.cjs');
} catch (err) {
loadErrors.push(err)
}
}
` + source,
);
fs.writeFileSync(path, data);
const workerPath = pathJoin(packageDir, "wasi-worker-browser.mjs");
const worker = fs.readFileSync(workerPath, "utf-8").replaceAll(/[ \t]+$/gmu, "");
fs.writeFileSync(workerPath, worker);