From c37c8d5671398553bbd04eabc199e61f0d8f295d Mon Sep 17 00:00:00 2001 From: Vincent Koc <25068+vincentkoc@users.noreply.github.com> Date: Sun, 12 Jul 2026 04:28:22 +0200 Subject: [PATCH] fix(plugin-sdk): resolve surface counts from source graph --- scripts/plugin-sdk-surface-report.mjs | 22 ++++++++----------- .../scripts/plugin-sdk-surface-report.test.ts | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/scripts/plugin-sdk-surface-report.mjs b/scripts/plugin-sdk-surface-report.mjs index 6f43ec058aa0..88fbde0cb6a2 100644 --- a/scripts/plugin-sdk-surface-report.mjs +++ b/scripts/plugin-sdk-surface-report.mjs @@ -199,12 +199,12 @@ export function readPluginSdkSurfaceBudgets(env = process.env) { ), publicExports: readPluginSdkSurfaceBudgetEnv( "OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_EXPORTS", - 10595, + 10623, env, ), publicFunctionExports: readPluginSdkSurfaceBudgetEnv( "OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS", - 5267, + 5348, env, ), publicDeprecatedExports: readPluginSdkSurfaceBudgetEnv( @@ -246,20 +246,9 @@ function hasDeprecatedTag(symbol) { return symbol.getJsDocTags().some((tag) => tag.name === "deprecated"); } -function isGeneratedPackageDeclaration(declaration) { - const relative = path.relative(repoRoot, declaration.getSourceFile().fileName); - const relativePath = relative.split(path.sep).join(path.posix.sep); - // Package builds can make workspace package reexports look newly callable. - // Source-surface counts must stay independent of generated dist state. - return /^packages\/[^/]+\/dist\//u.test(relativePath); -} - function isCallableExport(checker, symbol, sourceFile) { const target = unwrapAlias(checker, symbol); const declaration = target.valueDeclaration ?? target.declarations?.[0] ?? sourceFile; - if (isGeneratedPackageDeclaration(declaration)) { - return false; - } const type = checker.getTypeOfSymbolAtLocation(target, declaration); return checker.getSignaturesOfType(type, ts.SignatureKind.Call).length > 0; } @@ -288,13 +277,20 @@ let exportStatsProgram; function collectExportStats(entrypoints) { // CLI validation and help do not need the compiler's startup cost. ts ??= require("typescript"); + const configPath = path.join(repoRoot, "tsconfig.json"); + const config = ts.readConfigFile(configPath, ts.sys.readFile); + if (config.error) { + throw new Error(ts.flattenDiagnosticMessageText(config.error.messageText, "\n")); + } exportStatsProgram ??= ts.createProgram(pluginSdkEntrypoints.map(entrypointPath), { allowJs: false, + baseUrl: repoRoot, declaration: true, emitDeclarationOnly: true, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, noEmit: true, + paths: config.config.compilerOptions?.paths, skipLibCheck: true, strict: false, target: ts.ScriptTarget.ES2022, diff --git a/test/scripts/plugin-sdk-surface-report.test.ts b/test/scripts/plugin-sdk-surface-report.test.ts index 89271f0c078d..0def49d33993 100644 --- a/test/scripts/plugin-sdk-surface-report.test.ts +++ b/test/scripts/plugin-sdk-surface-report.test.ts @@ -146,7 +146,7 @@ describe("plugin SDK surface report", () => { } }); - it("keeps generated package declarations out of source surface counts", () => { + it("rejects callable surface growth from the canonical source graph", () => { const budget = readDefaultPublicSurfaceBudgets().callableExports; const budgetConfig = readPluginSdkSurfaceBudgets({ OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS: String(budget - 1),