mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
refactor: simplify plugin dependency handling
Simplify plugin installation and runtime loading around package-manager-owned dependencies, with Jiti reserved for local/TS fallback paths. Also scans npm plugin install roots so hoisted transitive dependencies are covered by dependency denylist and node_modules symlink checks.
This commit is contained in:
committed by
GitHub
parent
2e8e9cd6ca
commit
ed8f50f240
@@ -18,6 +18,3 @@ export function listBundledPluginBuildEntries(
|
||||
params?: BundledPluginBuildEntryParams,
|
||||
): Record<string, string>;
|
||||
export function listBundledPluginPackArtifacts(params?: BundledPluginBuildEntryParams): string[];
|
||||
export function listBundledPluginRuntimeDependencies(
|
||||
params?: BundledPluginBuildEntryParams,
|
||||
): string[];
|
||||
|
||||
@@ -47,10 +47,6 @@ function collectPluginSourceEntries(packageJson) {
|
||||
return packageEntries.length > 0 ? packageEntries : ["./index.ts"];
|
||||
}
|
||||
|
||||
function shouldStageBundledPluginRuntimeDependencies(packageJson) {
|
||||
return packageJson?.openclaw?.bundle?.stageRuntimeDependencies === true;
|
||||
}
|
||||
|
||||
function collectTopLevelPublicSurfaceEntries(pluginDir) {
|
||||
if (!fs.existsSync(pluginDir)) {
|
||||
return [];
|
||||
@@ -166,23 +162,3 @@ export function listBundledPluginPackArtifacts(params = {}) {
|
||||
|
||||
return [...artifacts].toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
export function listBundledPluginRuntimeDependencies(params = {}) {
|
||||
const runtimeDependencies = new Set();
|
||||
|
||||
for (const { packageJson } of collectBundledPluginBuildEntries(params)) {
|
||||
if (!shouldStageBundledPluginRuntimeDependencies(packageJson)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const dependencyName of Object.keys(packageJson?.dependencies ?? {})) {
|
||||
runtimeDependencies.add(dependencyName);
|
||||
}
|
||||
|
||||
for (const dependencyName of Object.keys(packageJson?.optionalDependencies ?? {})) {
|
||||
runtimeDependencies.add(dependencyName);
|
||||
}
|
||||
}
|
||||
|
||||
return [...runtimeDependencies].toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const JS_EXTENSIONS = new Set([".cjs", ".js", ".mjs"]);
|
||||
export function collectRuntimeDependencySpecs(packageJson = {}) {
|
||||
return new Map(
|
||||
[
|
||||
@@ -28,39 +27,22 @@ export function packageNameFromSpecifier(specifier) {
|
||||
return first.startsWith("@") && second ? `${first}/${second}` : first;
|
||||
}
|
||||
|
||||
function readJson(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
function collectPackageJsonPaths(rootDir) {
|
||||
if (!fs.existsSync(rootDir)) {
|
||||
return [];
|
||||
}
|
||||
return fs
|
||||
.readdirSync(rootDir, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => path.join(rootDir, entry.name, "package.json"))
|
||||
.filter((packageJsonPath) => fs.existsSync(packageJsonPath))
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function usesStagedRuntimeDependencies(packageJson) {
|
||||
return packageJson?.openclaw?.bundle?.stageRuntimeDependencies === true;
|
||||
}
|
||||
|
||||
function dependencySentinelPath(packageRoot, dependencyName) {
|
||||
return path.join(packageRoot, "node_modules", ...dependencyName.split("/"), "package.json");
|
||||
}
|
||||
|
||||
function pluginIdFromPackageJsonPath(packageJsonPath) {
|
||||
return path.basename(path.dirname(packageJsonPath));
|
||||
}
|
||||
|
||||
export function collectBundledPluginRuntimeDependencySpecs(bundledPluginsDir) {
|
||||
const specs = new Map();
|
||||
|
||||
for (const packageJsonPath of collectPackageJsonPaths(bundledPluginsDir)) {
|
||||
const packageJson = readJson(packageJsonPath);
|
||||
if (!fs.existsSync(bundledPluginsDir)) {
|
||||
return specs;
|
||||
}
|
||||
|
||||
const packageJsonPaths = fs
|
||||
.readdirSync(bundledPluginsDir, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => path.join(bundledPluginsDir, entry.name, "package.json"))
|
||||
.filter((packageJsonPath) => fs.existsSync(packageJsonPath))
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
|
||||
for (const packageJsonPath of packageJsonPaths) {
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
||||
const pluginId = path.basename(path.dirname(packageJsonPath));
|
||||
for (const [name, spec] of collectRuntimeDependencySpecs(packageJson)) {
|
||||
const existing = specs.get(name);
|
||||
@@ -78,178 +60,3 @@ export function collectBundledPluginRuntimeDependencySpecs(bundledPluginsDir) {
|
||||
|
||||
return specs;
|
||||
}
|
||||
|
||||
export function collectBuiltBundledPluginStagedRuntimeDependencyErrors(params) {
|
||||
const errors = [];
|
||||
|
||||
for (const packageJsonPath of collectPackageJsonPaths(params.bundledPluginsDir)) {
|
||||
const packageJson = readJson(packageJsonPath);
|
||||
if (!usesStagedRuntimeDependencies(packageJson)) {
|
||||
continue;
|
||||
}
|
||||
const pluginId = pluginIdFromPackageJsonPath(packageJsonPath);
|
||||
const pluginRoot = path.dirname(packageJsonPath);
|
||||
|
||||
for (const [dependencyName, spec] of collectRuntimeDependencySpecs(packageJson)) {
|
||||
if (!fs.existsSync(dependencySentinelPath(pluginRoot, dependencyName))) {
|
||||
const specText = String(spec);
|
||||
errors.push(
|
||||
`built bundled plugin '${pluginId}' is missing staged runtime dependency '${dependencyName}: ${specText}' under dist/extensions/${pluginId}/node_modules.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function walkJavaScriptFiles(rootDir) {
|
||||
const files = [];
|
||||
if (!fs.existsSync(rootDir)) {
|
||||
return files;
|
||||
}
|
||||
const queue = [rootDir];
|
||||
while (queue.length > 0) {
|
||||
const current = queue.shift();
|
||||
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
||||
const fullPath = path.join(current, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.name === "node_modules") {
|
||||
continue;
|
||||
}
|
||||
queue.push(fullPath);
|
||||
continue;
|
||||
}
|
||||
if (entry.isFile() && JS_EXTENSIONS.has(path.extname(entry.name))) {
|
||||
files.push(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return files.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function extractModuleSpecifiers(source) {
|
||||
const specifiers = new Set();
|
||||
const patterns = [
|
||||
/\bfrom\s*["']([^"']+)["']/g,
|
||||
/\bimport\s*["']([^"']+)["']/g,
|
||||
/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g,
|
||||
/\brequire\s*\(\s*["']([^"']+)["']\s*\)/g,
|
||||
];
|
||||
for (const pattern of patterns) {
|
||||
for (const match of source.matchAll(pattern)) {
|
||||
if (match[1]) {
|
||||
specifiers.add(match[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return specifiers;
|
||||
}
|
||||
|
||||
function isPluginOwnedDistImporter(relativePath, source, pluginIds) {
|
||||
return pluginIds.some(
|
||||
(pluginId) =>
|
||||
relativePath.startsWith(`extensions/${pluginId}/`) ||
|
||||
source.includes(`//#region extensions/${pluginId}/`),
|
||||
);
|
||||
}
|
||||
|
||||
export function collectRootDistBundledRuntimeMirrors(params) {
|
||||
const distDir = params.distDir;
|
||||
const bundledSpecs = params.bundledRuntimeDependencySpecs;
|
||||
const mirrors = new Map();
|
||||
|
||||
for (const filePath of walkJavaScriptFiles(distDir)) {
|
||||
const source = fs.readFileSync(filePath, "utf8");
|
||||
const relativePath = path.relative(distDir, filePath).replaceAll(path.sep, "/");
|
||||
for (const specifier of extractModuleSpecifiers(source)) {
|
||||
const dependencyName = packageNameFromSpecifier(specifier);
|
||||
if (!dependencyName || !bundledSpecs.has(dependencyName)) {
|
||||
continue;
|
||||
}
|
||||
const bundledSpec = bundledSpecs.get(dependencyName);
|
||||
if (isPluginOwnedDistImporter(relativePath, source, bundledSpec.pluginIds)) {
|
||||
continue;
|
||||
}
|
||||
const existing = mirrors.get(dependencyName);
|
||||
if (existing) {
|
||||
existing.importers.add(relativePath);
|
||||
continue;
|
||||
}
|
||||
mirrors.set(dependencyName, {
|
||||
importers: new Set([relativePath]),
|
||||
pluginIds: bundledSpec.pluginIds,
|
||||
spec: bundledSpec.spec,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return mirrors;
|
||||
}
|
||||
|
||||
export function collectBundledPluginRootRuntimeMirrorErrors(params) {
|
||||
const errors = [];
|
||||
const declaredRootRuntimeDeps = collectRuntimeDependencySpecs(params.rootPackageJson);
|
||||
const declaredMirrorDeps =
|
||||
params.rootPackageJson?.openclaw?.bundle?.mirroredRootRuntimeDependencies ?? [];
|
||||
const declaredMirrorDepNames = new Set(
|
||||
Array.isArray(declaredMirrorDeps)
|
||||
? declaredMirrorDeps.filter((dependencyName) => typeof dependencyName === "string")
|
||||
: [],
|
||||
);
|
||||
|
||||
for (const [dependencyName, record] of params.bundledRuntimeDependencySpecs) {
|
||||
for (const conflict of record.conflicts) {
|
||||
errors.push(
|
||||
`bundled runtime dependency '${dependencyName}' has conflicting plugin specs: ${record.pluginIds.join(", ")} use '${record.spec}', ${conflict.pluginId} uses '${conflict.spec}'.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [dependencyName, record] of params.requiredRootMirrors) {
|
||||
if (declaredRootRuntimeDeps.has(dependencyName)) {
|
||||
if (!declaredMirrorDepNames.has(dependencyName)) {
|
||||
const importerList = Array.from(record.importers)
|
||||
.toSorted((left, right) => left.localeCompare(right))
|
||||
.join(", ");
|
||||
errors.push(
|
||||
`installed package root mirror '${dependencyName}' for dist importers: ${importerList} is missing from package.json openclaw.bundle.mirroredRootRuntimeDependencies. Add it there so packaged runtime installs the mirrored dependency, or keep imports under dist/extensions/${record.pluginIds[0]}/.`,
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const importerList = Array.from(record.importers)
|
||||
.toSorted((left, right) => left.localeCompare(right))
|
||||
.join(", ");
|
||||
errors.push(
|
||||
`installed package root is missing mirrored bundled runtime dependency '${dependencyName}' for dist importers: ${importerList}. Add it to package.json dependencies/optionalDependencies or keep imports under dist/extensions/${record.pluginIds[0]}/.`,
|
||||
);
|
||||
}
|
||||
|
||||
return errors.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
export function collectDeclaredRootRuntimeDependencyMetadataErrors(rootPackageJson) {
|
||||
const declaredRootRuntimeDeps = collectRuntimeDependencySpecs(rootPackageJson);
|
||||
const declaredMirrorDeps =
|
||||
rootPackageJson?.openclaw?.bundle?.mirroredRootRuntimeDependencies ?? [];
|
||||
if (!Array.isArray(declaredMirrorDeps)) {
|
||||
return ["package.json openclaw.bundle.mirroredRootRuntimeDependencies must be an array."];
|
||||
}
|
||||
|
||||
const errors = [];
|
||||
for (const dependencyName of declaredMirrorDeps) {
|
||||
if (typeof dependencyName !== "string" || dependencyName.trim().length === 0) {
|
||||
errors.push(
|
||||
"package.json openclaw.bundle.mirroredRootRuntimeDependencies entries must be non-empty strings.",
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (!declaredRootRuntimeDeps.has(dependencyName)) {
|
||||
errors.push(
|
||||
`package.json openclaw.bundle.mirroredRootRuntimeDependencies declares '${dependencyName}' but package.json dependencies/optionalDependencies do not include it.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return errors.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const NPM_CONFIG_KEYS_TO_RESET = new Set([
|
||||
"npm_config_global",
|
||||
"npm_config_ignore_scripts",
|
||||
"npm_config_include_workspace_root",
|
||||
"npm_config_location",
|
||||
"npm_config_prefix",
|
||||
"npm_config_workspace",
|
||||
"npm_config_workspaces",
|
||||
]);
|
||||
|
||||
export function createNestedNpmInstallEnv(env = process.env) {
|
||||
const nextEnv = { ...env };
|
||||
for (const key of Object.keys(nextEnv)) {
|
||||
if (NPM_CONFIG_KEYS_TO_RESET.has(key.toLowerCase())) {
|
||||
delete nextEnv[key];
|
||||
}
|
||||
}
|
||||
return nextEnv;
|
||||
}
|
||||
|
||||
export function createBundledRuntimeDependencyInstallEnv(env = process.env, options = {}) {
|
||||
const nextEnv = {
|
||||
...createNestedNpmInstallEnv(env),
|
||||
npm_config_dry_run: "false",
|
||||
npm_config_fetch_retries: env.npm_config_fetch_retries ?? "5",
|
||||
npm_config_fetch_retry_maxtimeout: env.npm_config_fetch_retry_maxtimeout ?? "120000",
|
||||
npm_config_fetch_retry_mintimeout: env.npm_config_fetch_retry_mintimeout ?? "10000",
|
||||
npm_config_fetch_timeout: env.npm_config_fetch_timeout ?? "300000",
|
||||
npm_config_ignore_scripts: "true",
|
||||
npm_config_legacy_peer_deps: "true",
|
||||
npm_config_package_lock: "false",
|
||||
npm_config_save: "false",
|
||||
npm_config_workspaces: "false",
|
||||
};
|
||||
if (options.ci) {
|
||||
nextEnv.CI = "1";
|
||||
}
|
||||
if (options.quiet) {
|
||||
Object.assign(nextEnv, {
|
||||
npm_config_audit: "false",
|
||||
npm_config_fund: "false",
|
||||
npm_config_loglevel: "error",
|
||||
npm_config_progress: "false",
|
||||
npm_config_yes: "true",
|
||||
});
|
||||
}
|
||||
return nextEnv;
|
||||
}
|
||||
|
||||
export function createBundledRuntimeDependencyInstallArgs(specs = [], options = {}) {
|
||||
return [
|
||||
"install",
|
||||
...(options.noAudit ? ["--no-audit"] : []),
|
||||
...(options.noFund ? ["--no-fund"] : []),
|
||||
"--ignore-scripts",
|
||||
"--workspaces=false",
|
||||
...(options.silent ? ["--silent"] : []),
|
||||
...specs,
|
||||
];
|
||||
}
|
||||
|
||||
export function runBundledRuntimeDependencyNpmInstall(params) {
|
||||
const runSpawnSync = params.spawnSyncImpl ?? spawnSync;
|
||||
const result = runSpawnSync(params.npmRunner.command, params.npmRunner.args, {
|
||||
cwd: params.cwd,
|
||||
encoding: "utf8",
|
||||
env: params.env ?? params.npmRunner.env ?? process.env,
|
||||
shell: params.npmRunner.shell,
|
||||
stdio: params.stdio ?? "pipe",
|
||||
...(params.timeoutMs ? { timeout: params.timeoutMs } : {}),
|
||||
windowsHide: true,
|
||||
windowsVerbatimArguments: params.npmRunner.windowsVerbatimArguments,
|
||||
});
|
||||
if (result.status === 0) {
|
||||
return;
|
||||
}
|
||||
const output = [result.stderr, result.stdout].filter(Boolean).join("\n").trim();
|
||||
throw new Error(output || "npm install failed");
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import {
|
||||
collectInstalledRuntimeDependencyRoots,
|
||||
dependencyNodeModulesPath,
|
||||
findContainingRealRoot,
|
||||
resolveInstalledDirectDependencyNames,
|
||||
selectRuntimeDependencyRootsToCopy,
|
||||
} from "./bundled-runtime-deps-package-tree.mjs";
|
||||
import { pruneStagedRuntimeDependencyCargo } from "./bundled-runtime-deps-prune.mjs";
|
||||
import {
|
||||
assertPathIsNotSymlink,
|
||||
makePluginOwnedTempDir,
|
||||
removeLegacyBundledRuntimeDepsSymlink,
|
||||
removeOwnedTempPathBestEffort,
|
||||
removePathIfExists,
|
||||
replaceDirAtomically,
|
||||
writeJsonAtomically,
|
||||
} from "./bundled-runtime-deps-stage-state.mjs";
|
||||
|
||||
function copyMaterializedDependencyTree(params) {
|
||||
const { activeRoots, allowedRealRoots, sourcePath, targetPath } = params;
|
||||
const sourceStats = fs.lstatSync(sourcePath);
|
||||
|
||||
if (sourceStats.isSymbolicLink()) {
|
||||
let resolvedPath;
|
||||
try {
|
||||
resolvedPath = fs.realpathSync(sourcePath);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
const containingRoot = findContainingRealRoot(resolvedPath, allowedRealRoots);
|
||||
if (containingRoot === null) {
|
||||
return false;
|
||||
}
|
||||
if (activeRoots.has(containingRoot)) {
|
||||
return true;
|
||||
}
|
||||
const nextActiveRoots = new Set(activeRoots);
|
||||
nextActiveRoots.add(containingRoot);
|
||||
return copyMaterializedDependencyTree({
|
||||
activeRoots: nextActiveRoots,
|
||||
allowedRealRoots,
|
||||
sourcePath: resolvedPath,
|
||||
targetPath,
|
||||
});
|
||||
}
|
||||
|
||||
if (sourceStats.isDirectory()) {
|
||||
fs.mkdirSync(targetPath, { recursive: true });
|
||||
for (const entry of fs
|
||||
.readdirSync(sourcePath, { withFileTypes: true })
|
||||
.toSorted((left, right) => left.name.localeCompare(right.name))) {
|
||||
if (
|
||||
!copyMaterializedDependencyTree({
|
||||
activeRoots,
|
||||
allowedRealRoots,
|
||||
sourcePath: path.join(sourcePath, entry.name),
|
||||
targetPath: path.join(targetPath, entry.name),
|
||||
})
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceStats.isFile()) {
|
||||
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
||||
fs.copyFileSync(sourcePath, targetPath);
|
||||
fs.chmodSync(targetPath, sourceStats.mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function listBundledPluginRuntimeDirs(repoRoot) {
|
||||
const extensionsRoot = path.join(repoRoot, "dist", "extensions");
|
||||
if (!fs.existsSync(extensionsRoot)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return fs
|
||||
.readdirSync(extensionsRoot, { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map((dirent) => path.join(extensionsRoot, dirent.name))
|
||||
.filter((pluginDir) => fs.existsSync(path.join(pluginDir, "package.json")));
|
||||
}
|
||||
|
||||
export function resolveInstalledWorkspacePluginRoot(repoRoot, pluginId) {
|
||||
const currentPluginRoot = path.join(repoRoot, "extensions", pluginId);
|
||||
if (fs.existsSync(path.join(currentPluginRoot, "node_modules"))) {
|
||||
return currentPluginRoot;
|
||||
}
|
||||
|
||||
const nodeModulesDir = path.join(repoRoot, "node_modules");
|
||||
if (!fs.existsSync(nodeModulesDir)) {
|
||||
return currentPluginRoot;
|
||||
}
|
||||
|
||||
let installedWorkspaceRoot;
|
||||
try {
|
||||
installedWorkspaceRoot = path.dirname(fs.realpathSync(nodeModulesDir));
|
||||
} catch {
|
||||
return currentPluginRoot;
|
||||
}
|
||||
|
||||
const installedPluginRoot = path.join(installedWorkspaceRoot, "extensions", pluginId);
|
||||
if (fs.existsSync(path.join(installedPluginRoot, "package.json"))) {
|
||||
return installedPluginRoot;
|
||||
}
|
||||
|
||||
return currentPluginRoot;
|
||||
}
|
||||
|
||||
export function stageInstalledRootRuntimeDeps(params) {
|
||||
const {
|
||||
directDependencyPackageRoot = null,
|
||||
cheapFingerprint,
|
||||
fingerprint,
|
||||
packageJson,
|
||||
pluginDir,
|
||||
pruneConfig,
|
||||
repoRoot,
|
||||
stampPath,
|
||||
} = params;
|
||||
const dependencySpecs = {
|
||||
...packageJson.dependencies,
|
||||
...packageJson.optionalDependencies,
|
||||
};
|
||||
const optionalDependencyNames = new Set(Object.keys(packageJson.optionalDependencies ?? {}));
|
||||
const rootNodeModulesDir = path.join(repoRoot, "node_modules");
|
||||
if (Object.keys(dependencySpecs).length === 0 || !fs.existsSync(rootNodeModulesDir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const directDependencyNames = resolveInstalledDirectDependencyNames(
|
||||
rootNodeModulesDir,
|
||||
dependencySpecs,
|
||||
directDependencyPackageRoot,
|
||||
optionalDependencyNames,
|
||||
);
|
||||
if (directDependencyNames === null) {
|
||||
return false;
|
||||
}
|
||||
const resolution = collectInstalledRuntimeDependencyRoots(
|
||||
rootNodeModulesDir,
|
||||
dependencySpecs,
|
||||
directDependencyPackageRoot,
|
||||
optionalDependencyNames,
|
||||
);
|
||||
if (resolution === null) {
|
||||
return false;
|
||||
}
|
||||
const rootsToCopy = selectRuntimeDependencyRootsToCopy(resolution);
|
||||
const nodeModulesDir = path.join(pluginDir, "node_modules");
|
||||
if (rootsToCopy.length === 0) {
|
||||
removeLegacyBundledRuntimeDepsSymlink(nodeModulesDir, repoRoot);
|
||||
assertPathIsNotSymlink(nodeModulesDir, "remove runtime deps");
|
||||
removePathIfExists(nodeModulesDir);
|
||||
writeJsonAtomically(stampPath, {
|
||||
cheapFingerprint,
|
||||
fingerprint,
|
||||
generatedAt: new Date().toISOString(),
|
||||
});
|
||||
return true;
|
||||
}
|
||||
const allowedRealRoots = rootsToCopy.map((record) => record.realRoot);
|
||||
|
||||
const stagedNodeModulesDir = path.join(
|
||||
makePluginOwnedTempDir(pluginDir, "stage"),
|
||||
"node_modules",
|
||||
);
|
||||
|
||||
try {
|
||||
for (const record of rootsToCopy.toSorted((left, right) =>
|
||||
left.name.localeCompare(right.name),
|
||||
)) {
|
||||
const sourcePath = record.realRoot;
|
||||
const targetPath = dependencyNodeModulesPath(stagedNodeModulesDir, record.name);
|
||||
if (targetPath === null) {
|
||||
return false;
|
||||
}
|
||||
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
||||
const sourceRootReal = findContainingRealRoot(sourcePath, allowedRealRoots);
|
||||
if (
|
||||
sourceRootReal === null ||
|
||||
!copyMaterializedDependencyTree({
|
||||
activeRoots: new Set([sourceRootReal]),
|
||||
allowedRealRoots,
|
||||
sourcePath,
|
||||
targetPath,
|
||||
})
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
pruneStagedRuntimeDependencyCargo(stagedNodeModulesDir, pruneConfig);
|
||||
|
||||
removeLegacyBundledRuntimeDepsSymlink(nodeModulesDir, repoRoot);
|
||||
replaceDirAtomically(nodeModulesDir, stagedNodeModulesDir);
|
||||
writeJsonAtomically(stampPath, {
|
||||
cheapFingerprint,
|
||||
fingerprint,
|
||||
generatedAt: new Date().toISOString(),
|
||||
});
|
||||
return true;
|
||||
} finally {
|
||||
removeOwnedTempPathBestEffort(path.dirname(stagedNodeModulesDir));
|
||||
}
|
||||
}
|
||||
@@ -1,272 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import semverSatisfies from "semver/functions/satisfies.js";
|
||||
|
||||
function readJson(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
function dependencyPathSegments(depName) {
|
||||
if (typeof depName !== "string" || depName.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const segments = depName.split("/");
|
||||
if (depName.startsWith("@")) {
|
||||
if (segments.length !== 2) {
|
||||
return null;
|
||||
}
|
||||
const [scope, name] = segments;
|
||||
if (
|
||||
!/^@[A-Za-z0-9._-]+$/.test(scope) ||
|
||||
!/^[A-Za-z0-9._-]+$/.test(name) ||
|
||||
scope === "@." ||
|
||||
scope === "@.."
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return [scope, name];
|
||||
}
|
||||
if (segments.length !== 1 || !/^[A-Za-z0-9._-]+$/.test(segments[0])) {
|
||||
return null;
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function dependencyNodeModulesPath(nodeModulesDir, depName) {
|
||||
const segments = dependencyPathSegments(depName);
|
||||
return segments ? path.join(nodeModulesDir, ...segments) : null;
|
||||
}
|
||||
|
||||
function dependencyVersionSatisfied(spec, installedVersion) {
|
||||
return semverSatisfies(installedVersion, spec, { includePrerelease: false });
|
||||
}
|
||||
|
||||
export function readInstalledDependencyVersionFromRoot(depRoot) {
|
||||
const packageJsonPath = path.join(depRoot, "package.json");
|
||||
if (!fs.existsSync(packageJsonPath)) {
|
||||
return null;
|
||||
}
|
||||
const version = readJson(packageJsonPath).version;
|
||||
return typeof version === "string" ? version : null;
|
||||
}
|
||||
|
||||
export function resolveInstalledDependencyRoot(params) {
|
||||
const candidates = [];
|
||||
if (params.parentPackageRoot) {
|
||||
const nestedDepRoot = dependencyNodeModulesPath(
|
||||
path.join(params.parentPackageRoot, "node_modules"),
|
||||
params.depName,
|
||||
);
|
||||
if (nestedDepRoot !== null) {
|
||||
candidates.push(nestedDepRoot);
|
||||
}
|
||||
}
|
||||
const rootDepRoot = dependencyNodeModulesPath(params.rootNodeModulesDir, params.depName);
|
||||
if (rootDepRoot !== null) {
|
||||
candidates.push(rootDepRoot);
|
||||
}
|
||||
|
||||
for (const depRoot of candidates) {
|
||||
const installedVersion = readInstalledDependencyVersionFromRoot(depRoot);
|
||||
if (installedVersion === null) {
|
||||
continue;
|
||||
}
|
||||
if (params.enforceSpec === false || dependencyVersionSatisfied(params.spec, installedVersion)) {
|
||||
return depRoot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function collectInstalledRuntimeDependencyRoots(
|
||||
rootNodeModulesDir,
|
||||
dependencySpecs,
|
||||
directDependencyPackageRoot = null,
|
||||
optionalDependencyNames = new Set(),
|
||||
) {
|
||||
const packageCache = new Map();
|
||||
const directRoots = [];
|
||||
const allRoots = [];
|
||||
const queue = Object.entries(dependencySpecs).map(([depName, spec]) => ({
|
||||
depName,
|
||||
optional: optionalDependencyNames.has(depName),
|
||||
spec,
|
||||
parentPackageRoot: directDependencyPackageRoot,
|
||||
direct: true,
|
||||
}));
|
||||
const seen = new Set();
|
||||
|
||||
while (queue.length > 0) {
|
||||
const current = queue.shift();
|
||||
const depRoot = resolveInstalledDependencyRoot({
|
||||
depName: current.depName,
|
||||
spec: current.spec,
|
||||
enforceSpec: current.direct,
|
||||
parentPackageRoot: current.parentPackageRoot,
|
||||
rootNodeModulesDir,
|
||||
});
|
||||
if (depRoot === null) {
|
||||
if (current.optional) {
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const canonicalDepRoot = fs.realpathSync(depRoot);
|
||||
|
||||
const seenKey = `${current.depName}\0${canonicalDepRoot}`;
|
||||
if (seen.has(seenKey)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(seenKey);
|
||||
|
||||
const record = { name: current.depName, root: depRoot, realRoot: canonicalDepRoot };
|
||||
allRoots.push(record);
|
||||
if (current.direct) {
|
||||
directRoots.push(record);
|
||||
}
|
||||
|
||||
const packageJson =
|
||||
packageCache.get(canonicalDepRoot) ?? readJson(path.join(depRoot, "package.json"));
|
||||
packageCache.set(canonicalDepRoot, packageJson);
|
||||
for (const [childName, childSpec] of Object.entries(packageJson.dependencies ?? {})) {
|
||||
queue.push({
|
||||
depName: childName,
|
||||
optional: false,
|
||||
spec: childSpec,
|
||||
parentPackageRoot: depRoot,
|
||||
direct: false,
|
||||
});
|
||||
}
|
||||
for (const [childName, childSpec] of Object.entries(packageJson.optionalDependencies ?? {})) {
|
||||
queue.push({
|
||||
depName: childName,
|
||||
optional: true,
|
||||
spec: childSpec,
|
||||
parentPackageRoot: depRoot,
|
||||
direct: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { allRoots, directRoots };
|
||||
}
|
||||
|
||||
function pathIsInsideCopiedRoot(candidateRoot, copiedRoot) {
|
||||
return candidateRoot === copiedRoot || candidateRoot.startsWith(`${copiedRoot}${path.sep}`);
|
||||
}
|
||||
|
||||
export function findContainingRealRoot(candidatePath, allowedRealRoots) {
|
||||
return (
|
||||
allowedRealRoots.find((rootPath) => pathIsInsideCopiedRoot(candidatePath, rootPath)) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
export function selectRuntimeDependencyRootsToCopy(resolution) {
|
||||
const rootsToCopy = [];
|
||||
|
||||
for (const record of resolution.directRoots) {
|
||||
rootsToCopy.push(record);
|
||||
}
|
||||
|
||||
for (const record of resolution.allRoots) {
|
||||
if (rootsToCopy.some((entry) => pathIsInsideCopiedRoot(record.realRoot, entry.realRoot))) {
|
||||
continue;
|
||||
}
|
||||
rootsToCopy.push(record);
|
||||
}
|
||||
|
||||
return rootsToCopy;
|
||||
}
|
||||
|
||||
export function resolveInstalledDirectDependencyNames(
|
||||
rootNodeModulesDir,
|
||||
dependencySpecs,
|
||||
directDependencyPackageRoot = null,
|
||||
optionalDependencyNames = new Set(),
|
||||
) {
|
||||
const directDependencyNames = [];
|
||||
for (const [depName, spec] of Object.entries(dependencySpecs)) {
|
||||
const depRoot = resolveInstalledDependencyRoot({
|
||||
depName,
|
||||
spec,
|
||||
parentPackageRoot: directDependencyPackageRoot,
|
||||
rootNodeModulesDir,
|
||||
});
|
||||
if (depRoot === null) {
|
||||
if (optionalDependencyNames.has(depName)) {
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const installedVersion = readInstalledDependencyVersionFromRoot(depRoot);
|
||||
if (installedVersion === null || !dependencyVersionSatisfied(spec, installedVersion)) {
|
||||
return null;
|
||||
}
|
||||
directDependencyNames.push(depName);
|
||||
}
|
||||
return directDependencyNames;
|
||||
}
|
||||
|
||||
function appendDirectoryFingerprint(hash, rootDir, currentDir = rootDir) {
|
||||
const entries = fs
|
||||
.readdirSync(currentDir, { withFileTypes: true })
|
||||
.toSorted((left, right) => left.name.localeCompare(right.name));
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(currentDir, entry.name);
|
||||
const relativePath = path.relative(rootDir, fullPath).replace(/\\/g, "/");
|
||||
const stats = fs.lstatSync(fullPath);
|
||||
if (stats.isSymbolicLink()) {
|
||||
hash.update(`symlink:${relativePath}->${fs.readlinkSync(fullPath).replace(/\\/g, "/")}\n`);
|
||||
continue;
|
||||
}
|
||||
if (stats.isDirectory()) {
|
||||
hash.update(`dir:${relativePath}\n`);
|
||||
appendDirectoryFingerprint(hash, rootDir, fullPath);
|
||||
continue;
|
||||
}
|
||||
if (!stats.isFile()) {
|
||||
continue;
|
||||
}
|
||||
const stat = fs.statSync(fullPath);
|
||||
hash.update(`file:${relativePath}:${stat.size}\n`);
|
||||
hash.update(fs.readFileSync(fullPath));
|
||||
}
|
||||
}
|
||||
|
||||
function createInstalledRuntimeClosureFingerprint(records) {
|
||||
const hash = createHash("sha256");
|
||||
for (const record of [...records].toSorted(
|
||||
(left, right) =>
|
||||
left.name.localeCompare(right.name) || left.realRoot.localeCompare(right.realRoot),
|
||||
)) {
|
||||
if (!fs.existsSync(record.realRoot)) {
|
||||
return null;
|
||||
}
|
||||
hash.update(`package:${record.name}:${record.realRoot}\n`);
|
||||
appendDirectoryFingerprint(hash, record.realRoot);
|
||||
}
|
||||
return hash.digest("hex");
|
||||
}
|
||||
|
||||
export function resolveInstalledRuntimeClosureFingerprint(params) {
|
||||
const dependencySpecs = {
|
||||
...params.packageJson.dependencies,
|
||||
...params.packageJson.optionalDependencies,
|
||||
};
|
||||
if (Object.keys(dependencySpecs).length === 0 || !fs.existsSync(params.rootNodeModulesDir)) {
|
||||
return null;
|
||||
}
|
||||
const resolution = collectInstalledRuntimeDependencyRoots(
|
||||
params.rootNodeModulesDir,
|
||||
dependencySpecs,
|
||||
params.directDependencyPackageRoot,
|
||||
new Set(Object.keys(params.packageJson.optionalDependencies ?? {})),
|
||||
);
|
||||
if (resolution === null) {
|
||||
return null;
|
||||
}
|
||||
return createInstalledRuntimeClosureFingerprint(selectRuntimeDependencyRootsToCopy(resolution));
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { dependencyNodeModulesPath } from "./bundled-runtime-deps-package-tree.mjs";
|
||||
import { removePathIfExists } from "./bundled-runtime-deps-stage-state.mjs";
|
||||
|
||||
const defaultStagedRuntimeDepGlobalPruneSuffixes = [".d.ts", ".map"];
|
||||
const defaultStagedRuntimeDepGlobalPruneDirectories = [
|
||||
"__snapshots__",
|
||||
"__tests__",
|
||||
"test",
|
||||
"tests",
|
||||
];
|
||||
const defaultStagedRuntimeDepGlobalPruneFilePatterns = [
|
||||
/(?:^|\/)[^/]+\.(?:test|spec)\.(?:[cm]?[jt]sx?)$/u,
|
||||
];
|
||||
const defaultStagedRuntimeDepPruneRules = new Map([
|
||||
["@larksuiteoapi/node-sdk", { paths: ["types"] }],
|
||||
[
|
||||
"@matrix-org/matrix-sdk-crypto-nodejs",
|
||||
{
|
||||
paths: ["index.d.ts", "README.md", "CHANGELOG.md", "RELEASING.md", ".node-version"],
|
||||
},
|
||||
],
|
||||
[
|
||||
"@matrix-org/matrix-sdk-crypto-wasm",
|
||||
{
|
||||
paths: [
|
||||
"index.d.ts",
|
||||
"pkg/matrix_sdk_crypto_wasm.d.ts",
|
||||
"pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts",
|
||||
"README.md",
|
||||
],
|
||||
},
|
||||
],
|
||||
[
|
||||
"matrix-js-sdk",
|
||||
{
|
||||
paths: ["src", "CHANGELOG.md", "CONTRIBUTING.rst", "README.md", "release.sh"],
|
||||
suffixes: [".d.ts"],
|
||||
},
|
||||
],
|
||||
["matrix-widget-api", { paths: ["src"], suffixes: [".d.ts"] }],
|
||||
["oidc-client-ts", { paths: ["README.md"], suffixes: [".d.ts"] }],
|
||||
["music-metadata", { paths: ["README.md"], suffixes: [".d.ts"] }],
|
||||
["@cloudflare/workers-types", { paths: ["."] }],
|
||||
["gifwrap", { paths: ["test"] }],
|
||||
["playwright-core", { paths: ["types"], suffixes: [".d.ts"] }],
|
||||
["@jimp/plugin-blit", { paths: ["src/__image_snapshots__"] }],
|
||||
["@jimp/plugin-blur", { paths: ["src/__image_snapshots__"] }],
|
||||
["@jimp/plugin-color", { paths: ["src/__image_snapshots__"] }],
|
||||
["@jimp/plugin-print", { paths: ["src/__image_snapshots__"] }],
|
||||
["@jimp/plugin-quantize", { paths: ["src/__image_snapshots__"] }],
|
||||
["@jimp/plugin-threshold", { paths: ["src/__image_snapshots__"] }],
|
||||
["tokenjuice", { keepDirectories: ["dist/rules/tests"] }],
|
||||
]);
|
||||
|
||||
export function resolveRuntimeDepPruneConfig(params = {}) {
|
||||
return {
|
||||
globalPruneDirectories:
|
||||
params.stagedRuntimeDepGlobalPruneDirectories ??
|
||||
defaultStagedRuntimeDepGlobalPruneDirectories,
|
||||
globalPruneFilePatterns:
|
||||
params.stagedRuntimeDepGlobalPruneFilePatterns ??
|
||||
defaultStagedRuntimeDepGlobalPruneFilePatterns,
|
||||
globalPruneSuffixes:
|
||||
params.stagedRuntimeDepGlobalPruneSuffixes ?? defaultStagedRuntimeDepGlobalPruneSuffixes,
|
||||
pruneRules: params.stagedRuntimeDepPruneRules ?? defaultStagedRuntimeDepPruneRules,
|
||||
};
|
||||
}
|
||||
|
||||
function walkFiles(rootDir, visitFile) {
|
||||
if (!fs.existsSync(rootDir)) {
|
||||
return;
|
||||
}
|
||||
const queue = [rootDir];
|
||||
for (let index = 0; index < queue.length; index += 1) {
|
||||
const currentDir = queue[index];
|
||||
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
||||
const fullPath = path.join(currentDir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
queue.push(fullPath);
|
||||
continue;
|
||||
}
|
||||
if (entry.isFile()) {
|
||||
visitFile(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pruneDependencyFilesBySuffixes(depRoot, suffixes) {
|
||||
if (!suffixes || suffixes.length === 0 || !fs.existsSync(depRoot)) {
|
||||
return;
|
||||
}
|
||||
walkFiles(depRoot, (fullPath) => {
|
||||
if (suffixes.some((suffix) => fullPath.endsWith(suffix))) {
|
||||
removePathIfExists(fullPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function relativePathSegments(rootDir, fullPath) {
|
||||
return path.relative(rootDir, fullPath).split(path.sep).filter(Boolean);
|
||||
}
|
||||
|
||||
function isNodeModulesPackageRoot(segments, index) {
|
||||
const parent = segments[index - 1];
|
||||
if (parent === "node_modules") {
|
||||
return true;
|
||||
}
|
||||
return parent?.startsWith("@") === true && segments[index - 2] === "node_modules";
|
||||
}
|
||||
|
||||
function pruneDependencyDirectoriesByBasename(depRoot, basenames, keepDirs = new Set()) {
|
||||
if (!basenames || basenames.length === 0 || !fs.existsSync(depRoot)) {
|
||||
return;
|
||||
}
|
||||
const basenameSet = new Set(basenames);
|
||||
const queue = [depRoot];
|
||||
for (let index = 0; index < queue.length; index += 1) {
|
||||
const currentDir = queue[index];
|
||||
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
const fullPath = path.join(currentDir, entry.name);
|
||||
const segments = relativePathSegments(depRoot, fullPath);
|
||||
if (basenameSet.has(entry.name) && !isNodeModulesPackageRoot(segments, segments.length - 1)) {
|
||||
if (keepDirs.has(fullPath)) {
|
||||
queue.push(fullPath);
|
||||
continue;
|
||||
}
|
||||
removePathIfExists(fullPath);
|
||||
continue;
|
||||
}
|
||||
queue.push(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pruneDependencyFilesByPatterns(depRoot, patterns) {
|
||||
if (!patterns || patterns.length === 0 || !fs.existsSync(depRoot)) {
|
||||
return;
|
||||
}
|
||||
walkFiles(depRoot, (fullPath) => {
|
||||
const relativePath = relativePathSegments(depRoot, fullPath).join("/");
|
||||
if (patterns.some((pattern) => pattern.test(relativePath))) {
|
||||
removePathIfExists(fullPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function pruneStagedInstalledDependencyCargo(nodeModulesDir, depName, pruneConfig) {
|
||||
const depRoot = dependencyNodeModulesPath(nodeModulesDir, depName);
|
||||
if (depRoot === null) {
|
||||
return;
|
||||
}
|
||||
const pruneRule = pruneConfig.pruneRules.get(depName);
|
||||
for (const relativePath of pruneRule?.paths ?? []) {
|
||||
removePathIfExists(path.join(depRoot, relativePath));
|
||||
}
|
||||
const keepDirs = new Set(
|
||||
(pruneRule?.keepDirectories ?? []).map((relativePath) => path.resolve(depRoot, relativePath)),
|
||||
);
|
||||
pruneDependencyDirectoriesByBasename(depRoot, pruneConfig.globalPruneDirectories, keepDirs);
|
||||
pruneDependencyFilesByPatterns(depRoot, pruneConfig.globalPruneFilePatterns);
|
||||
pruneDependencyFilesBySuffixes(depRoot, pruneConfig.globalPruneSuffixes);
|
||||
pruneDependencyFilesBySuffixes(depRoot, pruneRule?.suffixes ?? []);
|
||||
}
|
||||
|
||||
function listInstalledDependencyNames(nodeModulesDir) {
|
||||
if (!fs.existsSync(nodeModulesDir)) {
|
||||
return [];
|
||||
}
|
||||
const names = [];
|
||||
for (const entry of fs.readdirSync(nodeModulesDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (entry.name.startsWith("@")) {
|
||||
const scopeDir = path.join(nodeModulesDir, entry.name);
|
||||
for (const scopedEntry of fs.readdirSync(scopeDir, { withFileTypes: true })) {
|
||||
if (scopedEntry.isDirectory()) {
|
||||
names.push(`${entry.name}/${scopedEntry.name}`);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
names.push(entry.name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
export function pruneStagedRuntimeDependencyCargo(nodeModulesDir, pruneConfig) {
|
||||
for (const depName of listInstalledDependencyNames(nodeModulesDir)) {
|
||||
pruneStagedInstalledDependencyCargo(nodeModulesDir, depName, pruneConfig);
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const TRANSIENT_TEMP_REMOVE_ERROR_CODES = new Set(["EBUSY", "ENOTEMPTY", "EPERM"]);
|
||||
const TEMP_REMOVE_RETRY_DELAYS_MS = [10, 25, 50];
|
||||
const TEMP_OWNER_FILE = "owner.json";
|
||||
|
||||
function readJson(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
function writeJson(filePath, value) {
|
||||
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
export function removePathIfExists(targetPath, options = {}) {
|
||||
const retryDelays = options.retryTransient ? TEMP_REMOVE_RETRY_DELAYS_MS : [];
|
||||
for (let attempt = 0; attempt <= retryDelays.length; attempt += 1) {
|
||||
try {
|
||||
fs.rmSync(targetPath, { recursive: true, force: true });
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (!isTransientTempRemoveError(error)) {
|
||||
throw error;
|
||||
}
|
||||
const delay = retryDelays[attempt];
|
||||
if (delay === undefined) {
|
||||
if (options.ignoreTransient) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
sleepSync(delay);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function removeOwnedTempPathBestEffort(targetPath) {
|
||||
return removePathIfExists(targetPath, { retryTransient: true, ignoreTransient: true });
|
||||
}
|
||||
|
||||
function isTransientTempRemoveError(error) {
|
||||
return (
|
||||
!!error &&
|
||||
typeof error === "object" &&
|
||||
typeof error.code === "string" &&
|
||||
TRANSIENT_TEMP_REMOVE_ERROR_CODES.has(error.code)
|
||||
);
|
||||
}
|
||||
|
||||
function sleepSync(ms) {
|
||||
if (!Number.isFinite(ms) || ms <= 0) {
|
||||
return;
|
||||
}
|
||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
||||
}
|
||||
|
||||
function makeTempDir(parentDir, prefix) {
|
||||
return fs.mkdtempSync(path.join(parentDir, prefix));
|
||||
}
|
||||
|
||||
export function writeRuntimeDepsTempOwner(tempDir) {
|
||||
writeJson(path.join(tempDir, TEMP_OWNER_FILE), {
|
||||
pid: process.pid,
|
||||
createdAtMs: Date.now(),
|
||||
});
|
||||
}
|
||||
|
||||
function makeOwnedTempDir(parentDir, prefix) {
|
||||
const tempDir = makeTempDir(parentDir, prefix);
|
||||
writeRuntimeDepsTempOwner(tempDir);
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
export function sanitizeTempPrefixSegment(value) {
|
||||
const normalized = value.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/-+/g, "-");
|
||||
return normalized.length > 0 ? normalized : "plugin";
|
||||
}
|
||||
|
||||
export function makePluginOwnedTempDir(pluginDir, label) {
|
||||
return makeOwnedTempDir(pluginDir, `.openclaw-runtime-deps-${label}-`);
|
||||
}
|
||||
|
||||
export function assertPathIsNotSymlink(targetPath, label) {
|
||||
try {
|
||||
if (fs.lstatSync(targetPath).isSymbolicLink()) {
|
||||
throw new Error(`refusing to ${label} via symlinked path: ${targetPath}`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error?.code === "ENOENT") {
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function isDirectChildPath(parentPath, childPath) {
|
||||
const relativePath = path.relative(parentPath, childPath);
|
||||
return (
|
||||
relativePath.length > 0 &&
|
||||
!relativePath.startsWith("..") &&
|
||||
!path.isAbsolute(relativePath) &&
|
||||
!relativePath.includes(path.sep)
|
||||
);
|
||||
}
|
||||
|
||||
function isLegacyBundledRuntimeDepsNodeModulesPath(targetPath, repoRoot, linkedPath) {
|
||||
const legacyRuntimeDepsRoot = path.resolve(repoRoot, ".local", "bundled-plugin-runtime-deps");
|
||||
const resolvedLinkedPath = path.resolve(path.dirname(targetPath), linkedPath);
|
||||
return (
|
||||
path.basename(resolvedLinkedPath) === "node_modules" &&
|
||||
isDirectChildPath(legacyRuntimeDepsRoot, path.dirname(resolvedLinkedPath))
|
||||
);
|
||||
}
|
||||
|
||||
export function removeLegacyBundledRuntimeDepsSymlink(targetPath, repoRoot) {
|
||||
let stats;
|
||||
try {
|
||||
stats = fs.lstatSync(targetPath);
|
||||
} catch (error) {
|
||||
if (error?.code === "ENOENT") {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
if (!stats.isSymbolicLink()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let linkedPath;
|
||||
try {
|
||||
linkedPath = fs.readlinkSync(targetPath);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (!isLegacyBundledRuntimeDepsNodeModulesPath(targetPath, repoRoot, linkedPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
removePathIfExists(targetPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function replaceDirAtomically(targetPath, sourcePath) {
|
||||
assertPathIsNotSymlink(targetPath, "replace runtime deps");
|
||||
const targetParentDir = path.dirname(targetPath);
|
||||
fs.mkdirSync(targetParentDir, { recursive: true });
|
||||
const backupPath = makeTempDir(
|
||||
targetParentDir,
|
||||
`.openclaw-runtime-deps-backup-${sanitizeTempPrefixSegment(path.basename(targetPath))}-`,
|
||||
);
|
||||
removePathIfExists(backupPath, { retryTransient: true });
|
||||
|
||||
let movedExistingTarget = false;
|
||||
try {
|
||||
if (fs.existsSync(targetPath)) {
|
||||
fs.renameSync(targetPath, backupPath);
|
||||
writeRuntimeDepsTempOwner(backupPath);
|
||||
movedExistingTarget = true;
|
||||
}
|
||||
fs.renameSync(sourcePath, targetPath);
|
||||
removeOwnedTempPathBestEffort(backupPath);
|
||||
} catch (error) {
|
||||
if (movedExistingTarget && !fs.existsSync(targetPath) && fs.existsSync(backupPath)) {
|
||||
fs.renameSync(backupPath, targetPath);
|
||||
removePathIfExists(path.join(targetPath, TEMP_OWNER_FILE));
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function writeJsonAtomically(targetPath, value) {
|
||||
assertPathIsNotSymlink(targetPath, "write runtime deps stamp");
|
||||
const targetParentDir = path.dirname(targetPath);
|
||||
fs.mkdirSync(targetParentDir, { recursive: true });
|
||||
const tempDir = makeOwnedTempDir(
|
||||
targetParentDir,
|
||||
`.openclaw-runtime-deps-stamp-${sanitizeTempPrefixSegment(path.basename(targetPath))}-`,
|
||||
);
|
||||
const tempPath = path.join(tempDir, path.basename(targetPath));
|
||||
try {
|
||||
fs.writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, {
|
||||
encoding: "utf8",
|
||||
flag: "wx",
|
||||
});
|
||||
fs.renameSync(tempPath, targetPath);
|
||||
} finally {
|
||||
removeOwnedTempPathBestEffort(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
function readRuntimeDepsTempOwner(tempDir) {
|
||||
try {
|
||||
const owner = readJson(path.join(tempDir, TEMP_OWNER_FILE));
|
||||
return owner && typeof owner === "object" ? owner : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function isLiveProcess(pid) {
|
||||
if (!Number.isInteger(pid) || pid <= 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return error?.code === "EPERM";
|
||||
}
|
||||
}
|
||||
|
||||
function shouldRemoveRuntimeDepsTempDir(tempDir) {
|
||||
const owner = readRuntimeDepsTempOwner(tempDir);
|
||||
if (!owner || typeof owner.pid !== "number") {
|
||||
return true;
|
||||
}
|
||||
return !isLiveProcess(owner.pid);
|
||||
}
|
||||
|
||||
export function removeStaleRuntimeDepsTempDirs(pluginDir) {
|
||||
if (!fs.existsSync(pluginDir)) {
|
||||
return;
|
||||
}
|
||||
for (const entry of fs.readdirSync(pluginDir, { withFileTypes: true })) {
|
||||
if (entry.name.startsWith(".openclaw-runtime-deps-")) {
|
||||
const targetPath = path.join(pluginDir, entry.name);
|
||||
if (!shouldRemoveRuntimeDepsTempDir(targetPath)) {
|
||||
continue;
|
||||
}
|
||||
removeOwnedTempPathBestEffort(targetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { sanitizeTempPrefixSegment } from "./bundled-runtime-deps-stage-state.mjs";
|
||||
|
||||
const runtimeDepsStagingVersion = 7;
|
||||
|
||||
function readJson(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
function readOptionalUtf8(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
return fs.readFileSync(filePath, "utf8");
|
||||
}
|
||||
|
||||
export function resolveLegacyRuntimeDepsStampPath(pluginDir) {
|
||||
return path.join(pluginDir, ".openclaw-runtime-deps-stamp.json");
|
||||
}
|
||||
|
||||
export function resolveRuntimeDepsStampPath(repoRoot, pluginId) {
|
||||
return path.join(
|
||||
repoRoot,
|
||||
".artifacts",
|
||||
"bundled-runtime-deps-stamps",
|
||||
`${sanitizeTempPrefixSegment(pluginId)}.json`,
|
||||
);
|
||||
}
|
||||
|
||||
export function createRuntimeDepsFingerprint(packageJson, pruneConfig, params = {}) {
|
||||
return createHash("sha256")
|
||||
.update(
|
||||
JSON.stringify({
|
||||
cheapFingerprint: createRuntimeDepsCheapFingerprint(packageJson, pruneConfig, params),
|
||||
rootInstalledRuntimeFingerprint: params.rootInstalledRuntimeFingerprint ?? null,
|
||||
}),
|
||||
)
|
||||
.digest("hex");
|
||||
}
|
||||
|
||||
export function createRuntimeDepsCheapFingerprint(packageJson, pruneConfig, params = {}) {
|
||||
const repoRoot = params.repoRoot;
|
||||
const lockfilePath =
|
||||
typeof repoRoot === "string" && repoRoot.length > 0
|
||||
? path.join(repoRoot, "pnpm-lock.yaml")
|
||||
: null;
|
||||
const rootLockfile = lockfilePath ? readOptionalUtf8(lockfilePath) : null;
|
||||
return createHash("sha256")
|
||||
.update(
|
||||
JSON.stringify({
|
||||
globalPruneDirectories: pruneConfig.globalPruneDirectories,
|
||||
globalPruneFilePatterns: pruneConfig.globalPruneFilePatterns.map((pattern) =>
|
||||
pattern.toString(),
|
||||
),
|
||||
globalPruneSuffixes: pruneConfig.globalPruneSuffixes,
|
||||
packageJson,
|
||||
pruneRules: [...pruneConfig.pruneRules.entries()],
|
||||
rootLockfile,
|
||||
version: runtimeDepsStagingVersion,
|
||||
}),
|
||||
)
|
||||
.digest("hex");
|
||||
}
|
||||
|
||||
export function readRuntimeDepsStamp(stampPath) {
|
||||
if (!fs.existsSync(stampPath)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return readJson(stampPath);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,11 @@
|
||||
"class": "default-runtime-initially",
|
||||
"risk": ["provider-sdk", "network"]
|
||||
},
|
||||
"playwright-core": {
|
||||
"owner": "core:browser",
|
||||
"class": "core-runtime",
|
||||
"risk": ["browser-automation", "cdp"]
|
||||
},
|
||||
"pdfjs-dist": {
|
||||
"owner": "plugin:document-extract",
|
||||
"class": "plugin-runtime",
|
||||
@@ -158,11 +163,6 @@
|
||||
"class": "default-runtime-initially",
|
||||
"risk": ["terminal-rendering", "png-encoding"]
|
||||
},
|
||||
"semver": {
|
||||
"owner": "core:package-versioning",
|
||||
"class": "core-runtime",
|
||||
"risk": ["version-parser"]
|
||||
},
|
||||
"sharp": {
|
||||
"owner": "plugin:media-understanding-core",
|
||||
"class": "plugin-runtime",
|
||||
|
||||
@@ -36,7 +36,6 @@ export function parseLaneSelection(raw) {
|
||||
return [];
|
||||
}
|
||||
const laneAliases = new Map([
|
||||
["bundled-channel-deps", ["bundled-channel-deps-compat"]],
|
||||
["install-e2e", ["install-e2e-openai", "install-e2e-anthropic"]],
|
||||
[
|
||||
"bundled-plugin-install-uninstall",
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Keep lane names, commands, image kind, timeout, resources, and release chunks
|
||||
// here. Planning and execution live in separate modules.
|
||||
|
||||
const BUNDLED_UPDATE_NO_OUTPUT_TIMEOUT_MS = 4 * 60 * 1000;
|
||||
const BUNDLED_UPDATE_TIMEOUT_MS = 6 * 60 * 1000;
|
||||
export const DEFAULT_LIVE_RETRIES = 1;
|
||||
const LIVE_ACP_TIMEOUT_MS = 20 * 60 * 1000;
|
||||
const LIVE_CLI_TIMEOUT_MS = 20 * 60 * 1000;
|
||||
@@ -21,9 +19,6 @@ export const LIVE_RETRY_PATTERNS = [
|
||||
/ECONNRESET|ETIMEDOUT|ENOTFOUND/i,
|
||||
];
|
||||
|
||||
const bundledChannelLaneCommand =
|
||||
"OPENCLAW_SKIP_DOCKER_BUILD=1 OPENCLAW_BUNDLED_CHANNEL_UPDATE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_ROOT_OWNED_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_SETUP_ENTRY_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_LOAD_FAILURE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_DISABLED_CONFIG_SCENARIO=0 pnpm test:docker:bundled-channel-deps";
|
||||
|
||||
function liveDockerScriptCommand(script, envPrefix = "") {
|
||||
const prefix = envPrefix ? `${envPrefix} ` : "";
|
||||
return `${prefix}OPENCLAW_SKIP_DOCKER_BUILD=1 bash -c 'harness="\${OPENCLAW_DOCKER_E2E_TRUSTED_HARNESS_DIR:-}"; if [ -z "$harness" ]; then if [ -d .release-harness/scripts ]; then harness=.release-harness; else harness=.; fi; fi; OPENCLAW_LIVE_DOCKER_REPO_ROOT="\${OPENCLAW_DOCKER_E2E_REPO_ROOT:-$PWD}" bash "$harness/scripts/${script}"'`;
|
||||
@@ -108,72 +103,6 @@ function serviceLane(name, command, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
function bundledChannelScenarioLane(name, env, options = {}) {
|
||||
return npmLane(
|
||||
name,
|
||||
`${env} OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:bundled-channel-deps`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
const bundledChannelSmokeLanes = ["telegram", "discord", "slack", "feishu", "memory-lancedb"].map(
|
||||
(channel) =>
|
||||
npmLane(
|
||||
`bundled-channel-${channel}`,
|
||||
`OPENCLAW_BUNDLED_CHANNELS=${channel} ${bundledChannelLaneCommand}`,
|
||||
{ stateScenario: "empty" },
|
||||
),
|
||||
);
|
||||
|
||||
const bundledChannelUpdateLanes = [
|
||||
"telegram",
|
||||
"discord",
|
||||
"slack",
|
||||
"feishu",
|
||||
"memory-lancedb",
|
||||
"acpx",
|
||||
].map((target) =>
|
||||
bundledChannelScenarioLane(
|
||||
`bundled-channel-update-${target}`,
|
||||
`OPENCLAW_BUNDLED_CHANNEL_SCENARIOS=0 OPENCLAW_BUNDLED_CHANNEL_UPDATE_SCENARIO=1 OPENCLAW_BUNDLED_CHANNEL_UPDATE_TARGETS=${target} OPENCLAW_BUNDLED_CHANNEL_ROOT_OWNED_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_SETUP_ENTRY_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_LOAD_FAILURE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_DISABLED_CONFIG_SCENARIO=0`,
|
||||
{
|
||||
noOutputTimeoutMs: BUNDLED_UPDATE_NO_OUTPUT_TIMEOUT_MS,
|
||||
retryPatterns: LIVE_RETRY_PATTERNS,
|
||||
retries: 1,
|
||||
stateScenario: "empty",
|
||||
timeoutMs: BUNDLED_UPDATE_TIMEOUT_MS,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const bundledChannelContractLanes = [
|
||||
bundledChannelScenarioLane(
|
||||
"bundled-channel-root-owned",
|
||||
"OPENCLAW_BUNDLED_CHANNEL_SCENARIOS=0 OPENCLAW_BUNDLED_CHANNEL_UPDATE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_ROOT_OWNED_SCENARIO=1 OPENCLAW_BUNDLED_CHANNEL_SETUP_ENTRY_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_LOAD_FAILURE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_DISABLED_CONFIG_SCENARIO=0",
|
||||
),
|
||||
bundledChannelScenarioLane(
|
||||
"bundled-channel-setup-entry",
|
||||
"OPENCLAW_BUNDLED_CHANNEL_SCENARIOS=0 OPENCLAW_BUNDLED_CHANNEL_UPDATE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_ROOT_OWNED_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_SETUP_ENTRY_SCENARIO=1 OPENCLAW_BUNDLED_CHANNEL_LOAD_FAILURE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_DISABLED_CONFIG_SCENARIO=0",
|
||||
{ stateScenario: "empty" },
|
||||
),
|
||||
bundledChannelScenarioLane(
|
||||
"bundled-channel-load-failure",
|
||||
"OPENCLAW_BUNDLED_CHANNEL_SCENARIOS=0 OPENCLAW_BUNDLED_CHANNEL_UPDATE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_ROOT_OWNED_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_SETUP_ENTRY_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_LOAD_FAILURE_SCENARIO=1 OPENCLAW_BUNDLED_CHANNEL_DISABLED_CONFIG_SCENARIO=0",
|
||||
{ stateScenario: "empty" },
|
||||
),
|
||||
bundledChannelScenarioLane(
|
||||
"bundled-channel-disabled-config",
|
||||
"OPENCLAW_BUNDLED_CHANNEL_SCENARIOS=0 OPENCLAW_BUNDLED_CHANNEL_UPDATE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_ROOT_OWNED_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_SETUP_ENTRY_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_LOAD_FAILURE_SCENARIO=0 OPENCLAW_BUNDLED_CHANNEL_DISABLED_CONFIG_SCENARIO=1",
|
||||
{ stateScenario: "empty" },
|
||||
),
|
||||
];
|
||||
|
||||
const bundledScenarioLanes = [
|
||||
...bundledChannelSmokeLanes,
|
||||
...bundledChannelUpdateLanes,
|
||||
...bundledChannelContractLanes,
|
||||
];
|
||||
|
||||
const bundledPluginInstallUninstallLanes = Array.from(
|
||||
{ length: BUNDLED_PLUGIN_INSTALL_UNINSTALL_SHARDS },
|
||||
(_, index) =>
|
||||
@@ -313,18 +242,12 @@ export const mainLanes = [
|
||||
weight: 6,
|
||||
},
|
||||
),
|
||||
npmLane(
|
||||
"bundled-channel-deps-compat",
|
||||
"OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:bundled-channel-deps:fast",
|
||||
{ resources: ["service"], stateScenario: "empty", weight: 3 },
|
||||
),
|
||||
npmLane("plugin-update", "OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:plugin-update", {
|
||||
stateScenario: "empty",
|
||||
}),
|
||||
serviceLane("config-reload", "OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:config-reload", {
|
||||
stateScenario: "empty",
|
||||
}),
|
||||
...bundledScenarioLanes,
|
||||
lane("openai-image-auth", "OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:openai-image-auth", {
|
||||
stateScenario: "empty",
|
||||
}),
|
||||
@@ -504,7 +427,6 @@ const releasePathBundledChannelLanes = [
|
||||
npmLane("plugin-update", "OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:plugin-update", {
|
||||
stateScenario: "empty",
|
||||
}),
|
||||
...bundledScenarioLanes,
|
||||
];
|
||||
|
||||
const releasePathPackageInstallOpenAiLanes = [
|
||||
@@ -606,15 +528,6 @@ const primaryReleasePathChunks = {
|
||||
"plugins-runtime-install-f": bundledPluginInstallUninstallLanes.slice(15, 18),
|
||||
"plugins-runtime-install-g": bundledPluginInstallUninstallLanes.slice(18, 21),
|
||||
"plugins-runtime-install-h": bundledPluginInstallUninstallLanes.slice(21),
|
||||
"bundled-channels-core": [releasePathBundledChannelLanes[0], ...bundledChannelSmokeLanes],
|
||||
"bundled-channels-update-a": [bundledChannelUpdateLanes[0], bundledChannelUpdateLanes[4]],
|
||||
"bundled-channels-update-discord": [bundledChannelUpdateLanes[1]],
|
||||
"bundled-channels-update-b": [
|
||||
bundledChannelUpdateLanes[2],
|
||||
bundledChannelUpdateLanes[3],
|
||||
bundledChannelUpdateLanes[5],
|
||||
],
|
||||
"bundled-channels-contracts": bundledChannelContractLanes,
|
||||
openwebui: [],
|
||||
};
|
||||
|
||||
@@ -628,11 +541,6 @@ const legacyReleasePathChunks = {
|
||||
"plugins-runtime": releasePathPluginRuntimeLanes,
|
||||
"plugins-integrations": [...releasePathPluginRuntimeLanes, ...releasePathBundledChannelLanes],
|
||||
"bundled-channels": releasePathBundledChannelLanes,
|
||||
"bundled-channels-update-a-legacy": [
|
||||
bundledChannelUpdateLanes[0],
|
||||
bundledChannelUpdateLanes[1],
|
||||
bundledChannelUpdateLanes[4],
|
||||
],
|
||||
};
|
||||
|
||||
function openWebUILane() {
|
||||
|
||||
@@ -4,6 +4,7 @@ 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 hasReleasedBundledInstall(packageJson: unknown): boolean;
|
||||
export function isExplicitlyDownloadablePlugin(packageJson: unknown): boolean;
|
||||
export function shouldBuildBundledCluster(
|
||||
cluster: string,
|
||||
env?: NodeJS.ProcessEnv,
|
||||
|
||||
@@ -35,7 +35,14 @@ export function hasReleasedBundledInstall(packageJson) {
|
||||
);
|
||||
}
|
||||
|
||||
export function isExplicitlyDownloadablePlugin(packageJson) {
|
||||
return packageJson?.openclaw?.bundle?.includeInCore === false;
|
||||
}
|
||||
|
||||
export function shouldBuildBundledCluster(cluster, env = process.env, options = {}) {
|
||||
if (isExplicitlyDownloadablePlugin(options.packageJson)) {
|
||||
return false;
|
||||
}
|
||||
if (hasReleasedBundledInstall(options.packageJson)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export const PLUGIN_PRERELEASE_REQUIRED_SURFACES = Object.freeze([
|
||||
"bundled-lifecycle",
|
||||
"external-plugins",
|
||||
"update-no-op",
|
||||
"channel-runtime-deps",
|
||||
"installed-plugin-deps",
|
||||
"doctor-fix",
|
||||
"config-round-trip",
|
||||
"gateway-bootstrap",
|
||||
@@ -29,11 +29,7 @@ const pluginPrereleaseDockerLanes = Object.freeze([
|
||||
},
|
||||
{
|
||||
lane: "update-channel-switch",
|
||||
surfaces: ["package-artifact", "channel-runtime-deps", "update-no-op"],
|
||||
},
|
||||
{
|
||||
lane: "bundled-channel-deps-compat",
|
||||
surfaces: ["package-artifact", "channel-runtime-deps", "gateway-bootstrap"],
|
||||
surfaces: ["package-artifact", "installed-plugin-deps", "update-no-op"],
|
||||
},
|
||||
{
|
||||
lane: "plugins-offline",
|
||||
|
||||
Reference in New Issue
Block a user