mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 04:40:20 +00:00
fix(test): restore bundled loader coverage
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { resolveOpenClawPackageRootSync } from "../../infra/openclaw-root.js";
|
||||
import { createSubsystemLogger } from "../../logging/subsystem.js";
|
||||
import type {
|
||||
@@ -23,10 +24,13 @@ type GeneratedBundledChannelEntry = {
|
||||
const log = createSubsystemLogger("channels");
|
||||
const OPENCLAW_PACKAGE_ROOT =
|
||||
resolveOpenClawPackageRootSync({
|
||||
cwd: process.cwd(),
|
||||
moduleUrl: import.meta.url,
|
||||
argv1: process.argv[1],
|
||||
}) ?? process.cwd();
|
||||
cwd: process.cwd(),
|
||||
moduleUrl: import.meta.url.startsWith("file:") ? import.meta.url : undefined,
|
||||
}) ??
|
||||
(import.meta.url.startsWith("file:")
|
||||
? path.resolve(fileURLToPath(new URL("../../..", import.meta.url)))
|
||||
: process.cwd());
|
||||
|
||||
function resolveChannelPluginModuleEntry(
|
||||
moduleExport: unknown,
|
||||
@@ -94,15 +98,35 @@ function resolveBundledChannelBoundaryRoot(params: {
|
||||
return path.resolve(OPENCLAW_PACKAGE_ROOT, "extensions", params.metadata.dirName);
|
||||
}
|
||||
|
||||
function resolveGeneratedBundledChannelModulePath(params: {
|
||||
metadata: BundledChannelPluginMetadata;
|
||||
entry: BundledChannelPluginMetadata["source"] | BundledChannelPluginMetadata["setupSource"];
|
||||
}): string | null {
|
||||
if (!params.entry) {
|
||||
return null;
|
||||
}
|
||||
const candidateRoots = [
|
||||
path.resolve(OPENCLAW_PACKAGE_ROOT, "dist", "extensions", params.metadata.dirName),
|
||||
path.resolve(OPENCLAW_PACKAGE_ROOT, "extensions", params.metadata.dirName),
|
||||
];
|
||||
for (const rootDir of candidateRoots) {
|
||||
const resolved = resolveBundledChannelGeneratedPath(
|
||||
rootDir,
|
||||
params.entry,
|
||||
params.metadata.dirName,
|
||||
);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function loadGeneratedBundledChannelModule(params: {
|
||||
metadata: BundledChannelPluginMetadata;
|
||||
entry: BundledChannelPluginMetadata["source"] | BundledChannelPluginMetadata["setupSource"];
|
||||
}): unknown {
|
||||
const modulePath = resolveBundledChannelGeneratedPath(
|
||||
OPENCLAW_PACKAGE_ROOT,
|
||||
params.entry,
|
||||
params.metadata.dirName,
|
||||
);
|
||||
const modulePath = resolveGeneratedBundledChannelModulePath(params);
|
||||
if (!modulePath) {
|
||||
throw new Error(`missing generated module for bundled channel ${params.metadata.manifest.id}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user