Bundle sql worker with webpack

This commit is contained in:
Fedor Indutny 2021-04-14 12:43:11 -07:00 committed by Scott Nonnenberg
parent 31a777a130
commit 1ca121aef5
9 changed files with 177 additions and 110 deletions

View file

@ -4,6 +4,8 @@
import { join } from 'path';
import { Worker } from 'worker_threads';
const ASAR_PATTERN = /app\.asar$/;
export type InitializeOptions = {
readonly configDir: string;
readonly key: string;
@ -56,12 +58,18 @@ export class MainSQL {
private onResponse = new Map<number, PromisePair<any>>();
constructor() {
const appDir = join(__dirname, '..', '..').replace(
/app\.asar$/,
'app.asar.unpacked'
);
let appDir = join(__dirname, '..', '..');
let isBundled = false;
this.worker = new Worker(join(appDir, 'ts', 'sql', 'mainWorker.js'));
if (ASAR_PATTERN.test(appDir)) {
appDir = appDir.replace(ASAR_PATTERN, 'app.asar.unpacked');
isBundled = true;
}
const scriptDir = join(appDir, 'ts', 'sql');
this.worker = new Worker(
join(scriptDir, isBundled ? 'mainWorker.bundle.js' : 'mainWorker.js')
);
this.worker.on('message', (wrappedResponse: WrappedWorkerResponse) => {
const { seq, error, response } = wrappedResponse;