2022-02-11 21:38:52 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
const esbuild = require('esbuild');
|
|
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
|
|
|
|
const ROOT_DIR = path.join(__dirname, '..');
|
2023-04-20 21:23:19 +00:00
|
|
|
const BUNDLES_DIR = 'bundles';
|
2022-02-11 21:38:52 +00:00
|
|
|
|
|
|
|
const watch = process.argv.some(argv => argv === '-w' || argv === '--watch');
|
|
|
|
const isProd = process.argv.some(argv => argv === '-prod' || argv === '--prod');
|
|
|
|
|
|
|
|
const nodeDefaults = {
|
|
|
|
platform: 'node',
|
2023-01-12 20:58:53 +00:00
|
|
|
target: 'esnext',
|
2024-02-07 01:50:20 +00:00
|
|
|
// Disabled even in dev because the debugger is broken
|
|
|
|
sourcemap: false,
|
2022-02-11 21:38:52 +00:00
|
|
|
// Otherwise React components get renamed
|
|
|
|
// See: https://github.com/evanw/esbuild/issues/1147
|
|
|
|
keepNames: true,
|
|
|
|
logLevel: 'info',
|
|
|
|
};
|
|
|
|
|
|
|
|
const bundleDefaults = {
|
|
|
|
...nodeDefaults,
|
2022-02-25 20:36:42 +00:00
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': isProd ? '"production"' : '"development"',
|
|
|
|
},
|
2022-02-11 21:38:52 +00:00
|
|
|
bundle: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
minify: isProd,
|
2022-02-11 21:38:52 +00:00
|
|
|
external: [
|
2022-02-28 17:39:39 +00:00
|
|
|
// Native libraries
|
2022-03-24 21:47:21 +00:00
|
|
|
'@signalapp/libsignal-client',
|
|
|
|
'@signalapp/libsignal-client/zkgroup',
|
2023-01-09 18:38:57 +00:00
|
|
|
'@signalapp/ringrtc',
|
2022-12-14 20:48:36 +00:00
|
|
|
'@signalapp/better-sqlite3',
|
2022-02-28 17:39:39 +00:00
|
|
|
'electron',
|
2022-02-11 21:38:52 +00:00
|
|
|
'fs-xattr',
|
|
|
|
'fsevents',
|
2022-02-28 17:39:39 +00:00
|
|
|
'mac-screen-capture-permissions',
|
|
|
|
'sass',
|
2022-12-16 02:03:01 +00:00
|
|
|
'bufferutil',
|
|
|
|
'utf-8-validate',
|
2022-02-28 17:39:39 +00:00
|
|
|
|
|
|
|
// Things that don't bundle well
|
2022-02-11 21:38:52 +00:00
|
|
|
'got',
|
|
|
|
'jquery',
|
|
|
|
'node-fetch',
|
|
|
|
'pino',
|
|
|
|
'proxy-agent',
|
2022-12-16 02:03:01 +00:00
|
|
|
'websocket',
|
2022-02-28 17:39:39 +00:00
|
|
|
|
|
|
|
// Large libraries (3.7mb total)
|
|
|
|
// See: https://esbuild.github.io/api/#analyze
|
|
|
|
'emoji-datasource',
|
|
|
|
'fabric',
|
|
|
|
'google-libphonenumber',
|
|
|
|
'moment',
|
|
|
|
'quill',
|
2022-02-11 21:38:52 +00:00
|
|
|
|
|
|
|
// Uses fast-glob and dynamic requires
|
|
|
|
'./preload_test',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
const sandboxedPreloadDefaults = {
|
|
|
|
...nodeDefaults,
|
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': isProd ? '"production"' : '"development"',
|
|
|
|
},
|
|
|
|
external: ['electron'],
|
|
|
|
bundle: true,
|
|
|
|
minify: isProd,
|
|
|
|
};
|
2023-01-18 20:12:19 +00:00
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
const sandboxedBrowserDefaults = {
|
|
|
|
...sandboxedPreloadDefaults,
|
|
|
|
chunkNames: 'chunks/[name]-[hash]',
|
|
|
|
format: 'esm',
|
|
|
|
outdir: path.join(ROOT_DIR, BUNDLES_DIR),
|
|
|
|
platform: 'browser',
|
|
|
|
splitting: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
async function build({ appConfig, preloadConfig }) {
|
|
|
|
const app = await esbuild.context(appConfig);
|
|
|
|
const preload = await esbuild.context(preloadConfig);
|
2023-01-18 20:12:19 +00:00
|
|
|
|
|
|
|
if (watch) {
|
2023-04-20 21:23:19 +00:00
|
|
|
await Promise.all([app.watch(), preload.watch()]);
|
2023-01-18 20:12:19 +00:00
|
|
|
} else {
|
2023-04-20 21:23:19 +00:00
|
|
|
await Promise.all([app.rebuild(), preload.rebuild()]);
|
2023-01-18 20:12:19 +00:00
|
|
|
|
2023-01-19 00:17:16 +00:00
|
|
|
await app.dispose();
|
2023-04-20 21:23:19 +00:00
|
|
|
await preload.dispose();
|
2023-01-19 00:17:16 +00:00
|
|
|
}
|
2023-01-18 20:12:19 +00:00
|
|
|
}
|
2022-02-11 21:38:52 +00:00
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
async function main() {
|
|
|
|
await build({
|
|
|
|
appConfig: {
|
|
|
|
...nodeDefaults,
|
|
|
|
format: 'cjs',
|
|
|
|
mainFields: ['browser', 'main'],
|
2024-09-08 21:09:57 +00:00
|
|
|
entryPoints: [
|
|
|
|
'preload.wrapper.ts',
|
|
|
|
...glob
|
|
|
|
.sync('{app,ts}/**/*.{ts,tsx}', {
|
|
|
|
nodir: true,
|
|
|
|
root: ROOT_DIR,
|
|
|
|
})
|
|
|
|
.filter(file => !file.endsWith('.d.ts')),
|
|
|
|
],
|
2023-04-20 21:23:19 +00:00
|
|
|
outdir: path.join(ROOT_DIR),
|
|
|
|
},
|
|
|
|
preloadConfig: {
|
|
|
|
...bundleDefaults,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
entryPoints: [path.join(ROOT_DIR, 'ts', 'windows', 'main', 'preload.ts')],
|
|
|
|
outfile: path.join(ROOT_DIR, 'preload.bundle.js'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-14 15:55:31 +00:00
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
async function sandboxedEnv() {
|
|
|
|
await build({
|
|
|
|
appConfig: {
|
|
|
|
...sandboxedBrowserDefaults,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
entryPoints: [
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'about', 'app.tsx'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'debuglog', 'app.tsx'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'loading', 'start.ts'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'permissions', 'app.tsx'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'screenShare', 'app.tsx'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'settings', 'app.tsx'),
|
2024-05-23 00:28:01 +00:00
|
|
|
path.join(
|
|
|
|
ROOT_DIR,
|
|
|
|
'ts',
|
|
|
|
'windows',
|
2024-05-23 22:19:12 +00:00
|
|
|
'calling-tools',
|
|
|
|
'webrtc_internals.ts'
|
2024-05-23 00:28:01 +00:00
|
|
|
),
|
2023-04-20 21:23:19 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
preloadConfig: {
|
|
|
|
...sandboxedPreloadDefaults,
|
|
|
|
mainFields: ['main'],
|
|
|
|
entryPoints: [
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'about', 'preload.ts'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'debuglog', 'preload.ts'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'loading', 'preload.ts'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'permissions', 'preload.ts'),
|
2024-05-23 22:19:12 +00:00
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'calling-tools', 'preload.ts'),
|
2023-04-20 21:23:19 +00:00
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'screenShare', 'preload.ts'),
|
|
|
|
path.join(ROOT_DIR, 'ts', 'windows', 'settings', 'preload.ts'),
|
|
|
|
],
|
|
|
|
format: 'cjs',
|
|
|
|
outdir: 'bundles',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-14 15:55:31 +00:00
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
Promise.all([main(), sandboxedEnv()]).catch(error => {
|
|
|
|
console.error(error.stack);
|
|
|
|
process.exit(1);
|
2023-03-14 15:55:31 +00:00
|
|
|
});
|