mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:00:42 +00:00
fix(docker): prune external plugin dist (#77547)
This commit is contained in:
6
scripts/prune-docker-plugin-dist.d.mts
Normal file
6
scripts/prune-docker-plugin-dist.d.mts
Normal file
@@ -0,0 +1,6 @@
|
||||
export function parseDockerPluginKeepList(value: unknown): Set<string>;
|
||||
export function pruneDockerPluginDist(params?: {
|
||||
cwd?: string;
|
||||
repoRoot?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): string[];
|
||||
52
scripts/prune-docker-plugin-dist.mjs
Normal file
52
scripts/prune-docker-plugin-dist.mjs
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user