mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
fix: ship bundled plugin runtime sidecars
This commit is contained in:
@@ -2,6 +2,8 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { shouldBuildBundledCluster } from "./optional-bundled-clusters.mjs";
|
||||
|
||||
const TOP_LEVEL_PUBLIC_SURFACE_EXTENSIONS = new Set([".ts", ".js", ".mts", ".cts", ".mjs", ".cjs"]);
|
||||
|
||||
function readBundledPluginPackageJson(packageJsonPath) {
|
||||
if (!fs.existsSync(packageJsonPath)) {
|
||||
return null;
|
||||
@@ -30,6 +32,39 @@ function collectPluginSourceEntries(packageJson) {
|
||||
return packageEntries.length > 0 ? packageEntries : ["./index.ts"];
|
||||
}
|
||||
|
||||
function collectTopLevelPublicSurfaceEntries(pluginDir) {
|
||||
if (!fs.existsSync(pluginDir)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return fs
|
||||
.readdirSync(pluginDir, { withFileTypes: true })
|
||||
.flatMap((dirent) => {
|
||||
if (!dirent.isFile()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const ext = path.extname(dirent.name);
|
||||
if (!TOP_LEVEL_PUBLIC_SURFACE_EXTENSIONS.has(ext)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const normalizedName = dirent.name.toLowerCase();
|
||||
if (
|
||||
normalizedName.endsWith(".d.ts") ||
|
||||
normalizedName.includes(".test.") ||
|
||||
normalizedName.includes(".spec.") ||
|
||||
normalizedName.includes(".fixture.") ||
|
||||
normalizedName.includes(".snap")
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [`./${dirent.name}`];
|
||||
})
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
export function collectBundledPluginBuildEntries(params = {}) {
|
||||
const cwd = params.cwd ?? process.cwd();
|
||||
const env = params.env ?? process.env;
|
||||
@@ -57,7 +92,12 @@ export function collectBundledPluginBuildEntries(params = {}) {
|
||||
id: dirent.name,
|
||||
hasPackageJson: packageJson !== null,
|
||||
packageJson,
|
||||
sourceEntries: collectPluginSourceEntries(packageJson),
|
||||
sourceEntries: Array.from(
|
||||
new Set([
|
||||
...collectPluginSourceEntries(packageJson),
|
||||
...collectTopLevelPublicSurfaceEntries(pluginDir),
|
||||
]),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ export function collectPublishablePluginPackageErrors(
|
||||
errors.push("package.json version must be non-empty.");
|
||||
} else if (parseReleaseVersion(packageVersion) === null) {
|
||||
errors.push(
|
||||
`package.json version must match YYYY.M.D or YYYY.M.D-beta.N; found "${packageVersion}".`,
|
||||
`package.json version must match YYYY.M.D, YYYY.M.D-N, or YYYY.M.D-beta.N; found "${packageVersion}".`,
|
||||
);
|
||||
}
|
||||
if (!Array.isArray(extensions) || extensions.length === 0) {
|
||||
@@ -224,7 +224,7 @@ export function collectPublishablePluginPackages(
|
||||
const parsedVersion = parseReleaseVersion(version);
|
||||
if (parsedVersion === null) {
|
||||
validationErrors.push(
|
||||
`${dir.name}: package.json version must match YYYY.M.D or YYYY.M.D-beta.N; found "${version}".`,
|
||||
`${dir.name}: package.json version must match YYYY.M.D, YYYY.M.D-N, or YYYY.M.D-beta.N; found "${version}".`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -18,17 +18,20 @@ type PackageJson = {
|
||||
|
||||
export type ParsedReleaseVersion = {
|
||||
version: string;
|
||||
baseVersion: string;
|
||||
channel: "stable" | "beta";
|
||||
year: number;
|
||||
month: number;
|
||||
day: number;
|
||||
betaNumber?: number;
|
||||
correctionNumber?: number;
|
||||
date: Date;
|
||||
};
|
||||
|
||||
export type ParsedReleaseTag = {
|
||||
version: string;
|
||||
packageVersion: string;
|
||||
baseVersion: string;
|
||||
channel: "stable" | "beta";
|
||||
correctionNumber?: number;
|
||||
date: Date;
|
||||
@@ -37,7 +40,8 @@ export type ParsedReleaseTag = {
|
||||
const STABLE_VERSION_REGEX = /^(?<year>\d{4})\.(?<month>[1-9]\d?)\.(?<day>[1-9]\d?)$/;
|
||||
const BETA_VERSION_REGEX =
|
||||
/^(?<year>\d{4})\.(?<month>[1-9]\d?)\.(?<day>[1-9]\d?)-beta\.(?<beta>[1-9]\d*)$/;
|
||||
const CORRECTION_TAG_REGEX = /^(?<base>\d{4}\.[1-9]\d?\.[1-9]\d?)-(?<correction>[1-9]\d*)$/;
|
||||
const CORRECTION_VERSION_REGEX =
|
||||
/^(?<year>\d{4})\.(?<month>[1-9]\d?)\.(?<day>[1-9]\d?)-(?<correction>[1-9]\d*)$/;
|
||||
const EXPECTED_REPOSITORY_URL = "https://github.com/openclaw/openclaw";
|
||||
const MAX_CALVER_DISTANCE_DAYS = 2;
|
||||
const REQUIRED_PACKED_PATHS = ["dist/control-ui/index.html"];
|
||||
@@ -92,6 +96,7 @@ function parseDateParts(
|
||||
|
||||
return {
|
||||
version,
|
||||
baseVersion: `${year}.${month}.${day}`,
|
||||
channel,
|
||||
year,
|
||||
month,
|
||||
@@ -117,6 +122,20 @@ export function parseReleaseVersion(version: string): ParsedReleaseVersion | nul
|
||||
return parseDateParts(trimmed, betaMatch.groups, "beta");
|
||||
}
|
||||
|
||||
const correctionMatch = CORRECTION_VERSION_REGEX.exec(trimmed);
|
||||
if (correctionMatch?.groups) {
|
||||
const parsedCorrection = parseDateParts(trimmed, correctionMatch.groups, "stable");
|
||||
const correctionNumber = Number.parseInt(correctionMatch.groups.correction ?? "", 10);
|
||||
if (parsedCorrection === null || !Number.isInteger(correctionNumber) || correctionNumber < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...parsedCorrection,
|
||||
correctionNumber,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -131,36 +150,14 @@ export function parseReleaseTagVersion(version: string): ParsedReleaseTag | null
|
||||
return {
|
||||
version: trimmed,
|
||||
packageVersion: parsedVersion.version,
|
||||
baseVersion: parsedVersion.baseVersion,
|
||||
channel: parsedVersion.channel,
|
||||
date: parsedVersion.date,
|
||||
correctionNumber: undefined,
|
||||
correctionNumber: parsedVersion.correctionNumber,
|
||||
};
|
||||
}
|
||||
|
||||
const correctionMatch = CORRECTION_TAG_REGEX.exec(trimmed);
|
||||
if (!correctionMatch?.groups) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const baseVersion = correctionMatch.groups.base ?? "";
|
||||
const parsedBaseVersion = parseReleaseVersion(baseVersion);
|
||||
const correctionNumber = Number.parseInt(correctionMatch.groups.correction ?? "", 10);
|
||||
if (
|
||||
parsedBaseVersion === null ||
|
||||
parsedBaseVersion.channel !== "stable" ||
|
||||
!Number.isInteger(correctionNumber) ||
|
||||
correctionNumber < 1
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
version: trimmed,
|
||||
packageVersion: parsedBaseVersion.version,
|
||||
channel: "stable",
|
||||
correctionNumber,
|
||||
date: parsedBaseVersion.date,
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
function startOfUtcDay(date: Date): number {
|
||||
@@ -227,7 +224,7 @@ export function collectReleaseTagErrors(params: {
|
||||
const parsedVersion = parseReleaseVersion(packageVersion);
|
||||
if (parsedVersion === null) {
|
||||
errors.push(
|
||||
`package.json version must match YYYY.M.D or YYYY.M.D-beta.N; found "${packageVersion || "<missing>"}".`,
|
||||
`package.json version must match YYYY.M.D, YYYY.M.D-N, or YYYY.M.D-beta.N; found "${packageVersion || "<missing>"}".`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -244,17 +241,24 @@ export function collectReleaseTagErrors(params: {
|
||||
}
|
||||
|
||||
const expectedTag = packageVersion ? `v${packageVersion}` : "<missing>";
|
||||
const expectedCorrectionTag = parsedVersion?.channel === "stable" ? `${expectedTag}-N` : null;
|
||||
const matchesExpectedTag =
|
||||
parsedTag !== null &&
|
||||
parsedVersion !== null &&
|
||||
parsedTag.packageVersion === parsedVersion.version &&
|
||||
parsedTag.channel === parsedVersion.channel;
|
||||
parsedTag.channel === parsedVersion.channel &&
|
||||
(parsedTag.packageVersion === parsedVersion.version ||
|
||||
(parsedVersion.channel === "stable" &&
|
||||
parsedVersion.correctionNumber === undefined &&
|
||||
parsedTag.correctionNumber !== undefined &&
|
||||
parsedTag.baseVersion === parsedVersion.baseVersion));
|
||||
if (!matchesExpectedTag) {
|
||||
errors.push(
|
||||
`Release tag ${releaseTag || "<missing>"} does not match package.json version ${
|
||||
packageVersion || "<missing>"
|
||||
}; expected ${expectedCorrectionTag ? `${expectedTag} or ${expectedCorrectionTag}` : expectedTag}.`,
|
||||
}; expected ${
|
||||
parsedVersion?.channel === "stable" && parsedVersion.correctionNumber === undefined
|
||||
? `${expectedTag} or ${expectedTag}-N`
|
||||
: expectedTag
|
||||
}.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user