mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:50:43 +00:00
fix: resolve bundled public surfaces from packaged dist
(cherry picked from commit 8771cfb5b7)
This commit is contained in:
@@ -70,6 +70,25 @@ describe("bundled plugin public surface runtime", () => {
|
||||
).toBe(sourceModulePath);
|
||||
});
|
||||
|
||||
it("falls back from an incomplete package dist-runtime override to packaged dist", () => {
|
||||
const packageRoot = createTempDir();
|
||||
const distModulePath = path.join(packageRoot, "dist", "extensions", "demo", "api.js");
|
||||
fs.mkdirSync(path.dirname(distModulePath), { recursive: true });
|
||||
fs.writeFileSync(distModulePath, "export const marker = 'dist';\n", "utf8");
|
||||
|
||||
const runtimeBundledPluginsDir = path.join(packageRoot, "dist-runtime", "extensions");
|
||||
fs.mkdirSync(path.join(runtimeBundledPluginsDir, "demo"), { recursive: true });
|
||||
|
||||
expect(
|
||||
resolveBundledPluginPublicSurfacePath({
|
||||
rootDir: packageRoot,
|
||||
bundledPluginsDir: runtimeBundledPluginsDir,
|
||||
dirName: "demo",
|
||||
artifactBasename: "api.js",
|
||||
}),
|
||||
).toBe(distModulePath);
|
||||
});
|
||||
|
||||
it("allows plugin-local nested artifact paths", () => {
|
||||
expect(normalizeBundledPluginArtifactSubpath("src/outbound-adapter.js")).toBe(
|
||||
"src/outbound-adapter.js",
|
||||
|
||||
@@ -70,7 +70,7 @@ export function resolveBundledPluginSourcePublicSurfacePath(params: {
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolvePackageSourceFallbackForBundledDir(params: {
|
||||
function resolvePackageFallbackForBundledDir(params: {
|
||||
rootDir: string;
|
||||
bundledPluginsDir: string;
|
||||
dirName: string;
|
||||
@@ -85,6 +85,15 @@ function resolvePackageSourceFallbackForBundledDir(params: {
|
||||
if (!packageBundledDirs.includes(normalizedBundledDir)) {
|
||||
return null;
|
||||
}
|
||||
for (const packageBundledDir of packageBundledDirs) {
|
||||
if (packageBundledDir === normalizedBundledDir) {
|
||||
continue;
|
||||
}
|
||||
const builtCandidate = path.join(packageBundledDir, params.dirName, params.artifactBasename);
|
||||
if (fs.existsSync(builtCandidate)) {
|
||||
return builtCandidate;
|
||||
}
|
||||
}
|
||||
return resolveBundledPluginSourcePublicSurfacePath({
|
||||
sourceRoot: path.join(normalizedRootDir, "extensions"),
|
||||
dirName: params.dirName,
|
||||
@@ -116,7 +125,7 @@ export function resolveBundledPluginPublicSurfacePath(params: {
|
||||
dirName,
|
||||
artifactBasename,
|
||||
}) ??
|
||||
resolvePackageSourceFallbackForBundledDir({
|
||||
resolvePackageFallbackForBundledDir({
|
||||
rootDir: params.rootDir,
|
||||
bundledPluginsDir: explicitBundledPluginsDir,
|
||||
dirName,
|
||||
|
||||
Reference in New Issue
Block a user