From 66097cbdf5ec78cff8b7dc35af04c62a5150e495 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 28 Feb 2022 21:12:07 +0800 Subject: [PATCH] Fix build script --- .../build/esbuild-plugins/interop-default.mjs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/build/esbuild-plugins/interop-default.mjs b/scripts/build/esbuild-plugins/interop-default.mjs index 972f2e999..a537a2331 100644 --- a/scripts/build/esbuild-plugins/interop-default.mjs +++ b/scripts/build/esbuild-plugins/interop-default.mjs @@ -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")); });