fix(docker): prune external plugin dist (#77547)

This commit is contained in:
Vincent Koc
2026-05-04 15:11:14 -07:00
committed by GitHub
parent 8ee08b2b77
commit 7e229f0d3d
6 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
export function parseDockerPluginKeepList(value: unknown): Set<string>;
export function pruneDockerPluginDist(params?: {
cwd?: string;
repoRoot?: string;
env?: NodeJS.ProcessEnv;
}): string[];

View File

@@ -0,0 +1,52 @@
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { collectRootPackageExcludedExtensionDirs } from "./lib/bundled-plugin-build-entries.mjs";
import { removePathIfExists } from "./runtime-postbuild-shared.mjs";
function parsePluginList(value) {
if (typeof value !== "string") {
return new Set();
}
return new Set(
value
.split(/[\s,]+/u)
.map((entry) => entry.trim())
.filter(Boolean),
);
}
export function parseDockerPluginKeepList(value) {
return parsePluginList(value);
}
export function pruneDockerPluginDist(params = {}) {
const repoRoot = params.cwd ?? params.repoRoot ?? process.cwd();
const env = params.env ?? process.env;
const keepPluginIds = parseDockerPluginKeepList(env.OPENCLAW_EXTENSIONS);
const excludedPluginIds = collectRootPackageExcludedExtensionDirs({ cwd: repoRoot });
const removed = [];
for (const pluginId of [...excludedPluginIds].toSorted((left, right) =>
left.localeCompare(right),
)) {
if (keepPluginIds.has(pluginId)) {
continue;
}
for (const root of ["dist", "dist-runtime"]) {
const pluginDistDir = path.join(repoRoot, root, "extensions", pluginId);
if (!fs.existsSync(pluginDistDir)) {
continue;
}
removePathIfExists(pluginDistDir);
removed.push(path.relative(repoRoot, pluginDistDir).replaceAll("\\", "/"));
}
}
return removed;
}
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
pruneDockerPluginDist();
}