Create polished demo videos without editing skills. Mac/Windows/Linux
fix(electron): preserve unsupported export blocks
wiiiii123144316ab77cc
diff --git a/electron/mainCjsNormalize.test.mjs b/electron/mainCjsNormalize.test.mjsindex 7b68badb..9ccf91da 100644--- a/electron/mainCjsNormalize.test.mjs+++ b/electron/mainCjsNormalize.test.mjs@@ -43,4 +43,28 @@ describe("Electron main CJS normalizer", () => {{ line: 1, text: "export default MAIN_DIST;" },]);});++ it("preserves an unsupported export block exactly while normalizing other syntax", () => {+ const source = [+ 'import fs from "node:fs";',+ "export {",+ ' MAIN_DIST as "main-dist",',+ "};",+ ].join("\n");++ const result = normalizeElectronMainCjsSource(source);++ expect(result.changed).toBe(true);+ expect(result.source).toBe(+ [+ 'const fs = require("node:fs");',+ "export {",+ ' MAIN_DIST as "main-dist",',+ "};",+ ].join("\n"),+ );+ expect(findElectronMainCjsEsmSyntax(result.source)).toEqual([+ { line: 2, text: "export {" },+ ]);+ });});diff --git a/scripts/normalize-electron-main-cjs.mjs b/scripts/normalize-electron-main-cjs.mjsindex a62171ee..fcbca31f 100644--- a/scripts/normalize-electron-main-cjs.mjs+++ b/scripts/normalize-electron-main-cjs.mjs@@ -86,7 +86,7 @@ function convertExportLine(line) {const blockStartMatch = line.match(/^([ \t]*)export\s*\{\s*$/);if (blockStartMatch) {- return { indent: blockStartMatch[1], specifiers: [] };+ return { indent: blockStartMatch[1], specifiers: [], rawLines: [line] };}return null;@@ -349,7 +349,7 @@ export function normalizeElectronMainCjsSource(source) {exportBlock.indent,);if (statements === null) {- normalizedLines.push(`export {\n${exportBlock.specifiers.join("\n")}\n};`);+ normalizedLines.push(...exportBlock.rawLines, line);} else {normalizedLines.push(...statements);changed = true;@@ -359,6 +359,7 @@ export function normalizeElectronMainCjsSource(source) {}exportBlock.specifiers.push(line.trim().replace(/,$/, ""));+ exportBlock.rawLines.push(line);continue;}