fix: use dynamic imports for matrix-bot-sdk to defer loading
ES modules hoist all static imports before any code executes, so matrix-bot-sdk was loaded BEFORE ensureNativeBinary() could download the native binary. Using dynamic imports inside runPlugin ensures the binary is downloaded first.
This commit is contained in:
parent
04a12d6f3e
commit
8dae9656b8
|
|
@ -7,8 +7,6 @@ import os from "os";
|
|||
import path from "path";
|
||||
import * as acorn from "acorn";
|
||||
import * as acornWalk from "acorn-walk";
|
||||
import { MatrixBotClient } from "./matrix-client.js";
|
||||
import { SessionManager } from "./session-manager.js";
|
||||
import { loadConfig } from "./config-loader.js";
|
||||
import { setAppLog, log, logError } from "./logger.js";
|
||||
// =============================================================================
|
||||
|
|
@ -64,6 +62,10 @@ function releaseLock() {
|
|||
// Plugin Setup
|
||||
// =============================================================================
|
||||
async function runPlugin(ctx, options, dataDir) {
|
||||
// Dynamic imports — loaded AFTER ensureNativeBinary() completes
|
||||
// (static imports would be hoisted and evaluated before ensureNativeBinary())
|
||||
const { MatrixBotClient } = await import("./matrix-client.js");
|
||||
const { SessionManager } = await import("./session-manager.js");
|
||||
ensureDataDir(dataDir);
|
||||
LOCK_FILE = `${dataDir}/lock`;
|
||||
const directory = ctx?.location?.directory || process.cwd();
|
||||
|
|
|
|||
11
index.ts
11
index.ts
|
|
@ -1,4 +1,8 @@
|
|||
import { ensureNativeBinary } from "./bootstrap-native.js"
|
||||
|
||||
// Type-only import — doesn't execute any code at runtime
|
||||
import type { MatrixEventContext } from "./matrix-client.js"
|
||||
|
||||
// Ensure native binary is available before loading matrix-bot-sdk
|
||||
// (opencode's npm doesn't run postinstall scripts)
|
||||
ensureNativeBinary()
|
||||
|
|
@ -8,8 +12,6 @@ import os from "os"
|
|||
import path from "path"
|
||||
import * as acorn from "acorn"
|
||||
import * as acornWalk from "acorn-walk"
|
||||
import { MatrixBotClient, type MatrixEventContext } from "./matrix-client.js"
|
||||
import { SessionManager } from "./session-manager.js"
|
||||
import { loadConfig } from "./config-loader.js"
|
||||
import { setAppLog, log, logError } from "./logger.js"
|
||||
|
||||
|
|
@ -68,6 +70,11 @@ function releaseLock(): void {
|
|||
// =============================================================================
|
||||
|
||||
async function runPlugin(ctx: any, options: any, dataDir: string) {
|
||||
// Dynamic imports — loaded AFTER ensureNativeBinary() completes
|
||||
// (static imports would be hoisted and evaluated before ensureNativeBinary())
|
||||
const { MatrixBotClient } = await import("./matrix-client.js")
|
||||
const { SessionManager } = await import("./session-manager.js")
|
||||
|
||||
ensureDataDir(dataDir)
|
||||
LOCK_FILE = `${dataDir}/lock`
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue