mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 03:11:10 +00:00
refactor(plugin-sdk): remove source alias residue
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import ts from "typescript";
|
||||
import { BUNDLED_PLUGIN_PATH_PREFIX, bundledPluginFile } from "./bundled-plugin-paths.mjs";
|
||||
import { bundledPluginFile } from "./bundled-plugin-paths.mjs";
|
||||
|
||||
function pluginSource(dirName, artifactBasename = "api.js") {
|
||||
return `openclaw/plugin-source/${dirName}/${artifactBasename}`;
|
||||
return `@openclaw/${dirName}/${artifactBasename}`;
|
||||
}
|
||||
|
||||
function runtimeApiSourcePath(dirName) {
|
||||
return bundledPluginFile(dirName, "runtime-api.ts");
|
||||
}
|
||||
|
||||
const BUNDLED_PLUGIN_SOURCE_RELATIVE_PREFIX = `../../${BUNDLED_PLUGIN_PATH_PREFIX}`;
|
||||
|
||||
export const GENERATED_PLUGIN_SDK_FACADES = [
|
||||
{
|
||||
subpath: "amazon-bedrock",
|
||||
@@ -1271,13 +1269,6 @@ export const GENERATED_PLUGIN_SDK_FACADE_TYPES_OUTPUT =
|
||||
"src/generated/plugin-sdk-facade-type-map.generated.ts";
|
||||
|
||||
function rewriteFacadeTypeImportSpecifier(sourcePath) {
|
||||
if (sourcePath.startsWith("openclaw/plugin-source/")) {
|
||||
const { dirName, artifactBasename } = normalizeFacadeSourceParts(sourcePath);
|
||||
return `${BUNDLED_PLUGIN_SOURCE_RELATIVE_PREFIX}${dirName}/${artifactBasename}`;
|
||||
}
|
||||
if (sourcePath.startsWith(BUNDLED_PLUGIN_SOURCE_RELATIVE_PREFIX)) {
|
||||
return sourcePath;
|
||||
}
|
||||
return sourcePath;
|
||||
}
|
||||
|
||||
@@ -1325,11 +1316,11 @@ function isArrayTypeLike(checker, type) {
|
||||
}
|
||||
|
||||
function normalizeFacadeSourceParts(sourcePath) {
|
||||
const pluginSourceMatch = /^openclaw\/plugin-source\/([^/]+)\/([^/]+)$/u.exec(sourcePath);
|
||||
if (pluginSourceMatch) {
|
||||
const packageSourceMatch = /^@openclaw\/([^/]+)\/([^/]+)$/u.exec(sourcePath);
|
||||
if (packageSourceMatch) {
|
||||
return {
|
||||
dirName: pluginSourceMatch[1],
|
||||
artifactBasename: pluginSourceMatch[2],
|
||||
dirName: packageSourceMatch[1],
|
||||
artifactBasename: packageSourceMatch[2],
|
||||
};
|
||||
}
|
||||
const match = /^\.\.\/\.\.\/extensions\/([^/]+)\/([^/]+)$/u.exec(sourcePath);
|
||||
@@ -1382,8 +1373,9 @@ function collectRuntimeApiPreExports(repoRoot, runtimeApiPath) {
|
||||
}
|
||||
|
||||
function resolveFacadeSourceTypescriptPath(repoRoot, sourcePath) {
|
||||
const absolutePath = sourcePath.startsWith("openclaw/plugin-source/")
|
||||
? path.resolve(repoRoot, "extensions", sourcePath.slice("openclaw/plugin-source/".length))
|
||||
const packageSourceMatch = /^@openclaw\/([^/]+)\/(.+)$/u.exec(sourcePath);
|
||||
const absolutePath = packageSourceMatch
|
||||
? path.resolve(repoRoot, "extensions", packageSourceMatch[1], packageSourceMatch[2])
|
||||
: path.resolve(repoRoot, "src/plugin-sdk", sourcePath);
|
||||
const candidates = [absolutePath.replace(/\.js$/, ".ts"), absolutePath.replace(/\.js$/, ".tsx")];
|
||||
return candidates.find((candidate) => fs.existsSync(candidate));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,11 +19,12 @@ export const ircSetupAdapter: FacadeModule["ircSetupAdapter"] = createLazyFacade
|
||||
export const ircSetupWizard: FacadeModule["ircSetupWizard"] = createLazyFacadeObjectValue(
|
||||
() => loadFacadeModule()["ircSetupWizard"] as object,
|
||||
) as FacadeModule["ircSetupWizard"];
|
||||
export const listIrcAccountIds: FacadeModule["listIrcAccountIds"] = ((...args) =>
|
||||
loadFacadeModule()["listIrcAccountIds"](...args)) as FacadeModule["listIrcAccountIds"];
|
||||
export const resolveDefaultIrcAccountId: FacadeModule["resolveDefaultIrcAccountId"] = ((...args) =>
|
||||
loadFacadeModule()["resolveDefaultIrcAccountId"](
|
||||
...args,
|
||||
)) as FacadeModule["resolveDefaultIrcAccountId"];
|
||||
export const listIrcAccountIds: FacadeModule["listIrcAccountIds"] = createLazyFacadeObjectValue(
|
||||
() => loadFacadeModule()["listIrcAccountIds"] as object,
|
||||
) as FacadeModule["listIrcAccountIds"];
|
||||
export const resolveDefaultIrcAccountId: FacadeModule["resolveDefaultIrcAccountId"] =
|
||||
createLazyFacadeObjectValue(
|
||||
() => loadFacadeModule()["resolveDefaultIrcAccountId"] as object,
|
||||
) as FacadeModule["resolveDefaultIrcAccountId"];
|
||||
export const resolveIrcAccount: FacadeModule["resolveIrcAccount"] = ((...args) =>
|
||||
loadFacadeModule()["resolveIrcAccount"](...args)) as FacadeModule["resolveIrcAccount"];
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
import type { PluginSdkFacadeTypeMap } from "../generated/plugin-sdk-facade-type-map.generated.js";
|
||||
type FacadeEntry = PluginSdkFacadeTypeMap["line-runtime"];
|
||||
type FacadeModule = FacadeEntry["module"];
|
||||
import { loadBundledPluginPublicSurfaceModuleSync } from "./facade-runtime.js";
|
||||
import {
|
||||
createLazyFacadeObjectValue,
|
||||
loadBundledPluginPublicSurfaceModuleSync,
|
||||
} from "./facade-runtime.js";
|
||||
|
||||
function loadFacadeModule(): FacadeModule {
|
||||
return loadBundledPluginPublicSurfaceModuleSync<FacadeModule>({
|
||||
@@ -68,8 +71,9 @@ export const deleteRichMenuAlias: FacadeModule["deleteRichMenuAlias"] = ((...arg
|
||||
loadFacadeModule()["deleteRichMenuAlias"](...args)) as FacadeModule["deleteRichMenuAlias"];
|
||||
export const downloadLineMedia: FacadeModule["downloadLineMedia"] = ((...args) =>
|
||||
loadFacadeModule()["downloadLineMedia"](...args)) as FacadeModule["downloadLineMedia"];
|
||||
export const firstDefined: FacadeModule["firstDefined"] = ((...args) =>
|
||||
loadFacadeModule()["firstDefined"](...args)) as FacadeModule["firstDefined"];
|
||||
export const firstDefined: FacadeModule["firstDefined"] = createLazyFacadeObjectValue(
|
||||
() => loadFacadeModule()["firstDefined"] as object,
|
||||
) as FacadeModule["firstDefined"];
|
||||
export const getDefaultRichMenuId: FacadeModule["getDefaultRichMenuId"] = ((...args) =>
|
||||
loadFacadeModule()["getDefaultRichMenuId"](...args)) as FacadeModule["getDefaultRichMenuId"];
|
||||
export const getRichMenu: FacadeModule["getRichMenu"] = ((...args) =>
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
import type { PluginSdkFacadeTypeMap } from "../generated/plugin-sdk-facade-type-map.generated.js";
|
||||
type FacadeEntry = PluginSdkFacadeTypeMap["matrix-runtime-surface"];
|
||||
type FacadeModule = FacadeEntry["module"];
|
||||
import { loadBundledPluginPublicSurfaceModuleSync } from "./facade-runtime.js";
|
||||
import {
|
||||
createLazyFacadeObjectValue,
|
||||
loadBundledPluginPublicSurfaceModuleSync,
|
||||
} from "./facade-runtime.js";
|
||||
|
||||
function loadFacadeModule(): FacadeModule {
|
||||
return loadBundledPluginPublicSurfaceModuleSync<FacadeModule>({
|
||||
@@ -16,5 +19,6 @@ export const resolveMatrixAccountStringValues: FacadeModule["resolveMatrixAccoun
|
||||
loadFacadeModule()["resolveMatrixAccountStringValues"](
|
||||
...args,
|
||||
)) as FacadeModule["resolveMatrixAccountStringValues"];
|
||||
export const setMatrixRuntime: FacadeModule["setMatrixRuntime"] = ((...args) =>
|
||||
loadFacadeModule()["setMatrixRuntime"](...args)) as FacadeModule["setMatrixRuntime"];
|
||||
export const setMatrixRuntime: FacadeModule["setMatrixRuntime"] = createLazyFacadeObjectValue(
|
||||
() => loadFacadeModule()["setMatrixRuntime"] as object,
|
||||
) as FacadeModule["setMatrixRuntime"];
|
||||
|
||||
@@ -63,6 +63,10 @@ function readGeneratedFacadeTypeMap(): string {
|
||||
);
|
||||
}
|
||||
|
||||
function buildLegacyPluginSourceAlias(): string {
|
||||
return ["openclaw", ["plugin", "source"].join("-")].join("/") + "/";
|
||||
}
|
||||
|
||||
describe("plugin-sdk package contract guardrails", () => {
|
||||
it("keeps package.json exports aligned with built plugin-sdk entrypoints", () => {
|
||||
expect(collectPluginSdkPackageExports()).toEqual([...pluginSdkEntrypoints].toSorted());
|
||||
@@ -99,7 +103,8 @@ describe("plugin-sdk package contract guardrails", () => {
|
||||
expect(optionalDependencies["@matrix-org/matrix-sdk-crypto-nodejs"]).toBe("^0.4.0");
|
||||
});
|
||||
|
||||
it("keeps generated facade types on package-valid module specifiers", () => {
|
||||
expect(readGeneratedFacadeTypeMap()).not.toContain("openclaw/plugin-source/");
|
||||
it("keeps generated facade types on package-style module specifiers", () => {
|
||||
expect(readGeneratedFacadeTypeMap()).not.toContain("../../extensions/");
|
||||
expect(readGeneratedFacadeTypeMap()).not.toContain(buildLegacyPluginSourceAlias());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"openclaw/plugin-sdk": ["./src/plugin-sdk/index.ts"],
|
||||
"openclaw/plugin-sdk/*": ["./src/plugin-sdk/*.ts"],
|
||||
"openclaw/plugin-sdk/account-id": ["./src/plugin-sdk/account-id.ts"],
|
||||
"openclaw/plugin-source/*": ["./extensions/*"]
|
||||
"@openclaw/*": ["./extensions/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*", "ui/**/*", "extensions/**/*", "packages/**/*"],
|
||||
|
||||
Reference in New Issue
Block a user