1- import { defineConfig } from 'rolldown' ;
1+ import { defineConfig , Plugin } from 'rolldown' ;
22
33// rolldown plugins
44import nodePolyfills from '@rolldown/plugin-node-polyfills' ;
@@ -22,16 +22,39 @@ const getSwcOptions = (dirPath: string) =>
2222 jsc : {
2323 transform : { useDefineForClassFields : false } ,
2424 minify : {
25- compress : production ,
26- mangle : production
27- ? {
28- keepClassNames : true ,
29- }
30- : false ,
25+ compress : production ? { keep_classnames : true , keep_fnames : true } : false ,
26+ mangle : production ? { keep_classnames : true } : false ,
3127 } ,
3228 } ,
3329 } ) ;
3430
31+ /**
32+ * Workaround for oxc printer lone-surrogate bug (https://github.com/oxc-project/oxc/issues/3526).
33+ * The oxc codegen replaces lone surrogates (0xD800-0xDFFF) with U+FFFD in long CJS strings,
34+ * corrupting ANTLR ATN serialized data which uses surrogates as raw char codes.
35+ * This plugin converts the string literals to numeric char code arrays before the printer
36+ * sees them. Can be removed once the upstream fix fully covers CJS long strings.
37+ */
38+ function preserveAntlrATN ( ) : Plugin {
39+ const segmentPattern =
40+ / ( \w + \. _ s e r i a l i z e d A T N S e g m e n t \d + ) \s * = \s * ( " (?: [ ^ " \\ ] | \\ .) * " (?: \s * \+ \s * " (?: [ ^ " \\ ] | \\ .) * " ) * ) \s * ; / g;
41+
42+ return {
43+ name : 'preserve-antlr-atn' ,
44+ transform ( code , id ) {
45+ if ( ! id . includes ( 'node_modules' ) || ! / _ s e r i a l i z e d A T N S e g m e n t \d + \s * = / . test ( code ) ) {
46+ return ;
47+ }
48+
49+ return code . replace ( segmentPattern , ( _match , varName : string , expr : string ) => {
50+ const str = new Function ( `return ${ expr } ` ) ( ) as string ;
51+ const charCodes = Array . from ( str , ( c ) => c . charCodeAt ( 0 ) ) ;
52+ return `${ varName } = String.fromCharCode(${ charCodes . join ( ',' ) } );` ;
53+ } ) ;
54+ } ,
55+ } ;
56+ }
57+
3558const production = process . env . NODE_ENV === 'production' ;
3659console . log ( 'Package mode:' , production ? 'production' : 'development' ) ;
3760export default defineConfig ( [
@@ -42,11 +65,18 @@ export default defineConfig([
4265 dir : './lana/out' ,
4366 chunkFileNames : 'lana-[name].js' ,
4467 sourcemap : false ,
68+ keepNames : true ,
4569 } ,
4670 tsconfig : production ? './lana/tsconfig.json' : './lana/tsconfig-dev.json' ,
4771 platform : 'node' ,
72+ resolve : {
73+ alias : {
74+ 'apex-log-parser' : path . resolve ( __dirname , 'apex-log-parser/src/index.ts' ) ,
75+ } ,
76+ } ,
77+
4878 external : [ 'vscode' ] ,
49- plugins : [ swc ( getSwcOptions ( './lana' ) ) ] ,
79+ plugins : [ preserveAntlrATN ( ) , swc ( getSwcOptions ( './lana' ) ) ] ,
5080 } ,
5181 {
5282 input : { bundle : './log-viewer/src/Main.ts' } ,
@@ -56,13 +86,13 @@ export default defineConfig([
5686 dir : './log-viewer/out' ,
5787 chunkFileNames : 'log-viewer-[name].js' ,
5888 sourcemap : false ,
89+ keepNames : true ,
5990 } ,
6091 ] ,
6192 platform : 'browser' ,
6293 resolve : {
6394 alias : { eventemitter3 : path . resolve ( __dirname , 'node_modules/eventemitter3/index.js' ) } ,
6495 } ,
65- keepNames : true ,
6696 moduleTypes : {
6797 '.css' : 'js' ,
6898 } ,
0 commit comments