Skip to content

Commit 32e3bd3

Browse files
authored
refactor(plugins): centralize bundled tree detection (#122093)
1 parent afc6444 commit 32e3bd3

2 files changed

Lines changed: 6 additions & 21 deletions

File tree

‎src/plugins/bundled-dir.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function shouldTrustTestBundledPluginsDirOverride(env: NodeJS.ProcessEnv): boole
4848
);
4949
}
5050

51-
function hasUsableBundledPluginTree(pluginsDir: string): boolean {
51+
export function hasUsableBundledPluginTree(pluginsDir: string): boolean {
5252
if (!fs.existsSync(pluginsDir)) {
5353
return false;
5454
}

‎src/plugins/discovery.ts‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { tryReadJsonSync } from "../infra/json-files.js";
1212
import { resolveUserPath } from "../utils.js";
1313
import { resolveCompatibilityHostVersion } from "../version.js";
1414
import { detectBundleManifestFormat, loadBundleManifest } from "./bundle-manifest.js";
15-
import { resolveSourceCheckoutDependencyDiagnostic } from "./bundled-dir.js";
15+
import {
16+
hasUsableBundledPluginTree,
17+
resolveSourceCheckoutDependencyDiagnostic,
18+
} from "./bundled-dir.js";
1619
import { buildLegacyBundledRootPath } from "./bundled-load-path-aliases.js";
1720
import { listBundledSourceOverlayDirs } from "./bundled-source-overlays.js";
1821
import { shouldRejectHardlinkedPluginFiles } from "./hardlink-policy.js";
@@ -1214,31 +1217,13 @@ function discoverInDirectory(params: {
12141217
}
12151218
}
12161219

1217-
function hasDiscoverablePluginTree(pluginsDir: string): boolean {
1218-
try {
1219-
return fs.readdirSync(pluginsDir, { withFileTypes: true }).some((entry) => {
1220-
if (!entry.isDirectory()) {
1221-
return false;
1222-
}
1223-
const pluginDir = path.join(pluginsDir, entry.name);
1224-
return (
1225-
fs.existsSync(path.join(pluginDir, "package.json")) ||
1226-
fs.existsSync(path.join(pluginDir, "openclaw.plugin.json"))
1227-
);
1228-
});
1229-
} catch {
1230-
return false;
1231-
}
1232-
}
1233-
12341220
function isSourceCheckoutExtensionsDir(extensionsDir: string): boolean {
12351221
const packageRoot = path.dirname(extensionsDir);
12361222
return (
12371223
fs.existsSync(path.join(packageRoot, ".git")) &&
12381224
fs.existsSync(path.join(packageRoot, "pnpm-workspace.yaml")) &&
12391225
fs.existsSync(path.join(packageRoot, "src")) &&
1240-
fs.existsSync(extensionsDir) &&
1241-
hasDiscoverablePluginTree(extensionsDir)
1226+
hasUsableBundledPluginTree(extensionsDir)
12421227
);
12431228
}
12441229

0 commit comments

Comments
 (0)