diff --git a/dist/index.js b/dist/index.js index e625bbe..6af7823 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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(); diff --git a/index.ts b/index.ts index ad9093b..baf51db 100644 --- a/index.ts +++ b/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`