mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
plugin-sdk: add channel subpaths and migrate bundled plugins
This commit is contained in:
50
scripts/check-no-monolithic-plugin-sdk-entry-imports.ts
Normal file
50
scripts/check-no-monolithic-plugin-sdk-entry-imports.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user