mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { discoverOpenClawPlugins } from "../src/plugins/discovery.js";
|
|
|
|
const ROOT_IMPORT_PATTERNS = [
|
|
/\b(?:import|export)\b[\s\S]*?\bfrom\s+["']openclaw\/plugin-sdk["']/,
|
|
/\bimport\s+["']openclaw\/plugin-sdk["']/,
|
|
/\bimport\s*\(\s*["']openclaw\/plugin-sdk["']\s*\)/,
|
|
/\brequire\s*\(\s*["']openclaw\/plugin-sdk["']\s*\)/,
|
|
];
|
|
|
|
function hasMonolithicRootImport(content: string): boolean {
|
|
return ROOT_IMPORT_PATTERNS.some((pattern) => pattern.test(content));
|
|
}
|
|
|
|
function main() {
|
|
const discovery = discoverOpenClawPlugins({});
|
|
const bundledEntryFiles = [
|
|
...new Set(discovery.candidates.filter((c) => c.origin === "bundled").map((c) => c.source)),
|
|
];
|
|
|
|
const offenders: string[] = [];
|
|
for (const entryFile of bundledEntryFiles) {
|
|
let content = "";
|
|
try {
|
|
content = fs.readFileSync(entryFile, "utf8");
|
|
} catch {
|
|
continue;
|
|
}
|
|
if (hasMonolithicRootImport(content)) {
|
|
offenders.push(entryFile);
|
|
}
|
|
}
|
|
|
|
if (offenders.length > 0) {
|
|
console.error("Bundled plugin entrypoints must not import monolithic openclaw/plugin-sdk.");
|
|
for (const file of offenders.toSorted()) {
|
|
const relative = path.relative(process.cwd(), file) || file;
|
|
console.error(`- ${relative}`);
|
|
}
|
|
console.error("Use openclaw/plugin-sdk/<channel> for channel plugins or /core for others.");
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(
|
|
`OK: bundled entrypoints use scoped plugin-sdk subpaths (${bundledEntryFiles.length} checked).`,
|
|
);
|
|
}
|
|
|
|
main();
|