Fix build script
This commit is contained in:
1 parent
ec2b75dce9
commit
66097cbdf5
1 file changed
+13
-5
@@ -15,14 +15,22 @@ export default function esbuildPluginInteropDefault() {
|
||||
|
||||
const text = fs.readFileSync(file, "utf8").trim();
|
||||
const lines = text.split("\n");
|
||||
let lastLine = lines[lines.length - 1];
|
||||
|
||||
if (!lastLine.startsWith("module.exports = __toCommonJS(")) {
|
||||
if (
|
||||
!lines[lines.length - 3].startsWith(
|
||||
"module.exports = __toCommonJS("
|
||||
) ||
|
||||
lines[lines.length - 2] !==
|
||||
"// Annotate the CommonJS export names for ESM import in node:" ||
|
||||
lines[lines.length - 1] !== "0 && (module.exports = {});"
|
||||
) {
|
||||
throw new Error("Unexpected output.");
|
||||
}
|
||||
|
||||
lastLine = lastLine.replace(/;$/, ".default;");
|
||||
lines[lines.length - 1] = lastLine;
|
||||
lines[lines.length - 3] = lines[lines.length - 3].replace(
|
||||
/;$/,
|
||||
".default;"
|
||||
);
|
||||
lines.length -= 2;
|
||||
|
||||
fs.writeFileSync(file, lines.join("\n"));
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user