agora-toolchain 3.8.1 → 3.8.2
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/package.json +1 -1
- package/presets/.babelrc.esm +26 -0
- package/presets/electron.vite.config.js +136 -45
- package/scripts/transpile.js +31 -1
- package/tools/transpile-options.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
[
|
|
4
|
+
"@babel/preset-env",
|
|
5
|
+
{
|
|
6
|
+
"modules": false,
|
|
7
|
+
"useBuiltIns": "usage",
|
|
8
|
+
"corejs": {
|
|
9
|
+
"version": "3.33",
|
|
10
|
+
"proposals": true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
"@babel/preset-react",
|
|
16
|
+
{
|
|
17
|
+
"runtime": "automatic"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"@babel/preset-typescript"
|
|
21
|
+
],
|
|
22
|
+
"plugins": [
|
|
23
|
+
["@babel/plugin-proposal-decorators", { "version": "2023-05" }],
|
|
24
|
+
["@babel/plugin-transform-runtime", { "regenerator": true }]
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -15,6 +15,7 @@ function generateWorkspaceAlias(libNames) {
|
|
|
15
15
|
try {
|
|
16
16
|
const modulePath = resolveModule(libName);
|
|
17
17
|
const srcPath = `${modulePath}/src`;
|
|
18
|
+
const libEsPath = `${modulePath}/lib-es`;
|
|
18
19
|
// const libPath = `${modulePath}/lib`;
|
|
19
20
|
|
|
20
21
|
// Check if src directory exists
|
|
@@ -23,19 +24,50 @@ function generateWorkspaceAlias(libNames) {
|
|
|
23
24
|
// Link to src if it exists
|
|
24
25
|
aliases.push(
|
|
25
26
|
{ find: new RegExp(`^${libName}/lib/(.*)`), replacement: `${srcPath}/$1` },
|
|
26
|
-
{ find: libName, replacement: srcPath },
|
|
27
|
+
{ find: new RegExp(`^${libName}$`), replacement: srcPath },
|
|
27
28
|
);
|
|
29
|
+
} else if (existsSync(libEsPath)) {
|
|
30
|
+
console.log(`source linker: ${libName} linked to lib-es`);
|
|
31
|
+
aliases.push({ find: new RegExp(`^${libName}/lib/(.*)`), replacement: `${libEsPath}/$1` });
|
|
32
|
+
if (existsSync(`${libEsPath}/index.js`)) {
|
|
33
|
+
aliases.push({ find: new RegExp(`^${libName}$`), replacement: libEsPath });
|
|
34
|
+
}
|
|
28
35
|
}
|
|
36
|
+
// else if (existsSync(libPath)) {
|
|
37
|
+
// console.log(`source linker: ${libName} linked to lib`);
|
|
38
|
+
// aliases.push({ find: new RegExp(`^${libName}/lib/(.*)`), replacement: `${libPath}/$1` });
|
|
39
|
+
// if (existsSync(`${libPath}/index.js`)) {
|
|
40
|
+
// aliases.push({ find: new RegExp(`^${libName}$`), replacement: libPath });
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
29
43
|
} catch (e) {
|
|
30
44
|
console.log(`source linker: ${libName} not found, using default paths`);
|
|
31
45
|
// Fallback to relative path if module not found
|
|
32
|
-
const relativePath = resolveCwd(`../${libName}/src`);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
46
|
+
// const relativePath = resolveCwd(`../${libName}/src`);
|
|
47
|
+
// const relativeLibEsPath = resolveCwd(`../${libName}/lib-es`);
|
|
48
|
+
// const relativeLibPath = resolveCwd(`../${libName}/lib`);
|
|
49
|
+
// if (existsSync(relativePath)) {
|
|
50
|
+
// aliases.push(
|
|
51
|
+
// { find: new RegExp(`^${libName}/lib/(.*)`), replacement: `${relativePath}/$1` },
|
|
52
|
+
// { find: new RegExp(`^${libName}$`), replacement: relativePath },
|
|
53
|
+
// );
|
|
54
|
+
// } else if (existsSync(relativeLibEsPath)) {
|
|
55
|
+
// aliases.push({
|
|
56
|
+
// find: new RegExp(`^${libName}/lib/(.*)`),
|
|
57
|
+
// replacement: `${relativeLibEsPath}/$1`,
|
|
58
|
+
// });
|
|
59
|
+
// if (existsSync(`${relativeLibEsPath}/index.js`)) {
|
|
60
|
+
// aliases.push({ find: new RegExp(`^${libName}$`), replacement: relativeLibEsPath });
|
|
61
|
+
// }
|
|
62
|
+
// } else if (existsSync(relativeLibPath)) {
|
|
63
|
+
// aliases.push({
|
|
64
|
+
// find: new RegExp(`^${libName}/lib/(.*)`),
|
|
65
|
+
// replacement: `${relativeLibPath}/$1`,
|
|
66
|
+
// });
|
|
67
|
+
// if (existsSync(`${relativeLibPath}/index.js`)) {
|
|
68
|
+
// aliases.push({ find: new RegExp(`^${libName}$`), replacement: relativeLibPath });
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
39
71
|
}
|
|
40
72
|
});
|
|
41
73
|
|
|
@@ -73,6 +105,45 @@ export default defineConfig(() => {
|
|
|
73
105
|
process.exit(1);
|
|
74
106
|
}
|
|
75
107
|
|
|
108
|
+
const external = [
|
|
109
|
+
'agora-electron-sdk',
|
|
110
|
+
'electron',
|
|
111
|
+
'winston',
|
|
112
|
+
'winston-daily-rotate-file',
|
|
113
|
+
'node:fs',
|
|
114
|
+
'node:fs/promises',
|
|
115
|
+
'fs',
|
|
116
|
+
'node:path',
|
|
117
|
+
'path',
|
|
118
|
+
'node:os',
|
|
119
|
+
'os',
|
|
120
|
+
'electron-screenshots',
|
|
121
|
+
'original-fs',
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
const resolveWorkspaceLib = (libName) => {
|
|
125
|
+
try {
|
|
126
|
+
const modulePath = resolveModule(libName);
|
|
127
|
+
const srcPath = `${modulePath}/src`;
|
|
128
|
+
const libEsPath = `${modulePath}/lib-es`;
|
|
129
|
+
const libPath = `${modulePath}/lib`;
|
|
130
|
+
if (existsSync(srcPath)) {
|
|
131
|
+
return { basePath: srcPath, modulePath };
|
|
132
|
+
}
|
|
133
|
+
if (existsSync(libEsPath)) {
|
|
134
|
+
return { basePath: libEsPath, modulePath };
|
|
135
|
+
}
|
|
136
|
+
if (existsSync(libPath)) {
|
|
137
|
+
return { basePath: libPath, modulePath };
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const foundationPaths = resolveWorkspaceLib('agora-foundation');
|
|
146
|
+
|
|
76
147
|
if (hasMain) {
|
|
77
148
|
config.main = {
|
|
78
149
|
// 主进程构建配置
|
|
@@ -82,20 +153,20 @@ export default defineConfig(() => {
|
|
|
82
153
|
input: {
|
|
83
154
|
index: resolveCwd(mainEntry),
|
|
84
155
|
},
|
|
85
|
-
external
|
|
156
|
+
external,
|
|
86
157
|
plugins: [
|
|
87
|
-
commonjs({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}),
|
|
158
|
+
// commonjs({
|
|
159
|
+
// include: [
|
|
160
|
+
// /fcr-ui-scene[/\\]lib[/\\].*/,
|
|
161
|
+
// /fcr-ui-scene-mobile[/\\]lib[/\\].*/,
|
|
162
|
+
// /fcr-ui-widget-sdk[/\\]lib[/\\].*/,
|
|
163
|
+
// /agora-ui-foundation[/\\]lib[/\\].*/,
|
|
164
|
+
// /fcr-core[/\\]lib[/\\].*/,
|
|
165
|
+
// /agora-rte-sdk[/\\]lib[/\\].*/,
|
|
166
|
+
// /agora-foundation[/\\]lib[/\\].*/,
|
|
167
|
+
// /foundation[/\\]lib[/\\].*/,
|
|
168
|
+
// ],
|
|
169
|
+
// }),
|
|
99
170
|
],
|
|
100
171
|
},
|
|
101
172
|
bytecode: true,
|
|
@@ -115,19 +186,20 @@ export default defineConfig(() => {
|
|
|
115
186
|
input: {
|
|
116
187
|
index: resolveCwd(preloadEntry),
|
|
117
188
|
},
|
|
189
|
+
external,
|
|
118
190
|
plugins: [
|
|
119
|
-
commonjs({
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}),
|
|
191
|
+
// commonjs({
|
|
192
|
+
// include: [
|
|
193
|
+
// /fcr-ui-scene[/\\]lib[/\\].*/,
|
|
194
|
+
// /fcr-ui-scene-mobile[/\\]lib[/\\].*/,
|
|
195
|
+
// /fcr-ui-widget-sdk[/\\]lib[/\\].*/,
|
|
196
|
+
// /agora-ui-foundation[/\\]lib[/\\].*/,
|
|
197
|
+
// /fcr-core[/\\]lib[/\\].*/,
|
|
198
|
+
// /agora-rte-sdk[/\\]lib[/\\].*/,
|
|
199
|
+
// /agora-foundation[/\\]lib[/\\].*/,
|
|
200
|
+
// /foundation[/\\]lib[/\\].*/,
|
|
201
|
+
// ],
|
|
202
|
+
// }),
|
|
131
203
|
],
|
|
132
204
|
},
|
|
133
205
|
bytecode: true,
|
|
@@ -140,19 +212,29 @@ export default defineConfig(() => {
|
|
|
140
212
|
|
|
141
213
|
if (hasRenderer) {
|
|
142
214
|
config.renderer = {
|
|
215
|
+
worker: {
|
|
216
|
+
rollupOptions: {
|
|
217
|
+
external,
|
|
218
|
+
},
|
|
219
|
+
plugins: () => [
|
|
220
|
+
// commonjs({
|
|
221
|
+
// include: [/foundation[/\\]lib/, /agora-foundation[/\\]lib/, /agora-rte-sdk[/\\]lib/],
|
|
222
|
+
// }),
|
|
223
|
+
],
|
|
224
|
+
},
|
|
143
225
|
plugins: [
|
|
144
|
-
commonjs({
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}),
|
|
226
|
+
// commonjs({
|
|
227
|
+
// include: [
|
|
228
|
+
// /fcr-ui-scene[/\\]lib[/\\].*/,
|
|
229
|
+
// /fcr-ui-scene-mobile[/\\]lib[/\\].*/,
|
|
230
|
+
// /fcr-ui-widget-sdk[/\\]lib[/\\].*/,
|
|
231
|
+
// /agora-ui-foundation[/\\]lib[/\\].*/,
|
|
232
|
+
// /fcr-core[/\\]lib[/\\].*/,
|
|
233
|
+
// /agora-rte-sdk[/\\]lib[/\\].*/,
|
|
234
|
+
// /agora-foundation[/\\]lib[/\\].*/,
|
|
235
|
+
// /foundation[/\\]lib[/\\].*/,
|
|
236
|
+
// ],
|
|
237
|
+
// }),
|
|
156
238
|
legacy({
|
|
157
239
|
targets: ['defaults'],
|
|
158
240
|
modernPolyfills: true,
|
|
@@ -167,6 +249,7 @@ export default defineConfig(() => {
|
|
|
167
249
|
build: {
|
|
168
250
|
outDir: `${outDirPrefix}/electron/renderer`,
|
|
169
251
|
rollupOptions: {
|
|
252
|
+
external,
|
|
170
253
|
input: {
|
|
171
254
|
index: resolveCwd(rendererEntry),
|
|
172
255
|
},
|
|
@@ -174,6 +257,14 @@ export default defineConfig(() => {
|
|
|
174
257
|
},
|
|
175
258
|
resolve: {
|
|
176
259
|
alias: [
|
|
260
|
+
...(foundationPaths
|
|
261
|
+
? [
|
|
262
|
+
{
|
|
263
|
+
find: /^agora-foundation\/lib\/(.*)/,
|
|
264
|
+
replacement: `${foundationPaths.basePath}/$1`,
|
|
265
|
+
},
|
|
266
|
+
]
|
|
267
|
+
: []),
|
|
177
268
|
// Node.js polyfills (对应 webpack 的 resolve.fallback)
|
|
178
269
|
{ find: 'crypto', replacement: 'crypto-browserify' },
|
|
179
270
|
{ find: 'stream', replacement: 'stream-browserify' },
|
package/scripts/transpile.js
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
const { spawn } = require('../tools/process-utils');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const { src, out, transpileOnly } = require('../tools/transpile-options');
|
|
5
|
+
const { src, out, transpileOnly, esm } = require('../tools/transpile-options');
|
|
6
6
|
const presetsDir = path.join(__dirname, '../presets');
|
|
7
7
|
const babelPresetPath = path.join(presetsDir, '.babelrc');
|
|
8
|
+
const babelEsmPresetPath = path.join(presetsDir, '.babelrc.esm');
|
|
8
9
|
const tsPresetPath = path.join(presetsDir, 'tsconfig.json');
|
|
9
10
|
|
|
10
11
|
const cwd = process.cwd();
|
|
11
12
|
|
|
12
13
|
const srcDir = path.join(cwd, src ?? 'src');
|
|
13
14
|
const outDir = path.join(cwd, out ?? 'lib');
|
|
15
|
+
const outEsmDir = path.join(cwd, 'lib-es');
|
|
14
16
|
|
|
15
17
|
// console.log("Agora Toolchain: transpiling...");
|
|
16
18
|
spawn(
|
|
@@ -54,6 +56,34 @@ spawn(
|
|
|
54
56
|
}
|
|
55
57
|
});
|
|
56
58
|
}
|
|
59
|
+
|
|
60
|
+
if (esm) {
|
|
61
|
+
spawn(
|
|
62
|
+
require.resolve('.bin/babel'),
|
|
63
|
+
[
|
|
64
|
+
srcDir,
|
|
65
|
+
'--extensions',
|
|
66
|
+
'.ts,.tsx',
|
|
67
|
+
'--out-dir',
|
|
68
|
+
outEsmDir,
|
|
69
|
+
'--ignore',
|
|
70
|
+
'**/*.d.ts',
|
|
71
|
+
'--config-file',
|
|
72
|
+
babelEsmPresetPath,
|
|
73
|
+
'--copy-files',
|
|
74
|
+
],
|
|
75
|
+
{
|
|
76
|
+
stdio: 'inherit',
|
|
77
|
+
},
|
|
78
|
+
).on('exit', (esmCode) => {
|
|
79
|
+
if (esmCode !== 0) {
|
|
80
|
+
console.error('Agora Toolchain: ESM transpilation failed! code:', esmCode);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log('Agora Toolchain: ESM transpilation successful!');
|
|
85
|
+
});
|
|
86
|
+
}
|
|
57
87
|
} else {
|
|
58
88
|
console.error('Agora Toolchain: transpilation failed! code:', code);
|
|
59
89
|
process.exit(1);
|
|
@@ -4,6 +4,7 @@ const opts = program
|
|
|
4
4
|
.option('--transpile-only', 'Only transpile the code, do not build types')
|
|
5
5
|
.option('--src <src>', 'Source directory')
|
|
6
6
|
.option('--out <out>', 'Output directory')
|
|
7
|
+
.option('--esm', 'Also output ESM modules')
|
|
7
8
|
.parse(process.argv)
|
|
8
9
|
.opts();
|
|
9
10
|
|