




















@@ -154,6 +154,21 @@ function createExtensionApiAliasFixture(params?: {
154154return { root, srcFile, distFile };
155155}
156156157+function writeWorkspacePackageEntry(params: {
158+root: string;
159+packageDir: string;
160+srcFile: string;
161+distFile: string;
162+}) {
163+const srcFile = path.join(params.root, "packages", params.packageDir, "src", params.srcFile);
164+const distFile = path.join(params.root, "packages", params.packageDir, "dist", params.distFile);
165+mkdirSafeDir(path.dirname(srcFile));
166+mkdirSafeDir(path.dirname(distFile));
167+fs.writeFileSync(srcFile, "export {};\n", "utf-8");
168+fs.writeFileSync(distFile, "export {};\n", "utf-8");
169+return { srcFile, distFile };
170+}
171+157172function createPluginRuntimeAliasFixture(params?: { srcBody?: string; distBody?: string }) {
158173const root = makeTempDir();
159174const srcFile = path.join(root, "src", "plugins", "runtime", "index.ts");
@@ -1331,6 +1346,90 @@ describe("plugin sdk alias helpers", () => {
13311346});
13321347});
133313481349+it("aliases gateway workspace packages to source when dist artifacts are missing", () => {
1350+const fixture = createPluginSdkAliasFixture();
1351+const gatewayClient = writeWorkspacePackageEntry({
1352+root: fixture.root,
1353+packageDir: "gateway-client",
1354+srcFile: "index.ts",
1355+distFile: "index.mjs",
1356+});
1357+const gatewayClientTimeouts = writeWorkspacePackageEntry({
1358+root: fixture.root,
1359+packageDir: "gateway-client",
1360+srcFile: "timeouts.ts",
1361+distFile: "timeouts.mjs",
1362+});
1363+const gatewayProtocol = writeWorkspacePackageEntry({
1364+root: fixture.root,
1365+packageDir: "gateway-protocol",
1366+srcFile: "index.ts",
1367+distFile: "index.mjs",
1368+});
1369+const gatewayProtocolSchema = writeWorkspacePackageEntry({
1370+root: fixture.root,
1371+packageDir: "gateway-protocol",
1372+srcFile: "schema.ts",
1373+distFile: "schema.mjs",
1374+});
1375+fs.rmSync(gatewayClient.distFile);
1376+fs.rmSync(gatewayClientTimeouts.distFile);
1377+fs.rmSync(gatewayProtocol.distFile);
1378+fs.rmSync(gatewayProtocolSchema.distFile);
1379+const sourcePluginEntry = writePluginEntry(
1380+fixture.root,
1381+bundledPluginFile("demo", "src/index.ts"),
1382+);
1383+1384+const aliases = withEnv({ NODE_ENV: undefined }, () =>
1385+buildPluginLoaderAliasMap(sourcePluginEntry, undefined, undefined, "dist"),
1386+);
1387+1388+expect(fs.realpathSync(aliases["@openclaw/gateway-client"] ?? "")).toBe(
1389+fs.realpathSync(gatewayClient.srcFile),
1390+);
1391+expect(fs.realpathSync(aliases["@openclaw/gateway-client/timeouts"] ?? "")).toBe(
1392+fs.realpathSync(gatewayClientTimeouts.srcFile),
1393+);
1394+expect(fs.realpathSync(aliases["@openclaw/gateway-protocol"] ?? "")).toBe(
1395+fs.realpathSync(gatewayProtocol.srcFile),
1396+);
1397+expect(fs.realpathSync(aliases["@openclaw/gateway-protocol/schema"] ?? "")).toBe(
1398+fs.realpathSync(gatewayProtocolSchema.srcFile),
1399+);
1400+});
1401+1402+it("aliases gateway workspace package subpaths to dist when available", () => {
1403+const fixture = createPluginSdkAliasFixture();
1404+const gatewayClient = writeWorkspacePackageEntry({
1405+root: fixture.root,
1406+packageDir: "gateway-client",
1407+srcFile: "readiness.ts",
1408+distFile: "readiness.mjs",
1409+});
1410+const gatewayProtocol = writeWorkspacePackageEntry({
1411+root: fixture.root,
1412+packageDir: "gateway-protocol",
1413+srcFile: "connect-error-details.ts",
1414+distFile: "connect-error-details.mjs",
1415+});
1416+const sourcePluginEntry = writePluginEntry(
1417+fixture.root,
1418+bundledPluginFile("demo", "src/index.ts"),
1419+);
1420+1421+const aliases = withEnv({ NODE_ENV: undefined }, () =>
1422+buildPluginLoaderAliasMap(sourcePluginEntry, undefined, undefined, "dist"),
1423+);
1424+1425+expect(fs.realpathSync(aliases["@openclaw/gateway-client/readiness"] ?? "")).toBe(
1426+fs.realpathSync(gatewayClient.distFile),
1427+);
1428+expect(fs.realpathSync(aliases["@openclaw/gateway-protocol/connect-error-details"] ?? "")).toBe(
1429+fs.realpathSync(gatewayProtocol.distFile),
1430+);
1431+});
1432+13341433it("aliases bundled plugin package public surfaces for source plugin transforms", () => {
13351434const { fixture, sourceApiPath, sourceRuntimeApiPath } =
13361435createBundledPluginPackagePublicSurfaceAliasFixture();
@@ -2146,9 +2245,7 @@ describe("buildPluginLoaderJitiOptions", () => {
21462245),
21472246);
214822472149-expect(guardedFsCache).toContain(
2150-path.join("jiti", "openclaw", "1.2.3-beta.4") + path.sep,
2151-);
2248+expect(guardedFsCache).toContain(path.join("jiti", "openclaw", "1.2.3-beta.4") + path.sep);
21522249expect(guardedFsCache.startsWith(path.join(root, "jiti") + path.sep)).toBe(false);
21532250expect(respectedFsCache).toContain(
21542251path.join(root, "jiti", "openclaw", "1.2.3-beta.4") + path.sep,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。