From b93aa7fb66356fe6ab937be831c1b8b1cce41864 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 05:29:39 +0000 Subject: [PATCH] refactor(plugins): dedupe plugin SDK alias lookup --- src/plugins/loader.ts | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/src/plugins/loader.ts b/src/plugins/loader.ts index 0603454766c..9365f584fe3 100644 --- a/src/plugins/loader.ts +++ b/src/plugins/loader.ts @@ -43,15 +43,18 @@ const registryCache = new Map(); 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: {