fix(plugin-sdk): resolve surface counts from source graph

This commit is contained in:
Vincent Koc
2026-07-12 04:28:22 +02:00
parent 5019d378af
commit c37c8d5671
2 changed files with 10 additions and 14 deletions
+9 -13
View File
@@ -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,
@@ -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),