Generate preload cache from live app
This commit is contained in:
parent
695f64a55a
commit
3dba3a07f0
7 changed files with 57 additions and 69 deletions
|
@ -1,35 +1,51 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { join } from 'node:path';
|
||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { mkdtemp, rm } from 'node:fs/promises';
|
||||
|
||||
app.on('ready', async () => {
|
||||
ipcMain.handle('done', () => {
|
||||
app.quit();
|
||||
});
|
||||
const ROOT_DIR = join(__dirname, '..', '..');
|
||||
|
||||
ipcMain.handle('error', (_event, err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
const ELECTRON = join(
|
||||
ROOT_DIR,
|
||||
'node_modules',
|
||||
'.bin',
|
||||
process.platform === 'win32' ? 'electron.cmd' : 'electron'
|
||||
);
|
||||
|
||||
const window = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
devTools: true,
|
||||
nodeIntegration: false,
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
preload: join(__dirname, 'generate-preload-cache.preload.js'),
|
||||
},
|
||||
});
|
||||
async function main(): Promise<void> {
|
||||
const storagePath = await mkdtemp(join(tmpdir(), 'signal-preload-cache-'));
|
||||
|
||||
await window.loadURL(
|
||||
pathToFileURL(join(__dirname, 'generate-preload-cache.html')).toString()
|
||||
);
|
||||
let status: number | null;
|
||||
try {
|
||||
({ status } = spawnSync(
|
||||
ELECTRON,
|
||||
['--js-args="--predictable --random-seed 1"', 'ci.js'],
|
||||
{
|
||||
cwd: ROOT_DIR,
|
||||
env: {
|
||||
...process.env,
|
||||
GENERATE_PRELOAD_CACHE: 'on',
|
||||
SIGNAL_CI_CONFIG: JSON.stringify({
|
||||
storagePath,
|
||||
}),
|
||||
},
|
||||
// Since we run `.cmd` file on Windows - use shell
|
||||
shell: process.platform === 'win32',
|
||||
}
|
||||
));
|
||||
} finally {
|
||||
await rm(storagePath, { recursive: true });
|
||||
}
|
||||
|
||||
window.webContents.openDevTools();
|
||||
window.webContents.send('compile', process.argv[2], process.argv[3]);
|
||||
if (status !== 0) {
|
||||
throw new Error(`Exit code: ${status}`);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue