Simplify esbuild script

This commit is contained in:
Fedor Indutny
2026-03-24 10:02:13 -07:00
committed by GitHub
parent e42c58667e
commit c6e9f5668a

View File

@@ -112,34 +112,21 @@ const sandboxedBrowserDefaults = {
splitting: true, splitting: true,
}; };
async function build({ appConfig, preloadConfig }) { async function build(config) {
let app; const instance = await esbuild.context(config);
let preload;
if (!noScripts) {
app = await esbuild.context(appConfig);
}
if (!noBundle) {
preload = await esbuild.context(preloadConfig);
}
if (watch) { if (watch) {
await Promise.all([app && app.watch(), preload && preload.watch()]); await instance.watch();
} else { } else {
await Promise.all([app && app.rebuild(), preload && preload.rebuild()]); await instance.rebuild();
await instance.dispose();
if (app) {
await app.dispose();
}
if (preload) {
await preload.dispose();
}
} }
} }
async function main() { async function main() {
await build({ await Promise.all([
appConfig: { !noScripts &&
build({
...nodeDefaults, ...nodeDefaults,
format: 'cjs', format: 'cjs',
mainFields: ['browser', 'main'], mainFields: ['browser', 'main'],
@@ -153,21 +140,18 @@ async function main() {
.filter(file => !file.endsWith('.d.ts')), .filter(file => !file.endsWith('.d.ts')),
], ],
outdir: path.join(ROOT_DIR), outdir: path.join(ROOT_DIR),
}, }),
preloadConfig: { !noBundle &&
build({
...bundleDefaults, ...bundleDefaults,
mainFields: ['browser', 'main'], mainFields: ['browser', 'main'],
entryPoints: [ entryPoints: [
path.join(ROOT_DIR, 'ts', 'windows', 'main', 'preload.preload.ts'), path.join(ROOT_DIR, 'ts', 'windows', 'main', 'preload.preload.ts'),
], ],
outfile: path.join(ROOT_DIR, 'preload.bundle.js'), outfile: path.join(ROOT_DIR, 'preload.bundle.js'),
}, }),
}); !noBundle &&
} build({
async function sandboxedEnv() {
await build({
appConfig: {
...sandboxedBrowserDefaults, ...sandboxedBrowserDefaults,
mainFields: ['browser', 'main'], mainFields: ['browser', 'main'],
entryPoints: [ entryPoints: [
@@ -178,8 +162,9 @@ async function sandboxedEnv() {
path.join(ROOT_DIR, 'ts', 'windows', 'permissions', 'app.dom.tsx'), path.join(ROOT_DIR, 'ts', 'windows', 'permissions', 'app.dom.tsx'),
path.join(ROOT_DIR, 'ts', 'windows', 'screenShare', 'app.dom.tsx'), path.join(ROOT_DIR, 'ts', 'windows', 'screenShare', 'app.dom.tsx'),
], ],
}, }),
preloadConfig: { !noBundle &&
build({
...sandboxedPreloadDefaults, ...sandboxedPreloadDefaults,
mainFields: ['browser', 'main'], mainFields: ['browser', 'main'],
entryPoints: [ entryPoints: [
@@ -191,7 +176,13 @@ async function sandboxedEnv() {
'calldiagnostic', 'calldiagnostic',
'preload.preload.ts' 'preload.preload.ts'
), ),
path.join(ROOT_DIR, 'ts', 'windows', 'debuglog', 'preload.preload.ts'), path.join(
ROOT_DIR,
'ts',
'windows',
'debuglog',
'preload.preload.ts'
),
path.join(ROOT_DIR, 'ts', 'windows', 'loading', 'preload.preload.ts'), path.join(ROOT_DIR, 'ts', 'windows', 'loading', 'preload.preload.ts'),
path.join( path.join(
ROOT_DIR, ROOT_DIR,
@@ -210,11 +201,11 @@ async function sandboxedEnv() {
], ],
format: 'cjs', format: 'cjs',
outdir: 'bundles', outdir: 'bundles',
}, }),
}); ]);
} }
Promise.all([main(), sandboxedEnv()]).catch(error => { main().catch(error => {
console.error(error.stack); console.error(error.stack);
process.exit(1); process.exit(1);
}); });