@steambrew/ttc 2.8.7 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/.prettierrc +9 -9
- package/bun.lock +611 -0
- package/dist/index.js +305 -460
- package/package.json +54 -54
- package/rollup.config.js +22 -22
- package/src/check-health.ts +53 -54
- package/src/index.ts +53 -61
- package/src/logger.ts +49 -46
- package/src/plugin-api.ts +77 -263
- package/src/query-parser.ts +83 -89
- package/src/static-embed.ts +274 -281
- package/src/transpiler.ts +298 -334
- package/src/version-control.ts +53 -31
- package/tsconfig.json +23 -23
- package/pnpm-workspace.yaml +0 -2
package/src/transpiler.ts
CHANGED
|
@@ -1,334 +1,298 @@
|
|
|
1
|
-
import babel from '@rollup/plugin-babel';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
import json from '@rollup/plugin-json';
|
|
4
|
-
import resolve, { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
|
-
import replace from '@rollup/plugin-replace';
|
|
6
|
-
import terser from '@rollup/plugin-terser';
|
|
7
|
-
import typescript from '@rollup/plugin-typescript';
|
|
8
|
-
import url from '@rollup/plugin-url';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { minify_sync } from 'terser';
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
import
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
'
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
];
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (fs.existsSync(`./webkit/index.tsx`)) {
|
|
301
|
-
const webkitRollupConfig: RollupOptions = {
|
|
302
|
-
input: `./webkit/index.tsx`,
|
|
303
|
-
plugins: await GetWebkitPluginComponents(props),
|
|
304
|
-
context: 'window',
|
|
305
|
-
external: (id) => {
|
|
306
|
-
if (id === '@steambrew/client') {
|
|
307
|
-
Logger.Error(
|
|
308
|
-
'The @steambrew/client module should not be included in the webkit module, use @steambrew/webkit instead. Please remove it from the webkit module and try again.',
|
|
309
|
-
);
|
|
310
|
-
process.exit(1);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return id === '@steambrew/webkit';
|
|
314
|
-
},
|
|
315
|
-
output: {
|
|
316
|
-
name: 'millennium_main',
|
|
317
|
-
file: '.millennium/Dist/webkit.js',
|
|
318
|
-
exports: 'named',
|
|
319
|
-
format: 'iife',
|
|
320
|
-
globals: {
|
|
321
|
-
'@steambrew/webkit': 'window.MILLENNIUM_API',
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
await (await rollup(webkitRollupConfig)).write(webkitRollupConfig.output as OutputOptions);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
Logger.Info('build', 'Succeeded passing all tests in', Number((performance.now() - global.PerfStartTime).toFixed(3)), 'ms elapsed.');
|
|
330
|
-
} catch (exception) {
|
|
331
|
-
Logger.Error('error', 'Build failed!', exception);
|
|
332
|
-
process.exit(1);
|
|
333
|
-
}
|
|
334
|
-
};
|
|
1
|
+
import babel from '@rollup/plugin-babel';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
import json from '@rollup/plugin-json';
|
|
4
|
+
import resolve, { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
|
+
import replace from '@rollup/plugin-replace';
|
|
6
|
+
import terser from '@rollup/plugin-terser';
|
|
7
|
+
import typescript from '@rollup/plugin-typescript';
|
|
8
|
+
import url from '@rollup/plugin-url';
|
|
9
|
+
import nodePolyfills from 'rollup-plugin-polyfill-node';
|
|
10
|
+
import { InputPluginOption, OutputBundle, OutputOptions, Plugin, RollupOptions, rollup } from 'rollup';
|
|
11
|
+
import { minify_sync } from 'terser';
|
|
12
|
+
import scss from 'rollup-plugin-scss';
|
|
13
|
+
import * as sass from 'sass';
|
|
14
|
+
import fs from 'fs';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import { pathToFileURL } from 'url';
|
|
17
|
+
import dotenv from 'dotenv';
|
|
18
|
+
import injectProcessEnv from 'rollup-plugin-inject-process-env';
|
|
19
|
+
import { ExecutePluginModule, InitializePlugins } from './plugin-api';
|
|
20
|
+
import { Logger } from './logger';
|
|
21
|
+
import constSysfsExpr from './static-embed';
|
|
22
|
+
|
|
23
|
+
const env = dotenv.config().parsed ?? {};
|
|
24
|
+
|
|
25
|
+
declare global {
|
|
26
|
+
interface Window {
|
|
27
|
+
PLUGIN_LIST: any;
|
|
28
|
+
MILLENNIUM_PLUGIN_SETTINGS_STORE: any;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare const pluginName: string, millennium_main: any, MILLENNIUM_BACKEND_IPC: any, MILLENNIUM_IS_CLIENT_MODULE: boolean;
|
|
33
|
+
|
|
34
|
+
declare const MILLENNIUM_API: {
|
|
35
|
+
callable: (fn: Function, route: string) => any;
|
|
36
|
+
__INTERNAL_CALL_WEBKIT_METHOD__: (pluginName: string, methodName: string, kwargs: any) => any;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
declare const __call_server_method__: (methodName: string, kwargs: any) => any;
|
|
40
|
+
|
|
41
|
+
export interface TranspilerProps {
|
|
42
|
+
minify: boolean;
|
|
43
|
+
pluginName: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
enum BuildTarget {
|
|
47
|
+
Plugin,
|
|
48
|
+
Webkit,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const kCallServerMethod = 'const __call_server_method__ = (methodName, kwargs) => Millennium.callServerMethod(pluginName, methodName, kwargs)';
|
|
52
|
+
|
|
53
|
+
function __wrapped_callable__(route: string) {
|
|
54
|
+
if (route.startsWith('webkit:')) {
|
|
55
|
+
return MILLENNIUM_API.callable(
|
|
56
|
+
(methodName: string, kwargs: any) => MILLENNIUM_API.__INTERNAL_CALL_WEBKIT_METHOD__(pluginName, methodName, kwargs),
|
|
57
|
+
route.replace(/^webkit:/, ''),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return MILLENNIUM_API.callable(__call_server_method__, route);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function wrapEntryPoint(code: string): string {
|
|
65
|
+
return `let PluginEntryPointMain = function() { ${code} return millennium_main; };`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function insertMillennium(target: BuildTarget, props: TranspilerProps): InputPluginOption {
|
|
69
|
+
return {
|
|
70
|
+
name: '',
|
|
71
|
+
generateBundle(_: unknown, bundle: OutputBundle) {
|
|
72
|
+
for (const fileName in bundle) {
|
|
73
|
+
const chunk = bundle[fileName];
|
|
74
|
+
if (chunk.type !== 'chunk') continue;
|
|
75
|
+
|
|
76
|
+
let code = `\
|
|
77
|
+
const MILLENNIUM_IS_CLIENT_MODULE = ${target === BuildTarget.Plugin};
|
|
78
|
+
const pluginName = "${props.pluginName}";
|
|
79
|
+
${InitializePlugins.toString()}
|
|
80
|
+
${InitializePlugins.name}()
|
|
81
|
+
${kCallServerMethod}
|
|
82
|
+
${__wrapped_callable__.toString()}
|
|
83
|
+
${wrapEntryPoint(chunk.code)}
|
|
84
|
+
${ExecutePluginModule.toString()}
|
|
85
|
+
${ExecutePluginModule.name}()`;
|
|
86
|
+
|
|
87
|
+
if (props.minify) {
|
|
88
|
+
code = minify_sync(code).code ?? code;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
chunk.code = code;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getFrontendDir(pluginJson: any): string {
|
|
98
|
+
return pluginJson?.frontend ?? 'frontend';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function resolveEntryFile(frontendDir: string): string {
|
|
102
|
+
return frontendDir === '.' || frontendDir === './' || frontendDir === '' ? './index.tsx' : `./${frontendDir}/index.tsx`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function resolveTsConfig(frontendDir: string): string {
|
|
106
|
+
if (frontendDir === '.' || frontendDir === './') return './tsconfig.json';
|
|
107
|
+
const candidate = `./${frontendDir}/tsconfig.json`;
|
|
108
|
+
return fs.existsSync(candidate) ? candidate : './tsconfig.json';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function withUserPlugins(plugins: InputPluginOption[]): Promise<InputPluginOption[]> {
|
|
112
|
+
if (!fs.existsSync('./ttc.config.mjs')) return plugins;
|
|
113
|
+
const configUrl = pathToFileURL(path.resolve('./ttc.config.mjs')).href;
|
|
114
|
+
const { MillenniumCompilerPlugins } = await import(configUrl);
|
|
115
|
+
const deduped = (MillenniumCompilerPlugins as Plugin<any>[]).filter((custom) => !plugins.some((p) => (p as Plugin<any>)?.name === custom?.name));
|
|
116
|
+
return [...plugins, ...deduped];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function logLocation(log: { loc?: { file?: string; line: number; column: number }; id?: string }): string | undefined {
|
|
120
|
+
const file = log.loc?.file ?? log.id;
|
|
121
|
+
if (!file || !log.loc) return undefined;
|
|
122
|
+
return `${path.relative(process.cwd(), file)}:${log.loc.line}:${log.loc.column}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function stripPluginPrefix(message: string): string {
|
|
126
|
+
message = message.replace(/^\[plugin [^\]]+\]\s*/, '');
|
|
127
|
+
message = message.replace(/^\S[^(]*\(\d+:\d+\):\s*/, '');
|
|
128
|
+
message = message.replace(/^@?[\w-]+\/[\w-]+\s+/, '');
|
|
129
|
+
return message;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
abstract class MillenniumBuild {
|
|
133
|
+
protected abstract readonly externals: ReadonlySet<string>;
|
|
134
|
+
protected abstract readonly forbidden: ReadonlyMap<string, string>;
|
|
135
|
+
protected abstract plugins(sysfsPlugin: InputPluginOption): InputPluginOption[] | Promise<InputPluginOption[]>;
|
|
136
|
+
protected abstract output(isMillennium: boolean): OutputOptions;
|
|
137
|
+
|
|
138
|
+
protected isExternal(id: string): boolean {
|
|
139
|
+
const hint = this.forbidden.get(id);
|
|
140
|
+
if (hint) {
|
|
141
|
+
Logger.error(`${id} cannot be used here; ${hint}`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
return this.externals.has(id);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async build(input: string, sysfsPlugin: InputPluginOption, isMillennium: boolean): Promise<void> {
|
|
148
|
+
let hasErrors = false;
|
|
149
|
+
|
|
150
|
+
const config: RollupOptions = {
|
|
151
|
+
input,
|
|
152
|
+
plugins: await this.plugins(sysfsPlugin),
|
|
153
|
+
onwarn: (warning) => {
|
|
154
|
+
const msg = stripPluginPrefix(warning.message);
|
|
155
|
+
const loc = logLocation(warning);
|
|
156
|
+
if (warning.plugin === 'typescript') {
|
|
157
|
+
Logger.error(msg, loc);
|
|
158
|
+
hasErrors = true;
|
|
159
|
+
} else {
|
|
160
|
+
Logger.warn(msg, loc);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
context: 'window',
|
|
164
|
+
external: (id) => this.isExternal(id),
|
|
165
|
+
output: this.output(isMillennium),
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
await (await rollup(config)).write(config.output as OutputOptions);
|
|
169
|
+
|
|
170
|
+
if (hasErrors) process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
class FrontendBuild extends MillenniumBuild {
|
|
175
|
+
protected readonly externals = new Set(['@steambrew/client', 'react', 'react-dom', 'react-dom/client', 'react/jsx-runtime']);
|
|
176
|
+
protected readonly forbidden = new Map([['@steambrew/webkit', 'use @steambrew/client in the frontend module']]);
|
|
177
|
+
|
|
178
|
+
constructor(
|
|
179
|
+
private readonly frontendDir: string,
|
|
180
|
+
private readonly props: TranspilerProps,
|
|
181
|
+
) {
|
|
182
|
+
super();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
protected plugins(sysfsPlugin: InputPluginOption): InputPluginOption[] {
|
|
186
|
+
const tsPlugin = typescript({ tsconfig: resolveTsConfig(this.frontendDir), compilerOptions: { noCheck: !this.props.minify, outDir: undefined } });
|
|
187
|
+
|
|
188
|
+
return [
|
|
189
|
+
tsPlugin,
|
|
190
|
+
url({ include: ['**/*.gif', '**/*.webm', '**/*.svg'], limit: 0, fileName: '[hash][extname]' }),
|
|
191
|
+
insertMillennium(BuildTarget.Plugin, this.props),
|
|
192
|
+
nodeResolve({ browser: true }),
|
|
193
|
+
commonjs(),
|
|
194
|
+
nodePolyfills(),
|
|
195
|
+
scss({ output: false, outputStyle: 'compressed', sourceMap: false, watch: 'src/styles', sass }),
|
|
196
|
+
json(),
|
|
197
|
+
sysfsPlugin,
|
|
198
|
+
replace({
|
|
199
|
+
delimiters: ['', ''],
|
|
200
|
+
preventAssignment: true,
|
|
201
|
+
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
202
|
+
'Millennium.callServerMethod': '__call_server_method__',
|
|
203
|
+
'client.callable': '__wrapped_callable__',
|
|
204
|
+
'client.pluginSelf': 'window.PLUGIN_LIST[pluginName]',
|
|
205
|
+
'client.Millennium.exposeObj(': 'client.Millennium.exposeObj(exports, ',
|
|
206
|
+
'client.BindPluginSettings()': 'client.BindPluginSettings(pluginName)',
|
|
207
|
+
}),
|
|
208
|
+
...(Object.keys(env).length > 0 ? [injectProcessEnv(env)] : []),
|
|
209
|
+
...(this.props.minify ? [terser()] : []),
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
protected output(isMillennium: boolean): OutputOptions {
|
|
214
|
+
return {
|
|
215
|
+
name: 'millennium_main',
|
|
216
|
+
file: isMillennium ? '../../build/frontend.bin' : '.millennium/Dist/index.js',
|
|
217
|
+
globals: {
|
|
218
|
+
react: 'window.SP_REACT',
|
|
219
|
+
'react-dom': 'window.SP_REACTDOM',
|
|
220
|
+
'react-dom/client': 'window.SP_REACTDOM',
|
|
221
|
+
'react/jsx-runtime': 'SP_JSX_FACTORY',
|
|
222
|
+
'@steambrew/client': 'window.MILLENNIUM_API',
|
|
223
|
+
},
|
|
224
|
+
exports: 'named',
|
|
225
|
+
format: 'iife',
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
class WebkitBuild extends MillenniumBuild {
|
|
231
|
+
protected readonly externals = new Set(['@steambrew/webkit']);
|
|
232
|
+
protected readonly forbidden = new Map([['@steambrew/client', 'use @steambrew/webkit in the webkit module']]);
|
|
233
|
+
|
|
234
|
+
constructor(private readonly props: TranspilerProps) {
|
|
235
|
+
super();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
protected async plugins(sysfsPlugin: InputPluginOption): Promise<InputPluginOption[]> {
|
|
239
|
+
const tsPlugin = typescript({ tsconfig: './webkit/tsconfig.json', compilerOptions: { noCheck: !this.props.minify } });
|
|
240
|
+
|
|
241
|
+
const base: InputPluginOption[] = [
|
|
242
|
+
insertMillennium(BuildTarget.Webkit, this.props),
|
|
243
|
+
tsPlugin,
|
|
244
|
+
url({ include: ['**/*.mp4', '**/*.webm', '**/*.ogg'], limit: 0, fileName: '[name][extname]', destDir: 'dist/assets' }),
|
|
245
|
+
resolve(),
|
|
246
|
+
commonjs(),
|
|
247
|
+
json(),
|
|
248
|
+
sysfsPlugin,
|
|
249
|
+
replace({
|
|
250
|
+
delimiters: ['', ''],
|
|
251
|
+
preventAssignment: true,
|
|
252
|
+
'Millennium.callServerMethod': '__call_server_method__',
|
|
253
|
+
'webkit.callable': '__wrapped_callable__',
|
|
254
|
+
'webkit.Millennium.exposeObj(': 'webkit.Millennium.exposeObj(exports, ',
|
|
255
|
+
'client.BindPluginSettings()': 'client.BindPluginSettings(pluginName)',
|
|
256
|
+
}),
|
|
257
|
+
babel({ presets: ['@babel/preset-env', '@babel/preset-react'], babelHelpers: 'bundled' }),
|
|
258
|
+
...(Object.keys(env).length > 0 ? [injectProcessEnv(env)] : []),
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
const merged = await withUserPlugins(base);
|
|
262
|
+
return this.props.minify ? [...merged, terser()] : merged;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
protected output(_isMillennium: boolean): OutputOptions {
|
|
266
|
+
return {
|
|
267
|
+
name: 'millennium_main',
|
|
268
|
+
file: '.millennium/Dist/webkit.js',
|
|
269
|
+
exports: 'named',
|
|
270
|
+
format: 'iife',
|
|
271
|
+
globals: { '@steambrew/webkit': 'window.MILLENNIUM_API' },
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export const TranspilerPluginComponent = async (isMillennium: boolean, pluginJson: any, props: TranspilerProps) => {
|
|
277
|
+
const webkitDir = './webkit/index.tsx';
|
|
278
|
+
const frontendDir = getFrontendDir(pluginJson);
|
|
279
|
+
const sysfs = constSysfsExpr();
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
await new FrontendBuild(frontendDir, props).build(resolveEntryFile(frontendDir), sysfs.plugin, isMillennium);
|
|
283
|
+
|
|
284
|
+
if (fs.existsSync(webkitDir)) {
|
|
285
|
+
await new WebkitBuild(props).build(webkitDir, sysfs.plugin, isMillennium);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
Logger.done({
|
|
289
|
+
elapsedMs: performance.now() - global.PerfStartTime,
|
|
290
|
+
buildType: props.minify ? 'prod' : 'dev',
|
|
291
|
+
sysfsCount: sysfs.getCount() || undefined,
|
|
292
|
+
envCount: Object.keys(env).length || undefined,
|
|
293
|
+
});
|
|
294
|
+
} catch (exception: any) {
|
|
295
|
+
Logger.error(stripPluginPrefix(exception?.message ?? String(exception)), logLocation(exception));
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
};
|