mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
refactor(plugins): centralize npm runtime package planning
This commit is contained in:
@@ -1,37 +1,15 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolvePluginNpmRuntimeBuildPlan } from "../scripts/lib/plugin-npm-runtime-build.mjs";
|
||||
import {
|
||||
listPublishablePluginPackageDirs,
|
||||
resolvePluginNpmRuntimeBuildPlan,
|
||||
} from "../scripts/lib/plugin-npm-runtime-build.mjs";
|
||||
|
||||
const repoRoot = path.resolve(import.meta.dirname, "..");
|
||||
|
||||
function readJsonFile(filePath: string): Record<string, unknown> {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8")) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function isPublishablePluginPackage(packageJson: Record<string, unknown>): boolean {
|
||||
const openclaw = packageJson.openclaw as { release?: { publishToNpm?: unknown } } | undefined;
|
||||
return openclaw?.release?.publishToNpm === true;
|
||||
}
|
||||
|
||||
function listPublishablePluginPackageDirs(): string[] {
|
||||
const extensionsRoot = path.join(repoRoot, "extensions");
|
||||
return fs
|
||||
.readdirSync(extensionsRoot, { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map((dirent) => path.join(extensionsRoot, dirent.name))
|
||||
.filter((packageDir) => {
|
||||
const packageJsonPath = path.join(packageDir, "package.json");
|
||||
return (
|
||||
fs.existsSync(packageJsonPath) && isPublishablePluginPackage(readJsonFile(packageJsonPath))
|
||||
);
|
||||
})
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
describe("plugin npm runtime build planning", () => {
|
||||
it("plans package-local runtime entries for every publishable plugin package", () => {
|
||||
const packageDirs = listPublishablePluginPackageDirs();
|
||||
const packageDirs = listPublishablePluginPackageDirs({ repoRoot });
|
||||
expect(packageDirs.length).toBeGreaterThan(0);
|
||||
|
||||
const plans = packageDirs.map((packageDir) =>
|
||||
@@ -46,6 +24,8 @@ describe("plugin npm runtime build planning", () => {
|
||||
for (const plan of plans) {
|
||||
expect(plan?.outDir).toBe(path.join(plan?.packageDir ?? "", "dist"));
|
||||
expect(plan?.runtimeExtensions.every((entry) => entry.startsWith("./dist/"))).toBe(true);
|
||||
expect(plan?.runtimeBuildOutputs.every((entry) => entry.startsWith("./dist/"))).toBe(true);
|
||||
expect(plan?.packageFiles).toContain("dist/**");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,5 +55,11 @@ describe("plugin npm runtime build planning", () => {
|
||||
"runtime-api": path.join(repoRoot, "extensions", "diffs", "runtime-api.ts"),
|
||||
}),
|
||||
);
|
||||
expect(diffsPlan?.packageFiles).toEqual([
|
||||
"dist/**",
|
||||
"openclaw.plugin.json",
|
||||
"README.md",
|
||||
"skills/**",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user