mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
db446518ca
Fixes #25610 AI assistance: Codex was used to implement this change.
30 lines
867 B
JavaScript
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);
|