Merge branch 'redesign/microkernel-plugin-architecture' of github.com:dylan-112/OpenACP into redesign/microkernel-plugin-architecture
# Conflicts: # src/core/config/config-editor.ts # src/core/plugin/plugin-installer.ts # src/core/setup/wizard.ts
This commit is contained in:
commit
7567900204
@ -1,3 +1,5 @@
|
||||
import * as os from 'node:os'
|
||||
import * as path from 'node:path'
|
||||
import * as clack from '@clack/prompts'
|
||||
import type { Config, ConfigManager } from './config.js'
|
||||
|
||||
@ -180,11 +182,11 @@ async function ensureDiscordPlugin(): Promise<any | null> {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const { installNpmPlugin } = await import('../plugin/plugin-installer.js')
|
||||
console.log(dim(`Installing ${DISCORD_PACKAGE}...`))
|
||||
await installNpmPlugin(DISCORD_PACKAGE)
|
||||
const { installNpmPlugin } = await import('../plugin/plugin-installer.js')
|
||||
const mod = await installNpmPlugin(DISCORD_PACKAGE)
|
||||
console.log(ok(`${DISCORD_PACKAGE} installed`))
|
||||
return await import(DISCORD_PACKAGE)
|
||||
return mod
|
||||
} catch (err) {
|
||||
console.log(warn(`Failed to install: ${(err as Error).message}`))
|
||||
return null
|
||||
@ -200,8 +202,6 @@ async function editDiscord(_config: Config, _updates: ConfigUpdates): Promise<vo
|
||||
if (plugin?.configure) {
|
||||
const { SettingsManager } = await import('../plugin/settings-manager.js')
|
||||
const { createInstallContext } = await import('../plugin/install-context.js')
|
||||
const { default: os } = await import('node:os')
|
||||
const { default: path } = await import('node:path')
|
||||
const basePath = path.join(os.homedir(), '.openacp', 'plugins')
|
||||
const settingsManager = new SettingsManager(basePath)
|
||||
const ctx = createInstallContext({
|
||||
|
||||
@ -6,10 +6,22 @@ import * as path from 'node:path'
|
||||
const execAsync = promisify(exec)
|
||||
|
||||
/**
|
||||
* Install an npm package into the plugins directory.
|
||||
* Uses async exec to avoid blocking the event loop.
|
||||
* Install an npm package to the plugins directory and return the loaded module.
|
||||
* Tries to import first; if not installed, runs npm install asynchronously.
|
||||
*/
|
||||
export async function installNpmPlugin(packageName: string): Promise<void> {
|
||||
const pluginsDir = path.join(os.homedir(), '.openacp', 'plugins')
|
||||
await execAsync(`npm install ${packageName}`, { cwd: pluginsDir })
|
||||
export async function installNpmPlugin(packageName: string, pluginsDir?: string): Promise<any> {
|
||||
// Try import first — already installed
|
||||
try {
|
||||
return await import(packageName)
|
||||
} catch {
|
||||
// Not installed, proceed with install
|
||||
}
|
||||
|
||||
const dir = pluginsDir ?? path.join(os.homedir(), '.openacp', 'plugins')
|
||||
|
||||
await execAsync(`npm install ${packageName} --prefix "${dir}" --save`, {
|
||||
timeout: 60000,
|
||||
})
|
||||
|
||||
return await import(packageName)
|
||||
}
|
||||
|
||||
@ -191,8 +191,9 @@ async function installAndSetupDiscord(
|
||||
spinner.start(`Installing ${packageName}...`);
|
||||
try {
|
||||
const { installNpmPlugin } = await import('../plugin/plugin-installer.js');
|
||||
await installNpmPlugin(packageName);
|
||||
discordPlugin = (await import(packageName)).default;
|
||||
const pluginsDir = settingsManager.getBasePath();
|
||||
const mod = await installNpmPlugin(packageName, pluginsDir);
|
||||
discordPlugin = mod.default;
|
||||
spinner.stop(ok(`${packageName} installed`));
|
||||
} catch (installErr) {
|
||||
spinner.stop(fail(`Failed to install ${packageName}: ${(installErr as Error).message}`));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user