Skip to content

Commit 04598c9

Browse files
committed
fix: rollup
1 parent f32a6df commit 04598c9

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

configs/jsactions/rollup.config.mjs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ export default async args => {
7878

7979
code = header + code;
8080

81-
// 4. Fix export pattern: async function Name { } export { Name };
81+
// 4. Add missing // BEGIN EXTRA CODE if // END EXTRA CODE exists without a BEGIN
82+
if (code.includes('// END EXTRA CODE') && !code.includes('// BEGIN EXTRA CODE')) {
83+
// Find last import line, add BEGIN EXTRA CODE after it
84+
code = code.replace(/(^import .+$)/m, '$1\n\n// BEGIN EXTRA CODE');
85+
}
86+
87+
// 5. If no EXTRA CODE markers at all, add empty block after imports
88+
if (!code.includes('// BEGIN EXTRA CODE') && !code.includes('// END EXTRA CODE')) {
89+
code = code.replace(/(^import .+$)(\r?\n)+(?=\/?\*\*|export)/m, '$1\n\n// BEGIN EXTRA CODE\n// END EXTRA CODE\n\n');
90+
}
91+
92+
// 6. Fix export pattern: async function Name { } export { Name };
8293
// → export async function Name { }
8394
const exportMatch = code.match(/export\s*\{\s*(\w+)\s*\};?\s*$/m);
8495
if (exportMatch) {
@@ -88,6 +99,26 @@ export default async args => {
8899
code = code.replace(/\nexport\s*\{\s*\w+\s*\};?\s*$/m, "");
89100
}
90101

102+
// 7. Fix USER CODE marker indentation: Studio Pro uses tabs inside functions
103+
// Match any whitespace before the markers and replace with single tab
104+
code = code.replace(/^[ \t]+(\/\/ BEGIN USER CODE)/gm, "\t$1");
105+
code = code.replace(/^[ \t]+(\/\/ END USER CODE)/gm, "\t$1");
106+
107+
// 8. Ensure blank line before // BEGIN EXTRA CODE
108+
code = code.replace(/([^\r\n])\r?\n(\/\/ BEGIN EXTRA CODE)/g, "$1\r\n\r\n$2");
109+
110+
// 9. Ensure blank line after // END EXTRA CODE
111+
code = code.replace(/(\/\/ END EXTRA CODE)\r?\n([^\r\n])/g, "$1\r\n\r\n$2");
112+
113+
// 10. Normalize JSDoc formatting to match Studio Pro
114+
// - Empty JSDoc lines: ` *` (one space before asterisk, nothing after)
115+
// - Lines with text: ` * text` (one space before, one space after asterisk)
116+
code = code.replace(/^[ \t]+\*[ \t]+$/gm, " *"); // Empty JSDoc lines: remove trailing whitespace
117+
code = code.replace(/^[ \t]+\*[ \t]+(.+)$/gm, " * $1"); // JSDoc with text: normalize to 1 space before and after asterisk
118+
119+
// 11. Normalize all line endings to CRLF (Studio Pro expects \r\n everywhere)
120+
code = code.replace(/\r?\n/g, "\r\n");
121+
91122
chunk.code = code;
92123
}
93124
}

0 commit comments

Comments
 (0)