mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 13:04:47 +00:00
fix(gateway): cover restored watch artifacts
This commit is contained in:
committed by
Peter Steinberger
parent
6b5296d4d4
commit
e40ddf9b02
@@ -34,6 +34,21 @@ function listExtensionPackageDirs(rootDir, fsImpl) {
|
||||
.toSorted((left, right) => left.dirName.localeCompare(right.dirName));
|
||||
}
|
||||
|
||||
function listDistExtensionPackageDirs(rootDir, fsImpl) {
|
||||
const extensionsRoot = path.join(rootDir, "dist", "extensions");
|
||||
if (!fsImpl.existsSync(extensionsRoot)) {
|
||||
return [];
|
||||
}
|
||||
return fsImpl
|
||||
.readdirSync(extensionsRoot, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory() && entry.name !== "node_modules")
|
||||
.map((entry) => ({
|
||||
dirName: entry.name,
|
||||
packageDir: path.join(extensionsRoot, entry.name),
|
||||
}))
|
||||
.toSorted((left, right) => left.dirName.localeCompare(right.dirName));
|
||||
}
|
||||
|
||||
function readPackageStaticAssetEntries(packageJson) {
|
||||
const entries = packageJson.openclaw?.build?.staticAssets;
|
||||
return Array.isArray(entries) ? entries : [];
|
||||
@@ -65,6 +80,33 @@ export function discoverStaticExtensionAssets(params = {}) {
|
||||
return assets.toSorted((left, right) => left.dest.localeCompare(right.dest));
|
||||
}
|
||||
|
||||
function discoverStaticExtensionRuntimeOverlayAssets(params = {}) {
|
||||
const rootDir = params.rootDir ?? process.cwd();
|
||||
const fsImpl = params.fs ?? fs;
|
||||
const assetsByDest = new Map();
|
||||
for (const asset of params.assets ?? discoverStaticExtensionAssets({ rootDir, fs: fsImpl })) {
|
||||
assetsByDest.set(asset.dest, asset);
|
||||
}
|
||||
for (const { dirName, packageDir } of listDistExtensionPackageDirs(rootDir, fsImpl)) {
|
||||
const packageJsonPath = path.join(packageDir, "package.json");
|
||||
if (!fsImpl.existsSync(packageJsonPath)) {
|
||||
continue;
|
||||
}
|
||||
const packageJson = readJsonFile(packageJsonPath, fsImpl);
|
||||
for (const entry of readPackageStaticAssetEntries(packageJson)) {
|
||||
const output = normalizePackageRelativePath(entry?.output);
|
||||
if (!output) {
|
||||
continue;
|
||||
}
|
||||
const dest = toPosixPath(path.posix.join("dist", "extensions", dirName, output));
|
||||
if (!assetsByDest.has(dest)) {
|
||||
assetsByDest.set(dest, { pluginDir: dirName, src: dest, dest });
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...assetsByDest.values()].toSorted((left, right) => left.dest.localeCompare(right.dest));
|
||||
}
|
||||
|
||||
export function listStaticExtensionAssetOutputs(params = {}) {
|
||||
const assets = params.assets ?? discoverStaticExtensionAssets(params);
|
||||
return assets
|
||||
@@ -99,7 +141,7 @@ export function copyStaticExtensionAssets(params = {}) {
|
||||
export function copyStaticExtensionAssetsToRuntimeOverlay(params = {}) {
|
||||
const rootDir = params.rootDir ?? process.cwd();
|
||||
const fsImpl = params.fs ?? fs;
|
||||
const assets = params.assets ?? discoverStaticExtensionAssets({ rootDir, fs: fsImpl });
|
||||
const assets = discoverStaticExtensionRuntimeOverlayAssets({ ...params, rootDir, fs: fsImpl });
|
||||
const runtimeExtensionsRoot = path.join(rootDir, "dist-runtime", "extensions");
|
||||
if (!fsImpl.existsSync(runtimeExtensionsRoot)) {
|
||||
return;
|
||||
@@ -111,10 +153,12 @@ export function copyStaticExtensionAssetsToRuntimeOverlay(params = {}) {
|
||||
continue;
|
||||
}
|
||||
const srcPath = path.join(rootDir, src);
|
||||
const distPath = path.join(rootDir, dest);
|
||||
const copySourcePath = fsImpl.existsSync(srcPath) ? srcPath : distPath;
|
||||
const destPath = path.join(rootDir, "dist-runtime", normalizedDest.slice("dist/".length));
|
||||
if (fsImpl.existsSync(srcPath)) {
|
||||
if (fsImpl.existsSync(copySourcePath)) {
|
||||
fsImpl.mkdirSync(path.dirname(destPath), { recursive: true });
|
||||
fsImpl.copyFileSync(srcPath, destPath);
|
||||
fsImpl.copyFileSync(copySourcePath, destPath);
|
||||
} else {
|
||||
warn(`[runtime-postbuild] static asset not found, skipping: ${src}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user