mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:10:44 +00:00
fix(plugins): widen extension-api source alias candidates
This commit is contained in:
@@ -103,9 +103,13 @@ function createPluginSdkAliasFixture(params?: {
|
||||
return { root, srcFile, distFile };
|
||||
}
|
||||
|
||||
function createExtensionApiAliasFixture(params?: { srcBody?: string; distBody?: string }) {
|
||||
function createExtensionApiAliasFixture(params?: {
|
||||
srcBody?: string;
|
||||
distBody?: string;
|
||||
srcExtension?: ".ts" | ".mts" | ".js" | ".mjs" | ".cts" | ".cjs";
|
||||
}) {
|
||||
const root = makeTempDir();
|
||||
const srcFile = path.join(root, "src", "extensionAPI.ts");
|
||||
const srcFile = path.join(root, "src", `extensionAPI${params?.srcExtension ?? ".ts"}`);
|
||||
const distFile = path.join(root, "dist", "extensionAPI.js");
|
||||
mkdirSafeDir(path.dirname(srcFile));
|
||||
mkdirSafeDir(path.dirname(distFile));
|
||||
@@ -441,6 +445,16 @@ describe("plugin sdk alias helpers", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves source extension-api aliases through the wider source extension family", () => {
|
||||
const fixture = createExtensionApiAliasFixture({ srcExtension: ".mts" });
|
||||
expectExtensionApiAliasResolution({
|
||||
fixture,
|
||||
modulePath: (root: string) => path.join(root, "src", "plugins", "loader.ts"),
|
||||
env: { NODE_ENV: undefined },
|
||||
expected: "src",
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "prefers dist candidates first for production src runtime",
|
||||
|
||||
@@ -252,6 +252,14 @@ export function resolvePluginSdkAliasFile(params: {
|
||||
const cachedPluginSdkExportedSubpaths = new Map<string, string[]>();
|
||||
const cachedPluginSdkScopedAliasMaps = new Map<string, Record<string, string>>();
|
||||
const PLUGIN_SDK_PACKAGE_NAMES = ["openclaw/plugin-sdk", "@openclaw/plugin-sdk"] as const;
|
||||
const EXTENSION_API_SOURCE_CANDIDATE_EXTENSIONS = [
|
||||
".ts",
|
||||
".mts",
|
||||
".js",
|
||||
".mjs",
|
||||
".cts",
|
||||
".cjs",
|
||||
] as const;
|
||||
|
||||
export function listPluginSdkExportedSubpaths(
|
||||
params: {
|
||||
@@ -344,14 +352,19 @@ export function resolveExtensionApiAlias(params: LoaderModuleResolveParams = {})
|
||||
isProduction: process.env.NODE_ENV === "production",
|
||||
pluginSdkResolution: params.pluginSdkResolution,
|
||||
});
|
||||
const candidateMap = {
|
||||
src: path.join(packageRoot, "src", "extensionAPI.ts"),
|
||||
dist: path.join(packageRoot, "dist", "extensionAPI.js"),
|
||||
} as const;
|
||||
for (const kind of orderedKinds) {
|
||||
const candidate = candidateMap[kind];
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
if (kind === "dist") {
|
||||
const candidate = path.join(packageRoot, "dist", "extensionAPI.js");
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (const ext of EXTENSION_API_SOURCE_CANDIDATE_EXTENSIONS) {
|
||||
const candidate = path.join(packageRoot, "src", `extensionAPI${ext}`);
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user