mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:20:43 +00:00
fix(plugin-sdk): fall back from dist facade overrides to source surfaces
This commit is contained in:
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
PUBLIC_SURFACE_SOURCE_EXTENSIONS,
|
||||
normalizeBundledPluginArtifactSubpath,
|
||||
resolveBundledPluginPublicSurfacePath,
|
||||
resolveBundledPluginSourcePublicSurfacePath,
|
||||
} from "./public-surface-runtime.js";
|
||||
|
||||
@@ -49,6 +50,25 @@ describe("bundled plugin public surface runtime", () => {
|
||||
).toBe(modulePath);
|
||||
});
|
||||
|
||||
it("falls back from package dist overrides to the source extension tree", () => {
|
||||
const packageRoot = createTempDir();
|
||||
const sourceModulePath = path.join(packageRoot, "extensions", "demo", "api.ts");
|
||||
fs.mkdirSync(path.dirname(sourceModulePath), { recursive: true });
|
||||
fs.writeFileSync(sourceModulePath, "export const marker = 'source';\n", "utf8");
|
||||
|
||||
const bundledPluginsDir = path.join(packageRoot, "dist", "extensions");
|
||||
fs.mkdirSync(path.join(bundledPluginsDir, "demo"), { recursive: true });
|
||||
|
||||
expect(
|
||||
resolveBundledPluginPublicSurfacePath({
|
||||
rootDir: packageRoot,
|
||||
bundledPluginsDir,
|
||||
dirName: "demo",
|
||||
artifactBasename: "api.js",
|
||||
}),
|
||||
).toBe(sourceModulePath);
|
||||
});
|
||||
|
||||
it("allows plugin-local nested artifact paths", () => {
|
||||
expect(normalizeBundledPluginArtifactSubpath("src/outbound-adapter.js")).toBe(
|
||||
"src/outbound-adapter.js",
|
||||
|
||||
@@ -58,6 +58,28 @@ export function resolveBundledPluginSourcePublicSurfacePath(params: {
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolvePackageSourceFallbackForBundledDir(params: {
|
||||
rootDir: string;
|
||||
bundledPluginsDir: string;
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
}): string | null {
|
||||
const normalizedBundledDir = path.resolve(params.bundledPluginsDir);
|
||||
const normalizedRootDir = path.resolve(params.rootDir);
|
||||
const packageBundledDirs = [
|
||||
path.join(normalizedRootDir, "dist", "extensions"),
|
||||
path.join(normalizedRootDir, "dist-runtime", "extensions"),
|
||||
];
|
||||
if (!packageBundledDirs.includes(normalizedBundledDir)) {
|
||||
return null;
|
||||
}
|
||||
return resolveBundledPluginSourcePublicSurfacePath({
|
||||
sourceRoot: path.join(normalizedRootDir, "extensions"),
|
||||
dirName: params.dirName,
|
||||
artifactBasename: params.artifactBasename,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveBundledPluginPublicSurfacePath(params: {
|
||||
rootDir: string;
|
||||
dirName: string;
|
||||
@@ -75,11 +97,19 @@ export function resolveBundledPluginPublicSurfacePath(params: {
|
||||
if (fs.existsSync(explicitBuiltCandidate)) {
|
||||
return explicitBuiltCandidate;
|
||||
}
|
||||
return resolveBundledPluginSourcePublicSurfacePath({
|
||||
sourceRoot: explicitBundledPluginsDir,
|
||||
dirName: params.dirName,
|
||||
artifactBasename,
|
||||
});
|
||||
return (
|
||||
resolveBundledPluginSourcePublicSurfacePath({
|
||||
sourceRoot: explicitBundledPluginsDir,
|
||||
dirName: params.dirName,
|
||||
artifactBasename,
|
||||
}) ??
|
||||
resolvePackageSourceFallbackForBundledDir({
|
||||
rootDir: params.rootDir,
|
||||
bundledPluginsDir: explicitBundledPluginsDir,
|
||||
dirName: params.dirName,
|
||||
artifactBasename,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
for (const candidate of [
|
||||
|
||||
Reference in New Issue
Block a user