mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 12:48:37 +00:00
Chore: harden A2UI bundle dependency resolution (#22507)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: d84c5bde51
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import path from "node:path";
|
||||
import { existsSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { defineConfig } from "rolldown";
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const repoRoot = path.resolve(here, "../../../../..");
|
||||
const uiRoot = path.resolve(repoRoot, "ui");
|
||||
const fromHere = (p) => path.resolve(here, p);
|
||||
const outputFile = path.resolve(
|
||||
here,
|
||||
@@ -17,19 +17,28 @@ const outputFile = path.resolve(
|
||||
|
||||
const a2uiLitDist = path.resolve(repoRoot, "vendor/a2ui/renderers/lit/dist/src");
|
||||
const a2uiThemeContext = path.resolve(a2uiLitDist, "0.8/ui/context/theme.js");
|
||||
const a2uiNodeModules = path.resolve(repoRoot, "ui/node_modules");
|
||||
const rootNodeModules = path.resolve(repoRoot, "node_modules");
|
||||
const uiNodeModules = path.resolve(uiRoot, "node_modules");
|
||||
const repoNodeModules = path.resolve(repoRoot, "node_modules");
|
||||
|
||||
const resolveA2uiDep = (pkg, rel = "") => {
|
||||
const uiPath = path.resolve(a2uiNodeModules, pkg, rel);
|
||||
if (existsSync(uiPath)) {
|
||||
return uiPath;
|
||||
function resolveUiDependency(moduleId) {
|
||||
const candidates = [
|
||||
path.resolve(uiNodeModules, moduleId),
|
||||
path.resolve(repoNodeModules, moduleId),
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
if (existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return path.resolve(rootNodeModules, pkg, rel);
|
||||
};
|
||||
const fallbackCandidates = candidates.join(", ");
|
||||
throw new Error(
|
||||
`A2UI bundle config cannot resolve ${moduleId}. Checked: ${fallbackCandidates}. ` +
|
||||
"Keep dependency installed in ui workspace or repo root before bundling.",
|
||||
);
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
export default {
|
||||
input: fromHere("bootstrap.js"),
|
||||
experimental: {
|
||||
attachDebugInfo: "none",
|
||||
@@ -40,13 +49,13 @@ export default defineConfig({
|
||||
"@a2ui/lit": path.resolve(a2uiLitDist, "index.js"),
|
||||
"@a2ui/lit/ui": path.resolve(a2uiLitDist, "0.8/ui/ui.js"),
|
||||
"@openclaw/a2ui-theme-context": a2uiThemeContext,
|
||||
"@lit/context": resolveA2uiDep("@lit/context", "index.js"),
|
||||
"@lit/context/": resolveA2uiDep("@lit/context"),
|
||||
"@lit-labs/signals": resolveA2uiDep("@lit-labs/signals", "index.js"),
|
||||
"@lit-labs/signals/": resolveA2uiDep("@lit-labs/signals"),
|
||||
lit: resolveA2uiDep("lit", "index.js"),
|
||||
"lit/": resolveA2uiDep("lit"),
|
||||
"signal-utils/": resolveA2uiDep("signal-utils"),
|
||||
"@lit/context": resolveUiDependency("@lit/context"),
|
||||
"@lit/context/": resolveUiDependency("@lit/context/"),
|
||||
"@lit-labs/signals": resolveUiDependency("@lit-labs/signals"),
|
||||
"@lit-labs/signals/": resolveUiDependency("@lit-labs/signals/"),
|
||||
lit: resolveUiDependency("lit"),
|
||||
"lit/": resolveUiDependency("lit/"),
|
||||
"signal-utils/": resolveUiDependency("signal-utils/"),
|
||||
},
|
||||
},
|
||||
output: {
|
||||
@@ -55,4 +64,4 @@ export default defineConfig({
|
||||
codeSplitting: false,
|
||||
sourcemap: false,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user