mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat: isolated plugin system (#2742)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env zx
|
||||
import 'zx/globals';
|
||||
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as esbuild from 'esbuild';
|
||||
|
||||
import { config } from './common.mjs';
|
||||
import { config, rootDir } from './common.mjs';
|
||||
|
||||
const NODE_ENV =
|
||||
process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
||||
@@ -16,6 +19,11 @@ if (process.platform === 'win32') {
|
||||
async function buildLayers() {
|
||||
const common = config();
|
||||
await esbuild.build(common.preload);
|
||||
console.log('Build plugin infra');
|
||||
spawnSync('yarn', ['build'], {
|
||||
stdio: 'inherit',
|
||||
cwd: resolve(rootDir, './packages/plugin-infra'),
|
||||
});
|
||||
|
||||
console.log('Build plugins');
|
||||
await import('./plugins/build-plugins.mjs');
|
||||
|
||||
@@ -41,12 +41,20 @@ export const config = () => {
|
||||
electronDir,
|
||||
'./layers/main/src/workers/merge-update.worker.ts'
|
||||
),
|
||||
resolve(electronDir, './layers/main/src/workers/plugin.worker.ts'),
|
||||
],
|
||||
outdir: resolve(electronDir, './dist/layers/main'),
|
||||
bundle: true,
|
||||
target: `node${NODE_MAJOR_VERSION}`,
|
||||
platform: 'node',
|
||||
external: ['electron', 'yjs', 'electron-updater', '@toeverything/infra'],
|
||||
external: [
|
||||
'electron',
|
||||
'yjs',
|
||||
'better-sqlite3',
|
||||
'electron-updater',
|
||||
'@toeverything/plugin-infra',
|
||||
'async-call-rpc',
|
||||
],
|
||||
define: define,
|
||||
format: 'cjs',
|
||||
loader: {
|
||||
|
||||
@@ -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, electronDir } 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');
|
||||
@@ -69,6 +69,10 @@ function spawnOrReloadElectron() {
|
||||
const common = config();
|
||||
|
||||
async function watchPlugins() {
|
||||
spawn('yarn', ['dev'], {
|
||||
stdio: 'inherit',
|
||||
cwd: resolve(rootDir, './packages/plugin-infra'),
|
||||
});
|
||||
await import('./plugins/dev-plugins.mjs');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,5 +5,16 @@ import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
await build({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: ['cheerio', 'electron', 'puppeteer', 'foxact'],
|
||||
external: [
|
||||
// server.ts
|
||||
'link-preview-js',
|
||||
// ui.ts
|
||||
'@toeverything/plugin-infra',
|
||||
'@affine/component',
|
||||
'@blocksuite/store',
|
||||
'@blocksuite/blocks',
|
||||
'react',
|
||||
'react-dom',
|
||||
'foxact',
|
||||
],
|
||||
});
|
||||
|
||||
@@ -5,7 +5,18 @@ import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
const plugin = await context({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: ['cheerio', 'electron', 'puppeteer', 'foxact'],
|
||||
external: [
|
||||
// server.ts
|
||||
'link-preview-js',
|
||||
// ui.ts
|
||||
'@toeverything/plugin-infra',
|
||||
'@affine/component',
|
||||
'@blocksuite/store',
|
||||
'@blocksuite/blocks',
|
||||
'react',
|
||||
'react-dom',
|
||||
'foxact',
|
||||
],
|
||||
});
|
||||
|
||||
await plugin.watch();
|
||||
|
||||
@@ -18,12 +18,17 @@ export const pluginDir = resolve(rootDir, 'plugins');
|
||||
*/
|
||||
export function definePluginServerConfig(pluginDirName) {
|
||||
const pluginRootDir = resolve(pluginDir, pluginDirName);
|
||||
const serverEntryFile = resolve(pluginRootDir, 'src/server.ts');
|
||||
const mainEntryFile = resolve(pluginRootDir, 'src/index.ts');
|
||||
const serverOutputDir = resolve(electronOutputDir, pluginDirName);
|
||||
return {
|
||||
entryPoints: [serverEntryFile],
|
||||
platform: 'node',
|
||||
entryPoints: [mainEntryFile],
|
||||
platform: 'neutral',
|
||||
format: 'esm',
|
||||
outExtension: {
|
||||
'.js': '.mjs',
|
||||
},
|
||||
outdir: serverOutputDir,
|
||||
bundle: true,
|
||||
splitting: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user