mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04: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 resolvePluginSdkAlias = (): string | null => {
|
||||
const resolvePluginSdkAliasFile = (params: {
|
||||
srcFile: string;
|
||||
distFile: string;
|
||||
}): string | null => {
|
||||
try {
|
||||
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", "index.ts");
|
||||
const distCandidate = path.join(cursor, "dist", "plugin-sdk", "index.js");
|
||||
const srcCandidate = path.join(cursor, "src", "plugin-sdk", params.srcFile);
|
||||
const distCandidate = path.join(cursor, "dist", "plugin-sdk", params.distFile);
|
||||
const orderedCandidates = isProduction
|
||||
? isTest
|
||||
? [distCandidate, srcCandidate]
|
||||
@@ -74,35 +77,11 @@ const resolvePluginSdkAlias = (): string | null => {
|
||||
return null;
|
||||
};
|
||||
|
||||
const resolvePluginSdkAlias = (): string | null =>
|
||||
resolvePluginSdkAliasFile({ srcFile: "index.ts", distFile: "index.js" });
|
||||
|
||||
const resolvePluginSdkAccountIdAlias = (): string | null => {
|
||||
try {
|
||||
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;
|
||||
return resolvePluginSdkAliasFile({ srcFile: "account-id.ts", distFile: "account-id.js" });
|
||||
};
|
||||
|
||||
function buildCacheKey(params: {
|
||||
|
||||
Reference in New Issue
Block a user