From 26e178fa961b97a31a23c5a33edd83f86ebf9433 Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Tue, 19 May 2026 20:19:28 +0200 Subject: [PATCH] Fix Electron resolution for optional chromadb dependency Replace dynamic ESM import with require() for chromadb to ensure Electron can resolve the package against the plugin's node_modules. Also wrap default fetch fallback in an arrow function to avoid potential strict mode issues with global fetch. --- main.js | 15 +++------------ src/indexing-pipeline/vectorization.ts | 2 +- src/ollama-client.ts | 2 +- src/semantic-cache.ts | 9 ++++++--- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/main.js b/main.js index 5b55966..4b7da91 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,7 @@ "use strict"; -var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) @@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => { } return to; }; -var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod -)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/main.ts @@ -194,7 +184,8 @@ var SemanticCacheService = class _SemanticCacheService { async initialize() { if (!this.config.enabled) return; try { - const { ChromaClient } = await import("chromadb"); + const chromadb = require("chromadb"); + const { ChromaClient } = chromadb; const chromaURL = this.config.chromaURL || "http://localhost:8000"; this.client = new ChromaClient({ path: chromaURL }); this.collection = await this.client.getOrCreateCollection({ @@ -285,7 +276,7 @@ var OllamaClient = class { this.currentStreamController = null; this.baseURL = baseURL; this.model = model; - this.fetchFn = fetchFn ?? fetch; + this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init)); if (cacheConfig?.enabled) { this.cacheService = new SemanticCacheService(baseURL, cacheConfig); void this.cacheService.initialize(); diff --git a/src/indexing-pipeline/vectorization.ts b/src/indexing-pipeline/vectorization.ts index 3c7fbd4..62612c0 100644 --- a/src/indexing-pipeline/vectorization.ts +++ b/src/indexing-pipeline/vectorization.ts @@ -19,7 +19,7 @@ export class ContentVectorizer { constructor(config: VectorizationConfig, fetchFn?: typeof fetch) { this.model = config.model; this.ollamaUrl = config.ollamaUrl; - this.fetchFn = fetchFn ?? fetch; + this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init)); } /** diff --git a/src/ollama-client.ts b/src/ollama-client.ts index 03a0fe2..ed149f0 100644 --- a/src/ollama-client.ts +++ b/src/ollama-client.ts @@ -22,7 +22,7 @@ export class OllamaClient { constructor(baseURL: string, model: string, fetchFn?: typeof fetch, cacheConfig?: CacheConfig) { this.baseURL = baseURL; this.model = model; - this.fetchFn = fetchFn ?? fetch; + this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init)); if (cacheConfig?.enabled) { this.cacheService = new SemanticCacheService(baseURL, cacheConfig); diff --git a/src/semantic-cache.ts b/src/semantic-cache.ts index 3e7b61a..cacc342 100644 --- a/src/semantic-cache.ts +++ b/src/semantic-cache.ts @@ -20,9 +20,12 @@ export class SemanticCacheService { if (!this.config.enabled) return; try { - // Dynamic import — chromadb is optional and may not be installed. - // This prevents the plugin from crashing at load time if chromadb is absent. - const { ChromaClient } = await import('chromadb'); + // Dynamic require — chromadb is optional and may not be installed. + // Using Node's require() instead of ESM import() so Electron can resolve + // the external chromadb package against the plugin's node_modules. + // eslint-disable-next-line @typescript-eslint/no-var-requires + const chromadb = require('chromadb'); + const { ChromaClient } = chromadb; const chromaURL = this.config.chromaURL || 'http://localhost:8000'; this.client = new ChromaClient({ path: chromaURL }); this.collection = await this.client.getOrCreateCollection({