mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 22:04:31 +00:00
refactor(plugins): dedupe plugin SDK alias lookup
This commit is contained in:
@@ -43,15 +43,18 @@ const registryCache = new Map<string, PluginRegistry>();
|
|||||||
|
|
||||||
const defaultLogger = () => createSubsystemLogger("plugins");
|
const defaultLogger = () => createSubsystemLogger("plugins");
|
||||||
|
|
||||||
const resolvePluginSdkAlias = (): string | null => {
|
const resolvePluginSdkAliasFile = (params: {
|
||||||
|
srcFile: string;
|
||||||
|
distFile: string;
|
||||||
|
}): string | null => {
|
||||||
try {
|
try {
|
||||||
const modulePath = fileURLToPath(import.meta.url);
|
const modulePath = fileURLToPath(import.meta.url);
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
const isProduction = process.env.NODE_ENV === "production";
|
||||||
const isTest = process.env.VITEST || process.env.NODE_ENV === "test";
|
const isTest = process.env.VITEST || process.env.NODE_ENV === "test";
|
||||||
let cursor = path.dirname(modulePath);
|
let cursor = path.dirname(modulePath);
|
||||||
for (let i = 0; i < 6; i += 1) {
|
for (let i = 0; i < 6; i += 1) {
|
||||||
const srcCandidate = path.join(cursor, "src", "plugin-sdk", "index.ts");
|
const srcCandidate = path.join(cursor, "src", "plugin-sdk", params.srcFile);
|
||||||
const distCandidate = path.join(cursor, "dist", "plugin-sdk", "index.js");
|
const distCandidate = path.join(cursor, "dist", "plugin-sdk", params.distFile);
|
||||||
const orderedCandidates = isProduction
|
const orderedCandidates = isProduction
|
||||||
? isTest
|
? isTest
|
||||||
? [distCandidate, srcCandidate]
|
? [distCandidate, srcCandidate]
|
||||||
@@ -74,35 +77,11 @@ const resolvePluginSdkAlias = (): string | null => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resolvePluginSdkAlias = (): string | null =>
|
||||||
|
resolvePluginSdkAliasFile({ srcFile: "index.ts", distFile: "index.js" });
|
||||||
|
|
||||||
const resolvePluginSdkAccountIdAlias = (): string | null => {
|
const resolvePluginSdkAccountIdAlias = (): string | null => {
|
||||||
try {
|
return resolvePluginSdkAliasFile({ srcFile: "account-id.ts", distFile: "account-id.js" });
|
||||||
const modulePath = fileURLToPath(import.meta.url);
|
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
|
||||||
const isTest = process.env.VITEST || process.env.NODE_ENV === "test";
|
|
||||||
let cursor = path.dirname(modulePath);
|
|
||||||
for (let i = 0; i < 6; i += 1) {
|
|
||||||
const srcCandidate = path.join(cursor, "src", "plugin-sdk", "account-id.ts");
|
|
||||||
const distCandidate = path.join(cursor, "dist", "plugin-sdk", "account-id.js");
|
|
||||||
const orderedCandidates = isProduction
|
|
||||||
? isTest
|
|
||||||
? [distCandidate, srcCandidate]
|
|
||||||
: [distCandidate]
|
|
||||||
: [srcCandidate, distCandidate];
|
|
||||||
for (const candidate of orderedCandidates) {
|
|
||||||
if (fs.existsSync(candidate)) {
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const parent = path.dirname(cursor);
|
|
||||||
if (parent === cursor) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cursor = parent;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildCacheKey(params: {
|
function buildCacheKey(params: {
|
||||||
|
|||||||
Reference in New Issue
Block a user