Plugins: prefer scanDir override paths

This commit is contained in:
Gustavo Madeira Santana
2026-04-15 17:02:33 -04:00
parent 8c392f0019
commit b2974da33a
2 changed files with 28 additions and 1 deletions

View File

@@ -313,6 +313,33 @@ describe("bundled plugin metadata", () => {
).toBe(path.join(pluginRoot, "index.ts"));
});
it("prefers direct scan-dir overrides over nested dist artifacts within the same override root", () => {
const pluginsDir = createGeneratedPluginTempRoot("openclaw-bundled-plugin-direct-priority-");
const pluginRoot = path.join(pluginsDir, "alpha");
const nestedDistPluginRoot = path.join(pluginsDir, "dist", "extensions", "alpha");
fs.mkdirSync(pluginRoot, { recursive: true });
fs.mkdirSync(nestedDistPluginRoot, { recursive: true });
fs.writeFileSync(path.join(pluginRoot, "index.js"), "export const source = true;\n", "utf8");
fs.writeFileSync(
path.join(nestedDistPluginRoot, "index.js"),
"export const built = true;\n",
"utf8",
);
expect(
resolveBundledPluginGeneratedPath(
pluginsDir,
{
source: "./index.ts",
built: "index.js",
},
"alpha",
pluginsDir,
),
).toBe(path.join(pluginRoot, "index.js"));
});
it("resolves bundled repo entry paths from dist before workspace source", () => {
const tempRoot = createGeneratedPluginTempRoot("openclaw-bundled-plugin-repo-entry-");
const pluginRoot = path.join(tempRoot, "extensions", "alpha");

View File

@@ -248,9 +248,9 @@ function listBundledPluginEntryBaseDirs(params: {
scanDir?: string;
}): string[] {
const baseDirs = [
...(params.scanDir ? [path.resolve(params.scanDir, params.pluginDirName ?? "")] : []),
path.resolve(params.rootDir, "dist", "extensions", params.pluginDirName ?? ""),
path.resolve(params.rootDir, "extensions", params.pluginDirName ?? ""),
...(params.scanDir ? [path.resolve(params.scanDir, params.pluginDirName ?? "")] : []),
];
return baseDirs.filter((entry, index, all) => all.indexOf(entry) === index);
}