fix(channels): honor module loader native opt-out

This commit is contained in:
Peter Steinberger
2026-05-01 15:05:58 +01:00
parent b15faae92f
commit f0a2b09df6
2 changed files with 6 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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);
}