perf(plugins): prefer built bundled extensions

This commit is contained in:
Peter Steinberger
2026-05-02 17:05:23 +01:00
parent d3f883e71b
commit bd83f8a844
3 changed files with 18 additions and 14 deletions

View File

@@ -199,7 +199,7 @@ describe("resolveBundledPluginsDir", () => {
},
],
[
"prefers source extensions in a pnpm git checkout outside vitest",
"prefers built dist/extensions in a pnpm git checkout outside vitest",
{
prefix: "openclaw-bundled-dir-git-built-",
hasExtensions: true,
@@ -210,7 +210,7 @@ describe("resolveBundledPluginsDir", () => {
hasPnpmWorkspace: true,
},
{
expectedRelativeDir: "extensions",
expectedRelativeDir: path.join("dist", "extensions"),
},
],
[
@@ -227,7 +227,7 @@ describe("resolveBundledPluginsDir", () => {
},
],
[
"still prefers source extensions during tsx-driven pnpm source execution",
"prefers built dist/extensions during tsx-driven pnpm source execution",
{
prefix: "openclaw-bundled-dir-tsx-built-",
hasExtensions: true,
@@ -238,7 +238,7 @@ describe("resolveBundledPluginsDir", () => {
hasPnpmWorkspace: true,
},
{
expectedRelativeDir: "extensions",
expectedRelativeDir: path.join("dist", "extensions"),
execArgv: ["--import", "tsx"],
},
],

View File

@@ -167,13 +167,9 @@ function resolveBundledDirFromPackageRoot(packageRoot: string): string | undefin
const builtExtensionsDir = path.join(packageRoot, "dist", "extensions");
const sourceCheckout = isSourceCheckoutRoot(packageRoot);
const hasUsableSourceTree = sourceCheckout && hasUsableBundledPluginTree(sourceExtensionsDir);
// In pnpm source checkouts, extensions/* is a workspace package tree with its
// own package.json dependencies. Prefer it so git checkouts remain editable
// and dependency-complete without moving optional plugin deps back into root.
if (hasUsableSourceTree) {
return sourceExtensionsDir;
}
// In pnpm source checkouts, prefer the built bundled plugin runtime when it
// exists so dist gateway runs avoid loading TS plugin entrypoints through jiti.
// Keep the source tree as the fallback for fresh checkouts before build.
const runtimeExtensionsDir = path.join(packageRoot, "dist-runtime", "extensions");
const hasUsableRuntimeTree = sourceCheckout
? hasUsableBundledPluginTree(runtimeExtensionsDir)
@@ -181,6 +177,12 @@ function resolveBundledDirFromPackageRoot(packageRoot: string): string | undefin
const hasUsableBuiltTree = sourceCheckout
? hasUsableBundledPluginTree(builtExtensionsDir)
: fs.existsSync(builtExtensionsDir);
if (sourceCheckout && hasUsableBuiltTree) {
return builtExtensionsDir;
}
if (sourceCheckout && hasUsableRuntimeTree) {
return runtimeExtensionsDir;
}
if (hasUsableRuntimeTree && hasUsableBuiltTree) {
return runtimeExtensionsDir;
}

View File

@@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
import { loadOpenClawPlugins } from "./loader.js";
describe("source checkout bundled plugin runtime", () => {
it("loads enabled bundled plugins from the pnpm workspace source tree", () => {
it("loads enabled bundled plugins from built dist when available", () => {
const registry = loadOpenClawPlugins({
cache: false,
onlyPluginIds: ["twitch"],
@@ -21,7 +21,9 @@ describe("source checkout bundled plugin runtime", () => {
status: "loaded",
origin: "bundled",
});
expect(twitch?.source).toContain(`${path.sep}extensions${path.sep}twitch${path.sep}index.ts`);
expect(twitch?.rootDir).toContain(`${path.sep}extensions${path.sep}twitch`);
expect(twitch?.source).toContain(
`${path.sep}dist${path.sep}extensions${path.sep}twitch${path.sep}index.js`,
);
expect(twitch?.rootDir).toContain(`${path.sep}dist${path.sep}extensions${path.sep}twitch`);
});
});