build: keep runtime dep stamps out of dist

This commit is contained in:
Peter Steinberger
2026-04-23 06:50:00 +01:00
parent bb55e23c67
commit acb8fe986d
7 changed files with 136 additions and 73 deletions

View File

@@ -457,6 +457,8 @@ export function collectForbiddenPackPaths(paths: Iterable<string>): string[] {
.filter(
(path) =>
forbiddenPrefixes.some((prefix) => path.startsWith(prefix)) ||
/(^|\/)\.openclaw-runtime-deps-[^/]+(\/|$)/u.test(path) ||
path.endsWith("/.openclaw-runtime-deps-stamp.json") ||
path.includes("node_modules/"),
)
.toSorted((left, right) => left.localeCompare(right));

View File

@@ -852,10 +852,19 @@ function runNpmInstall(params) {
throw new Error(output || "npm install failed");
}
function resolveRuntimeDepsStampPath(pluginDir) {
function resolveLegacyRuntimeDepsStampPath(pluginDir) {
return path.join(pluginDir, ".openclaw-runtime-deps-stamp.json");
}
function resolveRuntimeDepsStampPath(repoRoot, pluginId) {
return path.join(
repoRoot,
".artifacts",
"bundled-runtime-deps-stamps",
`${sanitizeTempPrefixSegment(pluginId)}.json`,
);
}
function createRuntimeDepsFingerprint(packageJson, pruneConfig, params = {}) {
const repoRoot = params.repoRoot;
const lockfilePath =
@@ -892,6 +901,17 @@ function readRuntimeDepsStamp(stampPath) {
}
}
function removeStaleRuntimeDepsTempDirs(pluginDir) {
if (!fs.existsSync(pluginDir)) {
return;
}
for (const entry of fs.readdirSync(pluginDir, { withFileTypes: true })) {
if (entry.name.startsWith(".openclaw-runtime-deps-")) {
removePathIfExists(path.join(pluginDir, entry.name));
}
}
}
function stageInstalledRootRuntimeDeps(params) {
const {
directDependencyPackageRoot = null,
@@ -900,6 +920,7 @@ function stageInstalledRootRuntimeDeps(params) {
pluginDir,
pruneConfig,
repoRoot,
stampPath,
} = params;
const dependencySpecs = {
...packageJson.dependencies,
@@ -931,7 +952,6 @@ function stageInstalledRootRuntimeDeps(params) {
}
const rootsToCopy = selectRuntimeDependencyRootsToCopy(resolution);
const nodeModulesDir = path.join(pluginDir, "node_modules");
const stampPath = resolveRuntimeDepsStampPath(pluginDir);
if (rootsToCopy.length === 0) {
assertPathIsNotSymlink(nodeModulesDir, "remove runtime deps");
removePathIfExists(nodeModulesDir);
@@ -1030,9 +1050,9 @@ function installPluginRuntimeDeps(params) {
pluginId,
pruneConfig,
repoRoot,
stampPath,
} = params;
const nodeModulesDir = path.join(pluginDir, "node_modules");
const stampPath = resolveRuntimeDepsStampPath(pluginDir);
const tempInstallDir = makePluginOwnedTempDir(pluginDir, "install");
const pinnedGroups = resolvePinnedRuntimeDependencyGroups(packageJson, {
directDependencyPackageRoot,
@@ -1088,7 +1108,10 @@ export function stageBundledPluginRuntimeDeps(params = {}) {
: null;
const packageJson = sanitizeBundledManifestForRuntimeInstall(pluginDir);
const nodeModulesDir = path.join(pluginDir, "node_modules");
const stampPath = resolveRuntimeDepsStampPath(pluginDir);
const stampPath = resolveRuntimeDepsStampPath(repoRoot, pluginId);
const legacyStampPath = resolveLegacyRuntimeDepsStampPath(pluginDir);
removePathIfExists(legacyStampPath);
removeStaleRuntimeDepsTempDirs(pluginDir);
if (!hasRuntimeDeps(packageJson) || !shouldStageRuntimeDeps(packageJson)) {
removePathIfExists(nodeModulesDir);
removePathIfExists(stampPath);
@@ -1115,6 +1138,7 @@ export function stageBundledPluginRuntimeDeps(params = {}) {
pluginDir,
pruneConfig,
repoRoot,
stampPath,
})
) {
continue;
@@ -1131,6 +1155,7 @@ export function stageBundledPluginRuntimeDeps(params = {}) {
pluginId,
pruneConfig,
repoRoot,
stampPath,
},
});
} catch (error) {