mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 06:04:51 +00:00
Fix extension loading in Bun binary by using jiti with aliases
This commit is contained in:
parent
71ee79f31a
commit
b8df988144
2 changed files with 7 additions and 9 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Extensions now load correctly in compiled Bun binary by using jiti for module resolution with proper alias handling
|
||||||
|
|
||||||
## [0.45.1] - 2026-01-13
|
## [0.45.1] - 2026-01-13
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import * as path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import type { KeyId } from "@mariozechner/pi-tui";
|
import type { KeyId } from "@mariozechner/pi-tui";
|
||||||
import { createJiti } from "jiti";
|
import { createJiti } from "jiti";
|
||||||
import { getAgentDir, isBunBinary } from "../../config.js";
|
import { getAgentDir } from "../../config.js";
|
||||||
import { createEventBus, type EventBus } from "../event-bus.js";
|
import { createEventBus, type EventBus } from "../event-bus.js";
|
||||||
import type { ExecOptions } from "../exec.js";
|
import type { ExecOptions } from "../exec.js";
|
||||||
import { execCommand } from "../exec.js";
|
import { execCommand } from "../exec.js";
|
||||||
|
|
@ -213,13 +213,7 @@ function createExtensionAPI(
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadBun(path: string) {
|
async function loadExtensionModule(path: string) {
|
||||||
const module = await import(path);
|
|
||||||
const factory = (module.default ?? module) as ExtensionFactory;
|
|
||||||
return typeof factory !== "function" ? undefined : factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadJiti(path: string) {
|
|
||||||
const jiti = createJiti(import.meta.url, {
|
const jiti = createJiti(import.meta.url, {
|
||||||
alias: getAliases(),
|
alias: getAliases(),
|
||||||
});
|
});
|
||||||
|
|
@ -254,7 +248,7 @@ async function loadExtension(
|
||||||
const resolvedPath = resolvePath(extensionPath, cwd);
|
const resolvedPath = resolvePath(extensionPath, cwd);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const factory = isBunBinary ? await loadBun(resolvedPath) : await loadJiti(resolvedPath);
|
const factory = await loadExtensionModule(resolvedPath);
|
||||||
if (!factory) {
|
if (!factory) {
|
||||||
return { extension: null, error: `Extension does not export a valid factory function: ${extensionPath}` };
|
return { extension: null, error: `Extension does not export a valid factory function: ${extensionPath}` };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue