-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrolldown.config.ts
More file actions
112 lines (103 loc) · 3.29 KB
/
rolldown.config.ts
File metadata and controls
112 lines (103 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { defineConfig, Plugin } from 'rolldown';
// rolldown plugins
import nodePolyfills from '@rolldown/plugin-node-polyfills';
// rollup plugins
import copy from 'rollup-plugin-copy';
import postcss from 'rollup-plugin-postcss';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Workaround for oxc printer lone-surrogate bug (https://github.com/oxc-project/oxc/issues/3526).
* The oxc codegen replaces lone surrogates (0xD800-0xDFFF) with U+FFFD in long CJS strings,
* corrupting ANTLR ATN serialized data which uses surrogates as raw char codes.
* This plugin converts the string literals to numeric char code arrays before the printer
* sees them. Can be removed once the upstream fix fully covers CJS long strings.
*/
function preserveAntlrATN(): Plugin {
const segmentPattern =
/(\w+\._serializedATNSegment\d+)\s*=\s*("(?:[^"\\]|\\.)*"(?:\s*\+\s*"(?:[^"\\]|\\.)*")*)\s*;/g;
return {
name: 'preserve-antlr-atn',
transform(code, id) {
if (!id.includes('node_modules') || !/_serializedATNSegment\d+\s*=/.test(code)) {
return;
}
return code.replace(segmentPattern, (_match, varName: string, expr: string) => {
const str = new Function(`return ${expr}`)() as string;
const charCodes = Array.from(str, (c) => c.charCodeAt(0));
return `${varName} = String.fromCharCode(${charCodes.join(',')});`;
});
},
};
}
const production = process.env.NODE_ENV === 'production';
console.log('Package mode:', production ? 'production' : 'development');
export default defineConfig([
{
input: './lana/src/Main.ts',
output: {
format: 'esm',
dir: './lana/out',
cleanDir: true,
chunkFileNames: 'lana-[name].js',
sourcemap: false,
keepNames: true,
minify: production,
},
tsconfig: production ? './lana/tsconfig.json' : './lana/tsconfig-dev.json',
platform: 'node',
resolve: {
alias: {
'apex-log-parser': path.resolve(__dirname, 'apex-log-parser/src/index.ts'),
},
},
external: ['vscode'],
plugins: [preserveAntlrATN()],
},
{
input: { bundle: './log-viewer/src/Main.ts' },
output: [
{
format: 'esm',
dir: './log-viewer/out',
cleanDir: true,
chunkFileNames: 'log-viewer-[name].js',
sourcemap: false,
keepNames: true,
minify: production,
},
],
platform: 'browser',
resolve: {
alias: { eventemitter3: path.resolve(__dirname, 'node_modules/eventemitter3/index.js') },
},
moduleTypes: {
'.css': 'js',
},
tsconfig: production ? './log-viewer/tsconfig.json' : './log-viewer/tsconfig-dev.json',
plugins: [
nodePolyfills(),
postcss({
extensions: ['.css', '.scss'],
minimize: true,
}),
copy({
hook: 'closeBundle',
targets: [
{
src: [
'log-viewer/out/*',
'log-viewer/index.html',
'lana/certinia-icon-color.png',
'node_modules/@vscode/codicons/dist/codicon.ttf',
],
dest: 'lana/out',
},
{ src: ['CHANGELOG.md', 'LICENSE.txt', 'README.md'], dest: 'lana' },
],
}),
],
},
]);