From f0a2b09df69a08bf9eb6c4f7c042c2eb8da42959 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 1 May 2026 15:05:58 +0100 Subject: [PATCH] fix(channels): honor module loader native opt-out --- src/channels/plugins/module-loader.test.ts | 3 +-- src/channels/plugins/module-loader.ts | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/channels/plugins/module-loader.test.ts b/src/channels/plugins/module-loader.test.ts index 94d8d934394..365a0e6bc40 100644 --- a/src/channels/plugins/module-loader.test.ts +++ b/src/channels/plugins/module-loader.test.ts @@ -3,7 +3,6 @@ import os from "node:os"; import path from "node:path"; import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures"; import { afterEach, describe, expect, it, vi } from "vitest"; -import { shouldExpectNativeJitiForJavaScriptTestRuntime } from "../../test-utils/jiti-runtime.js"; import { isJavaScriptModulePath, resolveCompiledBundledModulePath, @@ -122,7 +121,7 @@ describe("channel plugin module loader helpers", () => { expect(createJiti).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ - tryNative: shouldExpectNativeJitiForJavaScriptTestRuntime(), + tryNative: false, }), ); } finally { diff --git a/src/channels/plugins/module-loader.ts b/src/channels/plugins/module-loader.ts index b49e75f853f..ec3dfa51c37 100644 --- a/src/channels/plugins/module-loader.ts +++ b/src/channels/plugins/module-loader.ts @@ -11,7 +11,7 @@ export { isJavaScriptModulePath } from "../../plugins/native-module-require.js"; function createModuleLoader() { const jitiLoaders: PluginJitiLoaderCache = new Map(); - return (modulePath: string) => { + return (modulePath: string, tryNative?: boolean) => { return getCachedPluginJitiLoader({ cache: jitiLoaders, modulePath, @@ -19,6 +19,7 @@ function createModuleLoader() { argvEntry: process.argv[1], preferBuiltDist: true, jitiFilename: import.meta.url, + tryNative, }); }; } @@ -83,7 +84,8 @@ export function loadChannelPluginModule(params: { } const safePath = opened.path; fs.closeSync(opened.fd); - if (params.shouldTryNativeRequire?.(safePath)) { + const shouldTryNative = params.shouldTryNativeRequire?.(safePath); + if (shouldTryNative) { const nativeModule = tryNativeRequireJavaScriptModule(safePath, { allowWindows: true, }); @@ -91,5 +93,5 @@ export function loadChannelPluginModule(params: { return nativeModule.moduleExport; } } - return loadModule(safePath)(safePath); + return loadModule(safePath, shouldTryNative)(safePath); }