mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
fix(release): ship bundled plugins in pack artifacts
This commit is contained in:
95
scripts/lib/bundled-plugin-build-entries.mjs
Normal file
95
scripts/lib/bundled-plugin-build-entries.mjs
Normal file
@@ -0,0 +1,95 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { shouldBuildBundledCluster } from "./optional-bundled-clusters.mjs";
|
||||
|
||||
function readBundledPluginPackageJson(packageJsonPath) {
|
||||
if (!fs.existsSync(packageJsonPath)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function collectPluginSourceEntries(packageJson) {
|
||||
let packageEntries = Array.isArray(packageJson?.openclaw?.extensions)
|
||||
? packageJson.openclaw.extensions.filter(
|
||||
(entry) => typeof entry === "string" && entry.trim().length > 0,
|
||||
)
|
||||
: [];
|
||||
const setupEntry =
|
||||
typeof packageJson?.openclaw?.setupEntry === "string" &&
|
||||
packageJson.openclaw.setupEntry.trim().length > 0
|
||||
? packageJson.openclaw.setupEntry
|
||||
: undefined;
|
||||
if (setupEntry) {
|
||||
packageEntries = Array.from(new Set([...packageEntries, setupEntry]));
|
||||
}
|
||||
return packageEntries.length > 0 ? packageEntries : ["./index.ts"];
|
||||
}
|
||||
|
||||
export function collectBundledPluginBuildEntries(params = {}) {
|
||||
const cwd = params.cwd ?? process.cwd();
|
||||
const env = params.env ?? process.env;
|
||||
const extensionsRoot = path.join(cwd, "extensions");
|
||||
const entries = [];
|
||||
|
||||
for (const dirent of fs.readdirSync(extensionsRoot, { withFileTypes: true })) {
|
||||
if (!dirent.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const pluginDir = path.join(extensionsRoot, dirent.name);
|
||||
const manifestPath = path.join(pluginDir, "openclaw.plugin.json");
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const packageJsonPath = path.join(pluginDir, "package.json");
|
||||
const packageJson = readBundledPluginPackageJson(packageJsonPath);
|
||||
if (!shouldBuildBundledCluster(dirent.name, env, { packageJson })) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entries.push({
|
||||
id: dirent.name,
|
||||
hasPackageJson: packageJson !== null,
|
||||
packageJson,
|
||||
sourceEntries: collectPluginSourceEntries(packageJson),
|
||||
});
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
export function listBundledPluginBuildEntries(params = {}) {
|
||||
return Object.fromEntries(
|
||||
collectBundledPluginBuildEntries(params).flatMap(({ id, sourceEntries }) =>
|
||||
sourceEntries.map((entry) => {
|
||||
const normalizedEntry = entry.replace(/^\.\//, "");
|
||||
const entryKey = `extensions/${id}/${normalizedEntry.replace(/\.[^.]+$/u, "")}`;
|
||||
return [entryKey, path.join("extensions", id, normalizedEntry)];
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function listBundledPluginPackArtifacts(params = {}) {
|
||||
const entries = collectBundledPluginBuildEntries(params);
|
||||
const artifacts = new Set();
|
||||
|
||||
for (const { id, hasPackageJson, sourceEntries } of entries) {
|
||||
artifacts.add(`dist/extensions/${id}/openclaw.plugin.json`);
|
||||
if (hasPackageJson) {
|
||||
artifacts.add(`dist/extensions/${id}/package.json`);
|
||||
}
|
||||
for (const entry of sourceEntries) {
|
||||
const normalizedEntry = entry.replace(/^\.\//, "").replace(/\.[^.]+$/u, "");
|
||||
artifacts.add(`dist/extensions/${id}/${normalizedEntry}.js`);
|
||||
}
|
||||
}
|
||||
|
||||
return [...artifacts].toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
@@ -3,4 +3,9 @@ export const optionalBundledClusterSet: Set<string>;
|
||||
export const OPTIONAL_BUNDLED_BUILD_ENV: "OPENCLAW_INCLUDE_OPTIONAL_BUNDLED";
|
||||
export function isOptionalBundledCluster(cluster: string): boolean;
|
||||
export function shouldIncludeOptionalBundledClusters(env?: NodeJS.ProcessEnv): boolean;
|
||||
export function shouldBuildBundledCluster(cluster: string, env?: NodeJS.ProcessEnv): boolean;
|
||||
export function hasReleasedBundledInstall(packageJson: unknown): boolean;
|
||||
export function shouldBuildBundledCluster(
|
||||
cluster: string,
|
||||
env?: NodeJS.ProcessEnv,
|
||||
options?: { packageJson?: unknown },
|
||||
): boolean;
|
||||
|
||||
7
scripts/lib/optional-bundled-clusters.d.ts
vendored
7
scripts/lib/optional-bundled-clusters.d.ts
vendored
@@ -3,4 +3,9 @@ export const optionalBundledClusterSet: Set<string>;
|
||||
export const OPTIONAL_BUNDLED_BUILD_ENV: "OPENCLAW_INCLUDE_OPTIONAL_BUNDLED";
|
||||
export function isOptionalBundledCluster(cluster: string): boolean;
|
||||
export function shouldIncludeOptionalBundledClusters(env?: NodeJS.ProcessEnv): boolean;
|
||||
export function shouldBuildBundledCluster(cluster: string, env?: NodeJS.ProcessEnv): boolean;
|
||||
export function hasReleasedBundledInstall(packageJson: unknown): boolean;
|
||||
export function shouldBuildBundledCluster(
|
||||
cluster: string,
|
||||
env?: NodeJS.ProcessEnv,
|
||||
options?: { packageJson?: unknown },
|
||||
): boolean;
|
||||
|
||||
@@ -26,6 +26,16 @@ export function shouldIncludeOptionalBundledClusters(env = process.env) {
|
||||
return env[OPTIONAL_BUNDLED_BUILD_ENV] === "1";
|
||||
}
|
||||
|
||||
export function shouldBuildBundledCluster(cluster, env = process.env) {
|
||||
export function hasReleasedBundledInstall(packageJson) {
|
||||
return (
|
||||
typeof packageJson?.openclaw?.install?.npmSpec === "string" &&
|
||||
packageJson.openclaw.install.npmSpec.trim().length > 0
|
||||
);
|
||||
}
|
||||
|
||||
export function shouldBuildBundledCluster(cluster, env = process.env, options = {}) {
|
||||
if (hasReleasedBundledInstall(options.packageJson)) {
|
||||
return true;
|
||||
}
|
||||
return shouldIncludeOptionalBundledClusters(env) || !isOptionalBundledCluster(cluster);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user