feat: plugin system with isolated bundles (#2660)

(cherry picked from commit 94d20f1bdc)
This commit is contained in:
Himself65
2023-06-02 16:28:47 +08:00
committed by himself65
parent 66653d1d8a
commit bb8bfd0c9e
19 changed files with 147 additions and 28 deletions

View File

@@ -1,12 +1,12 @@
/* eslint-disable no-async-promise-executor */
import { spawn } from 'node:child_process';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import path, { resolve } from 'node:path';
import electronPath from 'electron';
import * as esbuild from 'esbuild';
import { config, root } from './common.mjs';
import { config, electronDir, rootDir } from './common.mjs';
// this means we don't spawn electron windows, mainly for testing
const watchMode = process.argv.includes('--watch');
@@ -21,7 +21,10 @@ const stderrFilterPatterns = [
// these are set before calling `config`, so we have a chance to override them
try {
const devJson = readFileSync(path.resolve(root, './dev.json'), 'utf-8');
const devJson = readFileSync(
path.resolve(electronDir, './dev.json'),
'utf-8'
);
const devEnv = JSON.parse(devJson);
Object.assign(process.env, devEnv);
} catch (err) {
@@ -65,7 +68,18 @@ function spawnOrReloadElectron() {
const common = config();
function watchPreload() {
function watchPlugins() {
const cp = spawn('yarn', ['dev'], {
cwd: resolve(rootDir, './plugins/bookmark-block'),
stdio: 'inherit',
});
process.once('beforeExit', () => {
cp.kill();
});
}
async function watchPreload() {
return new Promise(async resolve => {
let initialBuild = false;
const preloadBuild = await esbuild.context({
@@ -122,6 +136,7 @@ async function watchMain() {
}
async function main() {
watchPlugins();
await watchMain();
await watchPreload();