@webpieces/nx-webpieces-rules 0.4.832 → 0.4.834
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/executors/generate/executor.js +2 -0
- package/src/executors/generate/executor.js.map +1 -1
- package/src/executors/openapi-components-generate/executor.d.ts +2 -1
- package/src/executors/openapi-components-generate/executor.js +5 -2
- package/src/executors/openapi-components-generate/executor.js.map +1 -1
- package/src/executors/openapi-generate/executor.d.ts +15 -1
- package/src/executors/openapi-generate/executor.js +30 -2
- package/src/executors/openapi-generate/executor.js.map +1 -1
- package/src/executors/validate-api-lib-tag/executor.d.ts +5 -3
- package/src/executors/validate-api-lib-tag/executor.js +7 -5
- package/src/executors/validate-api-lib-tag/executor.js.map +1 -1
- package/src/executors/validate-architecture-unchanged/executor.js +2 -0
- package/src/executors/validate-architecture-unchanged/executor.js.map +1 -1
- package/src/lib/api-docs/components-wiring.d.ts +6 -0
- package/src/lib/api-docs/components-wiring.js +18 -1
- package/src/lib/api-docs/components-wiring.js.map +1 -1
- package/src/lib/api-usage/api-doc-rules-scan.d.ts +17 -1
- package/src/lib/api-usage/api-doc-rules-scan.js +28 -3
- package/src/lib/api-usage/api-doc-rules-scan.js.map +1 -1
- package/src/lib/api-usage/api-lib-tag-validator.d.ts +51 -14
- package/src/lib/api-usage/api-lib-tag-validator.js +272 -22
- package/src/lib/api-usage/api-lib-tag-validator.js.map +1 -1
- package/src/lib/api-usage/api-scanner.d.ts +3 -1
- package/src/lib/api-usage/api-scanner.js +6 -3
- package/src/lib/api-usage/api-scanner.js.map +1 -1
- package/src/lib/api-usage/wire-closure.d.ts +49 -0
- package/src/lib/api-usage/wire-closure.js +126 -0
- package/src/lib/api-usage/wire-closure.js.map +1 -0
- package/src/lib/dep-usage-scanner.d.ts +6 -2
- package/src/lib/dep-usage-scanner.js +45 -28
- package/src/lib/dep-usage-scanner.js.map +1 -1
- package/src/lib/di-graph/analyzer-strategy.d.ts +1 -0
- package/src/lib/di-graph/analyzer-strategy.js +3 -0
- package/src/lib/di-graph/analyzer-strategy.js.map +1 -1
- package/src/lib/framework-resolver.d.ts +1 -1
- package/src/lib/framework-resolver.js +5 -2
- package/src/lib/framework-resolver.js.map +1 -1
- package/src/lib/graph-metadata.d.ts +9 -2
- package/src/lib/graph-metadata.js +12 -3
- package/src/lib/graph-metadata.js.map +1 -1
- package/src/lib/graph-visualizer.js +6 -0
- package/src/lib/graph-visualizer.js.map +1 -1
- package/src/lib/role-resolver.d.ts +9 -3
- package/src/lib/role-resolver.js +12 -4
- package/src/lib/role-resolver.js.map +1 -1
- package/src/lib/tag-truth.d.ts +106 -0
- package/src/lib/tag-truth.js +323 -0
- package/src/lib/tag-truth.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-scanner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-scanner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AA2eH,8DAmBC;AAuBD,8CA8CC;AAUD,0EAgBC;AASD,0EAmBC;;AAvnBD,uDAAiC;AACjC,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAyD;AAGzD,iDAA0D;AAC1D,mDAA+D;AAC/D,mDAiByB;AACzB,+DAS+B;AAC/B,uDAAoF;AACpF,mDAA0F;AAC1F,6DAAuD;AACvD,uCAamB;AAEnB,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AAClD,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAsDtC,qGAAqG;AACrG,MAAM,cAAc;IACC,KAAK,CAAgB;IAEtC,YAAY,aAAqB,EAAE,YAAsC;QACrE,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,IAAI,IAAI,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AS,iBAAiB,CAAC,cAAsB;IAC7C,MAAM,UAAU,GAAG,IAAA,6BAAmB,EAAC,cAAc,CAAC,CAAC;IACvD,IAAI,CAAC,UAAU;QAAE,OAAO,mBAAmB,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE;QACnC,mCAAmC,EAAE,GAAS,EAAE,CAAC,SAAS;KAC7D,CAA2B,CAAC;IAC7B,MAAM,MAAM,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;IACzE,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3F,OAAO,mBAAmB,CAAC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/D,CAAC;AAED,wGAAwG;AACxG,SAAS,mBAAmB,CACxB,cAAsB,EACtB,OAA2B;IAE3B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,IAAA,wBAAc,EAAC,MAAM,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC","sourcesContent":["/**\n * API Usage Scanner\n *\n * Derives, by scanning real source (not a declaration file), how every project\n * relates to the api-lib projects it depends on. This is the single source of\n * truth for the `apiRelations` field in architecture/dependencies.json AND for\n * the runtime microservice graph.\n *\n * Signals (all resolved through the TypeScript checker, so re-exports resolve):\n * - IMPLEMENTS: `apiFactory.addRoutes(XxxApi, XxxController)` — the registration\n * that actually SERVES the contract over the wire. We deliberately\n * do NOT use `class Ctrl extends XxxApi`: a class can extend an API\n * as an in-process test double / simulator (e.g. Server2Simulator)\n * without ever serving it — only `addRoutes` proves a served route.\n * - USES: `factory.createRpcClient(XxxApi, ...)` → rpc client\n * `factory.createPubSubClient(XxxApi, ...)` → pubsub (Cloud Tasks) client\n * The config argument (`new ClientConfig('helper-fsdb')`) names WHICH service the\n * client talks to and is kept as `ApiRef.targetService` — see targetServiceOf.\n * An api-lib is DETECTED, not tagged: a project exporting an `abstract class`\n * carrying `@ApiPath` owns that API. Its transport is `@PubSub` → 'pubsub', else 'rpc'.\n *\n * Contracts are indexed from SOURCE in a pre-pass (ApiSourceIndexBuilder) rather than\n * from wherever the checker resolves an import to. A consumer without a tsconfig.base\n * `paths` entry resolves `import { XxxApi } from '@scope/xxx-api'` through node_modules\n * to the package's BUILT `dist/**.d.ts` — and tsc ERASES decorators when emitting\n * declarations, so `@ApiPath` can never be read there. Keying off the resolved\n * declaration therefore dropped whole services from the graph, silently. See\n * `recoverFromDeclaration`.\n */\n\nimport * as ts from 'typescript';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { matchesAnyGlob } from '@webpieces/rules-config';\nimport type { EnhancedGraph } from '../graph-sorter';\nimport { ProjectInfo } from '../project-info';\nimport { findProjectTsconfig } from '../di-graph/program';\nimport { resolveClassDeclaration } from '../di-graph/bindings';\nimport {\n ApiClassInfo,\n ApiContract,\n ApiContracts,\n ApiRef,\n ApiRelation,\n EmptiedApiContract,\n EndpointKind,\n NonLiteralDecoratorArg,\n ProjectApiRelations,\n UndeclaredExternalCaller,\n UndeclaredEndpointOperation,\n UnresolvedApiCall,\n UnresolvedEndpointPath,\n apiRefKey,\n deriveApiRelationKind,\n sortApiRefs,\n} from './api-relations';\nimport {\n ApiRulesForMcpError,\n ApiRulesForOpenApiError,\n EmptiedApiContractError,\n MissingBasePathError,\n RootUnionApiTypeError,\n UndeclaredExternalCallerError,\n UndeclaredEndpointOperationError,\n UnresolvedEndpointPathError,\n} from './api-contract-errors';\nimport { RootUnionFindings, RootUnionRule, RootUnionScan } from './root-union-scan';\nimport { ApiDocRule, ApiDocRulesFindings, MCP_RULE, OPENAPI_RULE } from './api-doc-rules';\nimport { ApiDocRulesScan } from './api-doc-rules-scan';\nimport {\n DecoratorArgDiagnostics,\n apiClassInfoFrom,\n apiClassInfoFromNode,\n calleeMethodName,\n collectTsFiles,\n constructorParamsOf,\n externalApiInfoFrom,\n implementedTypeNames,\n isAbstractClass,\n isTestFile,\n targetServiceOf,\n typeReferenceName,\n} from './api-ast';\n\nconst RPC_CLIENT_METHOD = 'createRpcClient';\nconst PUBSUB_CLIENT_METHOD = 'createPubSubClient';\nconst ADD_ROUTES_METHOD = 'addRoutes';\n\n/** The whole-workspace result of a scan. */\nexport interface ApiScanResult {\n /** projectName -> { apiLibProject -> relation }; only projects with ≥1 relation appear. */\n relationsByProject: Map<string, ProjectApiRelations>;\n /** Every project that owns ≥1 API contract class. */\n apiLibProjects: Set<string>;\n /** apiClassName -> where it lives + its transport. */\n apiIndex: Map<string, ApiClassInfo>;\n /**\n * Projects whose production (non-test) source was actually scanned. A project with only test\n * files (e.g. an e2e harness), or one the compiler couldn't load, is ABSENT — callers must not\n * conclude \"no implements/uses\" for it, because its behavior was never observed.\n */\n scannedProjects: Set<string>;\n /**\n * Call sites naming a contract we could not map back to workspace source. Non-empty means the\n * graph is INCOMPLETE — callers must surface these rather than emit a green, wrong graph.\n */\n unresolvedApiCalls: UnresolvedApiCall[];\n /**\n * Decorator arguments that were present but could not be reduced to a string (a cross-module\n * constant, a computed expression). Each one costs the graph a basePath, a method, or — when it\n * takes out every method of a class — the whole contract, so they must be surfaced.\n */\n nonLiteralDecoratorArgs: NonLiteralDecoratorArg[];\n /**\n * The subset of the above that is FATAL: an `@Endpoint` path that could not be read. Every client\n * builds its URL as `basePath + path`, so this is missing routing, not missing metadata —\n * buildApiContracts throws on a non-empty list rather than shipping a contract without it.\n */\n unresolvedEndpointPaths: UnresolvedEndpointPath[];\n /**\n * Contract classes that declared `@Endpoint` methods and kept none — the exact shape that used to\n * slip out through buildApiContracts' zero-method skip, taking a whole service's queues with it.\n */\n emptiedApiContracts: EmptiedApiContract[];\n /**\n * `external` endpoints that did not say WHO calls them. Fatal: the inbound box on the runtime\n * graph exists to name that system, and with nothing to name it restates our own contract name.\n */\n undeclaredExternalCallers: UndeclaredExternalCaller[];\n /** Endpoints lacking the explicit side-effect contract used for retry safety and MCP hints. */\n undeclaredEndpointOperations: UndeclaredEndpointOperation[];\n /** `no-root-union-api-type`'s findings. Fatal in buildApiContracts — see root-union-scan.ts. */\n rootUnions: RootUnionFindings;\n /**\n * `api-rules-for-openapi` / `api-rules-for-mcp` findings (#1011). Both ship OFF, so this is\n * EMPTY unless a repo stated otherwise — no rule in this framework has a default (#1017).\n */\n apiDocRules: ApiDocRulesFindings;\n}\n\n/** Maps an absolute source-file path to the workspace project that owns it (longest-root-prefix). */\nclass ProjectLocator {\n private readonly roots: ProjectRoot[];\n\n constructor(workspaceRoot: string, projectInfos: Map<string, ProjectInfo>) {\n const roots: ProjectRoot[] = [];\n for (const info of projectInfos.values()) {\n if (info.root === '' || info.root === '.') continue;\n roots.push(new ProjectRoot(info.name, path.resolve(workspaceRoot, info.root)));\n }\n // Longest root first so a nested project wins over its parent.\n this.roots = roots.sort((a: ProjectRoot, b: ProjectRoot) => b.abs.length - a.abs.length);\n }\n\n projectOf(absFile: string): string | null {\n const normalized = path.resolve(absFile);\n for (const root of this.roots) {\n if (normalized === root.abs || normalized.startsWith(root.abs + path.sep))\n return root.name;\n }\n return null;\n }\n}\n\nclass ProjectRoot {\n constructor(\n public readonly name: string,\n public readonly abs: string,\n ) {}\n}\n\n/**\n * Every API contract in the workspace, keyed by class name, read from SOURCE.\n *\n * Name-keyed because a call site only ever gives us a name once its import has resolved into a\n * decorator-erased declaration. Two api-libs exporting the same class name collide (last wins) —\n * the same collision the published `apiIndex` has always had.\n */\nclass ApiSourceIndex {\n constructor(\n public readonly byName: Map<string, ApiClassInfo>,\n public readonly owners: Set<string>,\n ) {}\n\n lookup(api: string): ApiClassInfo | null {\n return this.byName.get(api) ?? null;\n }\n}\n\n/**\n * Builds the ApiSourceIndex by parsing each project's own `src/**` directly.\n *\n * Deliberately parser-only (no ts.Program, no checker): we need the decorators exactly as\n * written, and a plain parse cannot be diverted to a `.d.ts` by module resolution — which is\n * the entire bug this guards against. It is also cheap enough to run over every project.\n */\nclass ApiSourceIndexBuilder {\n private readonly byName = new Map<string, ApiClassInfo>();\n private readonly owners = new Set<string>();\n\n constructor(\n private readonly workspaceRoot: string,\n private readonly projectInfos: Map<string, ProjectInfo>,\n /** Globs of project roots holding vendor contracts — see ExternalApiIndex. */\n private readonly externalApiPaths: readonly string[],\n /** Sink for decorator arguments this parser-only pass cannot reduce to a string. */\n private readonly diagnostics: DecoratorArgDiagnostics,\n ) {}\n\n build(): ApiSourceIndex {\n for (const info of this.projectInfos.values()) {\n if (info.root === '' || info.root === '.') continue;\n this.indexProject(info);\n }\n return new ApiSourceIndex(this.byName, this.owners);\n }\n\n private indexProject(info: ProjectInfo): void {\n const srcDir = path.join(path.resolve(this.workspaceRoot, info.root), 'src');\n if (!fs.existsSync(srcDir)) return;\n const external = matchesAnyGlob(info.root, this.externalApiPaths);\n for (const file of collectTsFiles(srcDir)) {\n if (isTestFile(file)) continue; // tests are not production topology\n const text = fs.readFileSync(file, 'utf8');\n const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);\n this.indexNode(sourceFile, info.name, external);\n }\n }\n\n private indexNode(node: ts.Node, project: string, external: boolean): void {\n const info = external\n ? externalApiInfoFrom(node, project)\n : apiClassInfoFromNode(node, project, this.diagnostics);\n if (info) {\n this.owners.add(project);\n this.byName.set(info.api, info);\n }\n ts.forEachChild(node, (child: ts.Node) => this.indexNode(child, project, external));\n }\n}\n/** Per-owner accumulator that dedupes API refs while a single project is scanned. */\nclass RelationAccumulator {\n private readonly implementsByOwner = new Map<string, Map<string, ApiRef>>();\n private readonly usesByOwner = new Map<string, Map<string, ApiRef>>();\n\n addImplements(owner: string, ref: ApiRef): void {\n ensureRefMap(this.implementsByOwner, owner).set(apiRefKey(ref), ref);\n }\n\n /**\n * Keyed by api + targetService: one project legitimately binds the SAME contract against two\n * different services (a WarmupApi client per data server), and those are two relations, not one.\n */\n addUses(owner: string, ref: ApiRef): void {\n ensureRefMap(this.usesByOwner, owner).set(apiRefKey(ref), ref);\n }\n\n /** Build the deterministic { owner -> relation } record, owners in sorted order. */\n toRelations(): ProjectApiRelations {\n const owners = new Set<string>([\n ...this.implementsByOwner.keys(),\n ...this.usesByOwner.keys(),\n ]);\n const relations: ProjectApiRelations = {};\n for (const owner of [...owners].sort()) {\n const implementsRefs = sortApiRefs([\n ...(this.implementsByOwner.get(owner)?.values() ?? []),\n ]);\n const usesRefs = sortApiRefs([...(this.usesByOwner.get(owner)?.values() ?? [])]);\n const relation: ApiRelation = {\n kind: deriveApiRelationKind(implementsRefs, usesRefs),\n implements: implementsRefs,\n uses: usesRefs,\n };\n relations[owner] = relation;\n }\n return relations;\n }\n\n isEmpty(): boolean {\n return this.implementsByOwner.size === 0 && this.usesByOwner.size === 0;\n }\n}\n\n// webpieces-disable no-function-outside-class -- tiny map helper, matching the AST-helper style of di-graph/bindings.ts\nfunction ensureRefMap(map: Map<string, Map<string, ApiRef>>, owner: string): Map<string, ApiRef> {\n let inner = map.get(owner);\n if (!inner) {\n inner = new Map<string, ApiRef>();\n map.set(owner, inner);\n }\n return inner;\n}\n\n/** Statically scans every project for its api-lib implements/uses relationships. */\nexport class ApiUsageScanner {\n private readonly locator: ProjectLocator;\n private readonly relationsByProject = new Map<string, ProjectApiRelations>();\n private readonly scannedProjects = new Set<string>();\n private readonly unresolvedApiCalls: UnresolvedApiCall[] = [];\n private readonly decoratorArgDiagnostics: DecoratorArgDiagnostics;\n private sourceIndex = new ApiSourceIndex(new Map<string, ApiClassInfo>(), new Set<string>());\n\n constructor(\n private readonly workspaceRoot: string,\n private readonly projectInfos: Map<string, ProjectInfo>,\n /** Globs of project roots whose exported `*Api` types are contracts for outside systems. */\n private readonly externalApiPaths: readonly string[] = [],\n /** `no-root-union-api-type`'s switches — ARMED unless scanAndAttachApiRelations read otherwise. */\n private readonly rootUnionRule: RootUnionRule = RootUnionRule.enabledEverywhere(),\n /** `api-rules-for-openapi`'s switches — read from the config, which MUST state them (#1017). */\n private readonly openApiRule: ApiDocRule = ApiDocRule.off(OPENAPI_RULE),\n /** `api-rules-for-mcp`'s switches — read from the config, which MUST state them (#1017). */\n private readonly mcpRule: ApiDocRule = ApiDocRule.off(MCP_RULE),\n ) {\n this.locator = new ProjectLocator(workspaceRoot, projectInfos);\n this.decoratorArgDiagnostics = new DecoratorArgDiagnostics(workspaceRoot);\n }\n\n scan(): ApiScanResult {\n // Pre-pass: every contract, from source, BEFORE any call site is resolved — a call site in\n // one project routinely names a contract owned by a project we have not walked yet.\n this.sourceIndex = new ApiSourceIndexBuilder(\n this.workspaceRoot,\n this.projectInfos,\n this.externalApiPaths,\n this.decoratorArgDiagnostics,\n ).build();\n for (const info of this.projectInfos.values()) {\n if (info.root === '' || info.root === '.') continue;\n this.scanProject(info);\n }\n return {\n relationsByProject: this.relationsByProject,\n apiLibProjects: this.sourceIndex.owners,\n apiIndex: this.sourceIndex.byName,\n scannedProjects: this.scannedProjects,\n unresolvedApiCalls: this.unresolvedApiCalls,\n nonLiteralDecoratorArgs: this.decoratorArgDiagnostics.all(),\n unresolvedEndpointPaths: this.decoratorArgDiagnostics.unresolvedEndpointPaths(),\n emptiedApiContracts: this.decoratorArgDiagnostics.emptiedContracts(),\n undeclaredExternalCallers: this.decoratorArgDiagnostics.undeclaredExternalCallers(),\n undeclaredEndpointOperations:\n this.decoratorArgDiagnostics.undeclaredEndpointOperations(),\n rootUnions: new RootUnionScan(\n this.workspaceRoot,\n this.projectInfos,\n this.rootUnionRule,\n ).run(),\n apiDocRules: new ApiDocRulesScan(\n this.workspaceRoot,\n this.projectInfos,\n this.openApiRule,\n this.mcpRule,\n ).run(),\n };\n }\n\n private scanProject(info: ProjectInfo): void {\n const program = createScanProgram(path.resolve(this.workspaceRoot, info.root));\n if (!program) return;\n const checker = program.getTypeChecker();\n const accumulator = new RelationAccumulator();\n let scannedProductionFile = false;\n\n for (const sourceFile of program.getSourceFiles()) {\n if (sourceFile.isDeclarationFile || sourceFile.fileName.includes('/node_modules/'))\n continue;\n if (isTestFile(sourceFile.fileName)) continue; // tests are not production topology\n // Only this project's OWN files — imported api-lib source is in the program too.\n if (this.locator.projectOf(sourceFile.fileName) !== info.name) continue;\n scannedProductionFile = true;\n this.visit(sourceFile, checker, info.name, accumulator);\n }\n\n // Record coverage only when we actually saw production source — an all-test project (e2e)\n // stays absent so the validator won't wrongly flag its api-lib deps as unused.\n if (scannedProductionFile) this.scannedProjects.add(info.name);\n if (!accumulator.isEmpty())\n this.relationsByProject.set(info.name, accumulator.toRelations());\n }\n\n private visit(\n node: ts.Node,\n checker: ts.TypeChecker,\n project: string,\n acc: RelationAccumulator,\n ): void {\n // In-repo contract classes are indexed by the source pre-pass, so only calls matter for them.\n if (ts.isCallExpression(node)) this.recordCall(node, checker, project, acc);\n // A VENDOR contract has no client-factory call site to key off — it arrives by injection —\n // so classes have to be inspected too.\n if (ts.isClassDeclaration(node)) this.recordExternalUses(node, acc);\n ts.forEachChild(node, (child: ts.Node) => this.visit(child, checker, project, acc));\n }\n\n /**\n * Record a `uses` for every vendor contract this class receives by CONSTRUCTOR INJECTION —\n * `constructor(@inject(GMAIL_TYPES.GmailApi) private readonly gmail: GmailApi)`.\n *\n * The parameter TYPE is the signal, not the token: a token is an opaque Symbol whose name we\n * would have to guess at, while the type is written right there and is what the class actually\n * calls. Matching happens by name against the external index, so an import that resolves to a\n * built `.d.ts` works exactly as well as one resolving to source.\n *\n * A class that IMPLEMENTS the contract is skipped — that is the vendor adapter (`GmailClient`)\n * or a test double (`InMemoryFirestore`, `MockTts`), which IS the seam rather than a caller of\n * it. Counting those would draw an edge from every service embedding a fake to a vendor it never\n * actually reaches.\n */\n private recordExternalUses(cls: ts.ClassDeclaration, acc: RelationAccumulator): void {\n const implemented = implementedTypeNames(cls);\n for (const param of constructorParamsOf(cls)) {\n const typeName = typeReferenceName(param.type);\n if (typeName === null || implemented.has(typeName)) continue;\n const info = this.sourceIndex.lookup(typeName);\n if (info === null || info.type !== 'external') continue;\n acc.addUses(info.owner, { api: info.api, type: 'external' });\n }\n }\n\n private recordCall(\n call: ts.CallExpression,\n checker: ts.TypeChecker,\n project: string,\n acc: RelationAccumulator,\n ): void {\n const method = calleeMethodName(call);\n if (method === null || call.arguments.length === 0) return;\n if (method === ADD_ROUTES_METHOD) {\n const info = this.apiInfoFromExpr(call.arguments[0], checker, project);\n if (info) acc.addImplements(info.owner, { api: info.api, type: info.type });\n return;\n }\n if (method === RPC_CLIENT_METHOD || method === PUBSUB_CLIENT_METHOD) {\n const info = this.apiInfoFromExpr(call.arguments[0], checker, project);\n if (!info) return;\n // Argument 2 names WHICH service this client talks to. Keeping it is what lets the\n // runtime graph draw ONE edge instead of one per implementer of the contract.\n const targetService = targetServiceOf(call);\n const ref: ApiRef = { api: info.api, type: info.type };\n if (targetService !== null) ref.targetService = targetService;\n acc.addUses(info.owner, ref);\n }\n }\n\n /** Resolve an expression to the API contract it names, or null if it is not one. */\n private apiInfoFromExpr(\n expr: ts.Expression,\n checker: ts.TypeChecker,\n project: string,\n ): ApiClassInfo | null {\n const decl = resolveClassDeclaration(expr, checker);\n if (!decl) return null;\n const fromSource = this.apiClassInfoFor(decl);\n return fromSource ?? this.recoverFromDeclaration(decl, expr, project);\n }\n\n /**\n * The checker landed on a BUILT declaration instead of source — the consumer has no\n * tsconfig.base `paths` entry for the api-lib, so the import went through node_modules to\n * `dist/**.d.ts`. tsc erases decorators when emitting declarations, so `@ApiPath` is simply\n * not there and never will be. Recover the contract by name from the source index; the graph\n * is then correct no matter how the consumer's tsconfig is laid out.\n */\n private recoverFromDeclaration(\n decl: ts.ClassDeclaration,\n expr: ts.Expression,\n project: string,\n ): ApiClassInfo | null {\n // An abstract class is the shape of a contract; a non-abstract argument is genuinely not one.\n if (!decl.getSourceFile().isDeclarationFile || !isAbstractClass(decl) || !decl.name)\n return null;\n const recovered = this.sourceIndex.lookup(decl.name.text);\n if (recovered) return recovered;\n // Abstract, in a .d.ts, yet no workspace source owns it — the scan is blind here. Say so.\n this.unresolvedApiCalls.push(\n new UnresolvedApiCall(\n project,\n decl.name.text,\n this.relativeLocation(expr),\n this.relativePath(decl.getSourceFile().fileName),\n ),\n );\n return null;\n }\n\n /** `path/to/file.ts:LINE` for `node`, workspace-relative, for a human-readable report. */\n private relativeLocation(node: ts.Node): string {\n const sourceFile = node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n return `${this.relativePath(sourceFile.fileName)}:${position.line + 1}`;\n }\n\n private relativePath(absFile: string): string {\n return path.relative(this.workspaceRoot, absFile);\n }\n\n /**\n * {api, owner, type, methods} when `cls` is an `abstract class` carrying `@ApiPath` IN SOURCE,\n * else null. Only the OWNER differs from the index pre-pass — here it comes from the file's\n * location rather than from the project being walked — so the contract test itself is delegated\n * to apiClassInfoFrom, keeping one definition of \"this is a contract\".\n */\n private apiClassInfoFor(cls: ts.ClassDeclaration): ApiClassInfo | null {\n const owner = this.locator.projectOf(cls.getSourceFile().fileName);\n if (owner === null) return null;\n return apiClassInfoFrom(cls, owner);\n }\n}\n\n/**\n * Run the scan and attach the derived `apiRelations` onto each graph entry in\n * place. Shared by `architecture:generate` (which then saves) and\n * `architecture:validate-architecture-unchanged` (which regenerates in memory\n * and must attach the SAME field, or it would see a phantom diff). Returns the\n * full scan so callers (validators, runtime graph) can reuse the api index.\n */\n// webpieces-disable no-function-outside-class -- module entry point, mirrors generateReducedGraph/collectBindings\nexport function scanAndAttachApiRelations(\n workspaceRoot: string,\n graph: EnhancedGraph,\n projectInfos: Map<string, ProjectInfo>,\n externalApiPaths: readonly string[] = [],\n): ApiScanResult {\n const result = new ApiUsageScanner(\n workspaceRoot,\n projectInfos,\n externalApiPaths,\n RootUnionRule.fromConfig(workspaceRoot),\n ApiDocRule.fromConfig(workspaceRoot, OPENAPI_RULE),\n ApiDocRule.fromConfig(workspaceRoot, MCP_RULE),\n ).scan();\n for (const projectName of result.relationsByProject.keys()) {\n const entry = graph[projectName];\n if (entry) entry.apiRelations = result.relationsByProject.get(projectName);\n }\n return result;\n}\n\n/**\n * The committed api contract table (one `architecture/apis/<ApiName>.json` per entry), from a\n * completed scan.\n *\n * Only contracts with ≥1 endpoint are emitted: a vendor seam has no routes, so a table entry for it\n * would be an empty shell, and its identity is already carried by the `external` refs in\n * apiRelations. Sorted by api name, methods left in declaration order, so the file is deterministic.\n *\n * THROWS on the ways an entry can be wrong-but-green, checked root cause first:\n * 1. an `@Endpoint` path the scan could not read (UnresolvedEndpointPathError) — the other half of\n * the URL a consumer computes, and the cause of most emptied contracts;\n * 2. a class that declared endpoints and kept none (EmptiedApiContractError), which would otherwise\n * leave silently through the zero-method skip above;\n * 3. a method without an explicit operation (UndeclaredEndpointOperationError);\n * 4. an `external` method that never said WHO calls it (UndeclaredExternalCallerError);\n * 5. a routed contract with no basePath (MissingBasePathError).\n * All are worse than an absent entry: a consumer joining `basePath + path` computes a\n * confidently wrong URL with no signal that anything is off, because every other entry is complete.\n * Each error aggregates EVERY offender, so a developer fixing five constants sees five in one run.\n */\n// webpieces-disable no-function-outside-class -- module entry point, mirrors scanAndAttachApiRelations\nexport function buildApiContracts(scan: ApiScanResult): ApiContracts {\n // Root cause before symptom: an unreadable path is what empties a contract, so naming the paths\n // is what the author can actually act on.\n if (scan.unresolvedEndpointPaths.length > 0)\n throw new UnresolvedEndpointPathError(scan.unresolvedEndpointPaths);\n if (scan.emptiedApiContracts.length > 0)\n throw new EmptiedApiContractError(scan.emptiedApiContracts);\n if (scan.undeclaredEndpointOperations.length > 0) {\n throw new UndeclaredEndpointOperationError(scan.undeclaredEndpointOperations);\n }\n // A shape no function-calling API will accept, read perfectly well — unlike the four above, which\n // are contracts the scan could not READ at all.\n if (!scan.rootUnions.isEmpty()) throw new RootUnionApiTypeError(scan.rootUnions);\n // Contract shapes that are not PUBLISHABLE, read by the generator's own extractor (#1011).\n // After the root union, which is the one shape no function-calling API will accept at all, and\n // before the caller checks below, which are about the architecture graph rather than a document.\n if (!scan.apiDocRules.openApi.isEmpty()) {\n throw new ApiRulesForOpenApiError(scan.apiDocRules.openApi);\n }\n if (!scan.apiDocRules.mcp.isEmpty()) {\n throw new ApiRulesForMcpError(scan.apiDocRules.mcp, scan.apiDocRules.mcpExclusions);\n }\n // After the two above: an unreadable path is what empties a contract, and a contract that lost\n // every method has no external endpoint left to complain about.\n if (scan.undeclaredExternalCallers.length > 0) {\n throw new UndeclaredExternalCallerError(scan.undeclaredExternalCallers);\n }\n const contracts: ApiContracts = {};\n const missing: string[] = [];\n for (const api of [...scan.apiIndex.keys()].sort()) {\n const info = scan.apiIndex.get(api)!;\n if (info.methods.length === 0) continue;\n if (info.basePath === undefined) {\n missing.push(`${api} (owner ${info.owner})`);\n continue;\n }\n const contract: ApiContract = {\n owner: info.owner,\n apiKind: info.type,\n basePath: info.basePath,\n methods: info.methods,\n };\n contracts[api] = contract;\n }\n if (missing.length > 0) throw new MissingBasePathError(missing);\n return contracts;\n}\n\n/**\n * Loud, actionable report for decorator arguments the scan could not reduce to a string.\n *\n * Same-module constants resolve, so anything reaching here is genuinely out of reach of a\n * parser-only pass — and every one of them silently shrinks the graph. Empty string when there is\n * nothing to say, so callers can test it without special-casing.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnresolvedApiCalls\nexport function describeNonLiteralDecoratorArgs(args: readonly NonLiteralDecoratorArg[]): string {\n if (args.length === 0) return '';\n const lines = [\n `⚠️ ${args.length} decorator argument(s) are not string literals and could not be resolved.`,\n ` Each one drops data from the graph: a missing basePath, a missing method, or a whole contract:`,\n ];\n for (const arg of args) {\n const where = arg.method === null ? arg.api : `${arg.api}.${arg.method}`;\n lines.push(` • @${arg.decorator}(${arg.argument}) on ${where} at ${arg.at}`);\n }\n lines.push(\n ` A constant declared in the SAME module resolves. One imported from another module does not —`,\n ` this scan is parser-only by design (module resolution can land on a decorator-erased .d.ts).`,\n ` Fix by inlining the string literal, or by moving the constant into the contract's own module.`,\n );\n return lines.join('\\n');\n}\n\n/**\n * Every contract method whose declared @Endpoint kind its api kind cannot deliver — an rpc method on\n * a @PubSub contract (nothing calls a queue synchronously), or a cloudtasks/cron method on an @Rpc\n * contract (naming a queue or schedule nothing could deliver to). Mirrors core-util's\n * ENDPOINT_KINDS_BY_API_KIND at BUILD time, where it can name the file instead of throwing at wiring.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnresolvedApiCalls\nexport function describeMismatchedEndpointKinds(contracts: ApiContracts): string[] {\n const allowedByKind: Record<string, readonly EndpointKind[]> = {\n rpc: ['rpc', 'external'],\n pubsub: ['cloudtasks', 'cron', 'external'],\n };\n const problems: string[] = [];\n for (const api of Object.keys(contracts)) {\n const contract = contracts[api];\n const allowed = allowedByKind[contract.apiKind];\n if (allowed === undefined) continue;\n for (const method of contract.methods) {\n if (allowed.includes(method.kind)) continue;\n problems.push(\n `${api}.${method.name} declares @Endpoint(${method.httpMethod ?? 'POST'}, '${method.path}', ${method.operation}, ${method.kind}) but ${api} is ` +\n `@${contract.apiKind === 'pubsub' ? 'PubSub' : 'Rpc'} — allowed kinds are ${allowed.join(' | ')}.`,\n );\n }\n }\n return problems;\n}\n\n/**\n * Build a program for scanning ONE project. Prefers the project's compile tsconfig; but when that\n * is a solution-style tsconfig (only `references`, no `files`/`include` — e.g. legacy-server), it\n * yields zero files, so we fall back to globbing the project's own `src/**` and reuse the resolved\n * compiler options (which carry tsconfig.base `paths` for cross-package @webpieces resolution).\n *\n * `paths` is a PREFERENCE, not a precondition: it lets imports resolve straight to source. Without\n * it they land on a decorator-erased `dist/**.d.ts`, which the source index recovers from — see\n * ApiUsageScanner.recoverFromDeclaration.\n */\n// webpieces-disable no-function-outside-class -- ts Program factory, mirrors di-graph/program.ts\nfunction createScanProgram(projectRootAbs: string): ts.Program | null {\n const configPath = findProjectTsconfig(projectRootAbs);\n if (!configPath) return buildProgramFromSrc(projectRootAbs, {});\n const host = Object.assign({}, ts.sys, {\n onUnRecoverableConfigFileDiagnostic: (): void => undefined,\n }) as ts.ParseConfigFileHost;\n const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, host);\n if (!parsed) return null;\n if (parsed.fileNames.length > 0) return ts.createProgram(parsed.fileNames, parsed.options);\n return buildProgramFromSrc(projectRootAbs, parsed.options);\n}\n\n// webpieces-disable no-function-outside-class -- ts Program factory helper, mirrors di-graph/program.ts\nfunction buildProgramFromSrc(\n projectRootAbs: string,\n options: ts.CompilerOptions,\n): ts.Program | null {\n const srcDir = path.join(projectRootAbs, 'src');\n if (!fs.existsSync(srcDir)) return null;\n const files = collectTsFiles(srcDir);\n return files.length > 0 ? ts.createProgram(files, options) : null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api-scanner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-scanner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AA6eH,8DAoBC;AAuBD,8CA8CC;AAUD,0EAgBC;AASD,0EAmBC;;AA1nBD,uDAAiC;AACjC,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAyD;AAGzD,iDAA0D;AAC1D,mDAA+D;AAC/D,mDAiByB;AACzB,+DAS+B;AAC/B,uDAAoF;AACpF,mDAA0F;AAC1F,6DAAuD;AACvD,iDAAiD;AACjD,uCAamB;AAEnB,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,oBAAoB,GAAG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,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,IAAA,wBAAc,EAAC,MAAM,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC","sourcesContent":["/**\n * API Usage Scanner\n *\n * Derives, by scanning real source (not a declaration file), how every project\n * relates to the api-lib projects it depends on. This is the single source of\n * truth for the `apiRelations` field in architecture/dependencies.json AND for\n * the runtime microservice graph.\n *\n * Signals (all resolved through the TypeScript checker, so re-exports resolve):\n * - IMPLEMENTS: `apiFactory.addRoutes(XxxApi, XxxController)` — the registration\n * that actually SERVES the contract over the wire. We deliberately\n * do NOT use `class Ctrl extends XxxApi`: a class can extend an API\n * as an in-process test double / simulator (e.g. Server2Simulator)\n * without ever serving it — only `addRoutes` proves a served route.\n * - USES: `factory.createRpcClient(XxxApi, ...)` → rpc client\n * `factory.createPubSubClient(XxxApi, ...)` → pubsub (Cloud Tasks) client\n * The config argument (`new ClientConfig('helper-fsdb')`) names WHICH service the\n * client talks to and is kept as `ApiRef.targetService` — see targetServiceOf.\n * An api-lib is DETECTED, not tagged: a project exporting an `abstract class`\n * carrying `@ApiPath` owns that API. Its transport is `@PubSub` → 'pubsub', else 'rpc'.\n *\n * Contracts are indexed from SOURCE in a pre-pass (ApiSourceIndexBuilder) rather than\n * from wherever the checker resolves an import to. A consumer without a tsconfig.base\n * `paths` entry resolves `import { XxxApi } from '@scope/xxx-api'` through node_modules\n * to the package's BUILT `dist/**.d.ts` — and tsc ERASES decorators when emitting\n * declarations, so `@ApiPath` can never be read there. Keying off the resolved\n * declaration therefore dropped whole services from the graph, silently. See\n * `recoverFromDeclaration`.\n */\n\nimport * as ts from 'typescript';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { matchesAnyGlob } from '@webpieces/rules-config';\nimport type { EnhancedGraph } from '../graph-sorter';\nimport { ProjectInfo } from '../project-info';\nimport { findProjectTsconfig } from '../di-graph/program';\nimport { resolveClassDeclaration } from '../di-graph/bindings';\nimport {\n ApiClassInfo,\n ApiContract,\n ApiContracts,\n ApiRef,\n ApiRelation,\n EmptiedApiContract,\n EndpointKind,\n NonLiteralDecoratorArg,\n ProjectApiRelations,\n UndeclaredExternalCaller,\n UndeclaredEndpointOperation,\n UnresolvedApiCall,\n UnresolvedEndpointPath,\n apiRefKey,\n deriveApiRelationKind,\n sortApiRefs,\n} from './api-relations';\nimport {\n ApiRulesForMcpError,\n ApiRulesForOpenApiError,\n EmptiedApiContractError,\n MissingBasePathError,\n RootUnionApiTypeError,\n UndeclaredExternalCallerError,\n UndeclaredEndpointOperationError,\n UnresolvedEndpointPathError,\n} from './api-contract-errors';\nimport { RootUnionFindings, RootUnionRule, RootUnionScan } from './root-union-scan';\nimport { ApiDocRule, ApiDocRulesFindings, MCP_RULE, OPENAPI_RULE } from './api-doc-rules';\nimport { ApiDocRulesScan } from './api-doc-rules-scan';\nimport { WireClosureRule } from './wire-closure';\nimport {\n DecoratorArgDiagnostics,\n apiClassInfoFrom,\n apiClassInfoFromNode,\n calleeMethodName,\n collectTsFiles,\n constructorParamsOf,\n externalApiInfoFrom,\n implementedTypeNames,\n isAbstractClass,\n isTestFile,\n targetServiceOf,\n typeReferenceName,\n} from './api-ast';\n\nconst RPC_CLIENT_METHOD = 'createRpcClient';\nconst PUBSUB_CLIENT_METHOD = 'createPubSubClient';\nconst ADD_ROUTES_METHOD = 'addRoutes';\n\n/** The whole-workspace result of a scan. */\nexport interface ApiScanResult {\n /** projectName -> { apiLibProject -> relation }; only projects with ≥1 relation appear. */\n relationsByProject: Map<string, ProjectApiRelations>;\n /** Every project that owns ≥1 API contract class. */\n apiLibProjects: Set<string>;\n /** apiClassName -> where it lives + its transport. */\n apiIndex: Map<string, ApiClassInfo>;\n /**\n * Projects whose production (non-test) source was actually scanned. A project with only test\n * files (e.g. an e2e harness), or one the compiler couldn't load, is ABSENT — callers must not\n * conclude \"no implements/uses\" for it, because its behavior was never observed.\n */\n scannedProjects: Set<string>;\n /**\n * Call sites naming a contract we could not map back to workspace source. Non-empty means the\n * graph is INCOMPLETE — callers must surface these rather than emit a green, wrong graph.\n */\n unresolvedApiCalls: UnresolvedApiCall[];\n /**\n * Decorator arguments that were present but could not be reduced to a string (a cross-module\n * constant, a computed expression). Each one costs the graph a basePath, a method, or — when it\n * takes out every method of a class — the whole contract, so they must be surfaced.\n */\n nonLiteralDecoratorArgs: NonLiteralDecoratorArg[];\n /**\n * The subset of the above that is FATAL: an `@Endpoint` path that could not be read. Every client\n * builds its URL as `basePath + path`, so this is missing routing, not missing metadata —\n * buildApiContracts throws on a non-empty list rather than shipping a contract without it.\n */\n unresolvedEndpointPaths: UnresolvedEndpointPath[];\n /**\n * Contract classes that declared `@Endpoint` methods and kept none — the exact shape that used to\n * slip out through buildApiContracts' zero-method skip, taking a whole service's queues with it.\n */\n emptiedApiContracts: EmptiedApiContract[];\n /**\n * `external` endpoints that did not say WHO calls them. Fatal: the inbound box on the runtime\n * graph exists to name that system, and with nothing to name it restates our own contract name.\n */\n undeclaredExternalCallers: UndeclaredExternalCaller[];\n /** Endpoints lacking the explicit side-effect contract used for retry safety and MCP hints. */\n undeclaredEndpointOperations: UndeclaredEndpointOperation[];\n /** `no-root-union-api-type`'s findings. Fatal in buildApiContracts — see root-union-scan.ts. */\n rootUnions: RootUnionFindings;\n /**\n * `api-rules-for-openapi` / `api-rules-for-mcp` findings (#1011). Both ship OFF, so this is\n * EMPTY unless a repo stated otherwise — no rule in this framework has a default (#1017).\n */\n apiDocRules: ApiDocRulesFindings;\n}\n\n/** Maps an absolute source-file path to the workspace project that owns it (longest-root-prefix). */\nclass ProjectLocator {\n private readonly roots: ProjectRoot[];\n\n constructor(workspaceRoot: string, projectInfos: Map<string, ProjectInfo>) {\n const roots: ProjectRoot[] = [];\n for (const info of projectInfos.values()) {\n if (info.root === '' || info.root === '.') continue;\n roots.push(new ProjectRoot(info.name, path.resolve(workspaceRoot, info.root)));\n }\n // Longest root first so a nested project wins over its parent.\n this.roots = roots.sort((a: ProjectRoot, b: ProjectRoot) => b.abs.length - a.abs.length);\n }\n\n projectOf(absFile: string): string | null {\n const normalized = path.resolve(absFile);\n for (const root of this.roots) {\n if (normalized === root.abs || normalized.startsWith(root.abs + path.sep))\n return root.name;\n }\n return null;\n }\n}\n\nclass ProjectRoot {\n constructor(\n public readonly name: string,\n public readonly abs: string,\n ) {}\n}\n\n/**\n * Every API contract in the workspace, keyed by class name, read from SOURCE.\n *\n * Name-keyed because a call site only ever gives us a name once its import has resolved into a\n * decorator-erased declaration. Two api-libs exporting the same class name collide (last wins) —\n * the same collision the published `apiIndex` has always had.\n */\nclass ApiSourceIndex {\n constructor(\n public readonly byName: Map<string, ApiClassInfo>,\n public readonly owners: Set<string>,\n ) {}\n\n lookup(api: string): ApiClassInfo | null {\n return this.byName.get(api) ?? null;\n }\n}\n\n/**\n * Builds the ApiSourceIndex by parsing each project's own `src/**` directly.\n *\n * Deliberately parser-only (no ts.Program, no checker): we need the decorators exactly as\n * written, and a plain parse cannot be diverted to a `.d.ts` by module resolution — which is\n * the entire bug this guards against. It is also cheap enough to run over every project.\n */\nclass ApiSourceIndexBuilder {\n private readonly byName = new Map<string, ApiClassInfo>();\n private readonly owners = new Set<string>();\n\n constructor(\n private readonly workspaceRoot: string,\n private readonly projectInfos: Map<string, ProjectInfo>,\n /** Globs of project roots holding vendor contracts — see ExternalApiIndex. */\n private readonly externalApiPaths: readonly string[],\n /** Sink for decorator arguments this parser-only pass cannot reduce to a string. */\n private readonly diagnostics: DecoratorArgDiagnostics,\n ) {}\n\n build(): ApiSourceIndex {\n for (const info of this.projectInfos.values()) {\n if (info.root === '' || info.root === '.') continue;\n this.indexProject(info);\n }\n return new ApiSourceIndex(this.byName, this.owners);\n }\n\n private indexProject(info: ProjectInfo): void {\n const srcDir = path.join(path.resolve(this.workspaceRoot, info.root), 'src');\n if (!fs.existsSync(srcDir)) return;\n const external = matchesAnyGlob(info.root, this.externalApiPaths);\n for (const file of collectTsFiles(srcDir)) {\n if (isTestFile(file)) continue; // tests are not production topology\n const text = fs.readFileSync(file, 'utf8');\n const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);\n this.indexNode(sourceFile, info.name, external);\n }\n }\n\n private indexNode(node: ts.Node, project: string, external: boolean): void {\n const info = external\n ? externalApiInfoFrom(node, project)\n : apiClassInfoFromNode(node, project, this.diagnostics);\n if (info) {\n this.owners.add(project);\n this.byName.set(info.api, info);\n }\n ts.forEachChild(node, (child: ts.Node) => this.indexNode(child, project, external));\n }\n}\n/** Per-owner accumulator that dedupes API refs while a single project is scanned. */\nclass RelationAccumulator {\n private readonly implementsByOwner = new Map<string, Map<string, ApiRef>>();\n private readonly usesByOwner = new Map<string, Map<string, ApiRef>>();\n\n addImplements(owner: string, ref: ApiRef): void {\n ensureRefMap(this.implementsByOwner, owner).set(apiRefKey(ref), ref);\n }\n\n /**\n * Keyed by api + targetService: one project legitimately binds the SAME contract against two\n * different services (a WarmupApi client per data server), and those are two relations, not one.\n */\n addUses(owner: string, ref: ApiRef): void {\n ensureRefMap(this.usesByOwner, owner).set(apiRefKey(ref), ref);\n }\n\n /** Build the deterministic { owner -> relation } record, owners in sorted order. */\n toRelations(): ProjectApiRelations {\n const owners = new Set<string>([\n ...this.implementsByOwner.keys(),\n ...this.usesByOwner.keys(),\n ]);\n const relations: ProjectApiRelations = {};\n for (const owner of [...owners].sort()) {\n const implementsRefs = sortApiRefs([\n ...(this.implementsByOwner.get(owner)?.values() ?? []),\n ]);\n const usesRefs = sortApiRefs([...(this.usesByOwner.get(owner)?.values() ?? [])]);\n const relation: ApiRelation = {\n kind: deriveApiRelationKind(implementsRefs, usesRefs),\n implements: implementsRefs,\n uses: usesRefs,\n };\n relations[owner] = relation;\n }\n return relations;\n }\n\n isEmpty(): boolean {\n return this.implementsByOwner.size === 0 && this.usesByOwner.size === 0;\n }\n}\n\n// webpieces-disable no-function-outside-class -- tiny map helper, matching the AST-helper style of di-graph/bindings.ts\nfunction ensureRefMap(map: Map<string, Map<string, ApiRef>>, owner: string): Map<string, ApiRef> {\n let inner = map.get(owner);\n if (!inner) {\n inner = new Map<string, ApiRef>();\n map.set(owner, inner);\n }\n return inner;\n}\n\n/** Statically scans every project for its api-lib implements/uses relationships. */\nexport class ApiUsageScanner {\n private readonly locator: ProjectLocator;\n private readonly relationsByProject = new Map<string, ProjectApiRelations>();\n private readonly scannedProjects = new Set<string>();\n private readonly unresolvedApiCalls: UnresolvedApiCall[] = [];\n private readonly decoratorArgDiagnostics: DecoratorArgDiagnostics;\n private sourceIndex = new ApiSourceIndex(new Map<string, ApiClassInfo>(), new Set<string>());\n\n constructor(\n private readonly workspaceRoot: string,\n private readonly projectInfos: Map<string, ProjectInfo>,\n /** Globs of project roots whose exported `*Api` types are contracts for outside systems. */\n private readonly externalApiPaths: readonly string[] = [],\n /** `no-root-union-api-type`'s switches — ARMED unless scanAndAttachApiRelations read otherwise. */\n private readonly rootUnionRule: RootUnionRule = RootUnionRule.enabledEverywhere(),\n /** `api-rules-for-openapi`'s switches — read from the config, which MUST state them (#1017). */\n private readonly openApiRule: ApiDocRule = ApiDocRule.off(OPENAPI_RULE),\n /** `api-rules-for-mcp`'s switches — read from the config, which MUST state them (#1017). */\n private readonly mcpRule: ApiDocRule = ApiDocRule.off(MCP_RULE),\n private readonly wireClosureRule: WireClosureRule = WireClosureRule.withoutSuffixes(), // #1064 D4\n ) {\n this.locator = new ProjectLocator(workspaceRoot, projectInfos);\n this.decoratorArgDiagnostics = new DecoratorArgDiagnostics(workspaceRoot);\n }\n\n scan(): ApiScanResult {\n // Pre-pass: every contract, from source, BEFORE any call site is resolved — a call site in\n // one project routinely names a contract owned by a project we have not walked yet.\n this.sourceIndex = new ApiSourceIndexBuilder(\n this.workspaceRoot,\n this.projectInfos,\n this.externalApiPaths,\n this.decoratorArgDiagnostics,\n ).build();\n for (const info of this.projectInfos.values()) {\n if (info.root === '' || info.root === '.') continue;\n this.scanProject(info);\n }\n return {\n relationsByProject: this.relationsByProject,\n apiLibProjects: this.sourceIndex.owners,\n apiIndex: this.sourceIndex.byName,\n scannedProjects: this.scannedProjects,\n unresolvedApiCalls: this.unresolvedApiCalls,\n nonLiteralDecoratorArgs: this.decoratorArgDiagnostics.all(),\n unresolvedEndpointPaths: this.decoratorArgDiagnostics.unresolvedEndpointPaths(),\n emptiedApiContracts: this.decoratorArgDiagnostics.emptiedContracts(),\n undeclaredExternalCallers: this.decoratorArgDiagnostics.undeclaredExternalCallers(),\n undeclaredEndpointOperations:\n this.decoratorArgDiagnostics.undeclaredEndpointOperations(),\n rootUnions: new RootUnionScan(\n this.workspaceRoot,\n this.projectInfos,\n this.rootUnionRule,\n ).run(),\n apiDocRules: new ApiDocRulesScan(\n this.workspaceRoot,\n this.projectInfos,\n this.openApiRule,\n this.mcpRule, this.wireClosureRule,\n ).run(),\n };\n }\n\n private scanProject(info: ProjectInfo): void {\n const program = createScanProgram(path.resolve(this.workspaceRoot, info.root));\n if (!program) return;\n const checker = program.getTypeChecker();\n const accumulator = new RelationAccumulator();\n let scannedProductionFile = false;\n\n for (const sourceFile of program.getSourceFiles()) {\n if (sourceFile.isDeclarationFile || sourceFile.fileName.includes('/node_modules/'))\n continue;\n if (isTestFile(sourceFile.fileName)) continue; // tests are not production topology\n // Only this project's OWN files — imported api-lib source is in the program too.\n if (this.locator.projectOf(sourceFile.fileName) !== info.name) continue;\n scannedProductionFile = true;\n this.visit(sourceFile, checker, info.name, accumulator);\n }\n\n // Record coverage only when we actually saw production source — an all-test project (e2e)\n // stays absent so the validator won't wrongly flag its api-lib deps as unused.\n if (scannedProductionFile) this.scannedProjects.add(info.name);\n if (!accumulator.isEmpty())\n this.relationsByProject.set(info.name, accumulator.toRelations());\n }\n\n private visit(\n node: ts.Node,\n checker: ts.TypeChecker,\n project: string,\n acc: RelationAccumulator,\n ): void {\n // In-repo contract classes are indexed by the source pre-pass, so only calls matter for them.\n if (ts.isCallExpression(node)) this.recordCall(node, checker, project, acc);\n // A VENDOR contract has no client-factory call site to key off — it arrives by injection —\n // so classes have to be inspected too.\n if (ts.isClassDeclaration(node)) this.recordExternalUses(node, acc);\n ts.forEachChild(node, (child: ts.Node) => this.visit(child, checker, project, acc));\n }\n\n /**\n * Record a `uses` for every vendor contract this class receives by CONSTRUCTOR INJECTION —\n * `constructor(@inject(GMAIL_TYPES.GmailApi) private readonly gmail: GmailApi)`.\n *\n * The parameter TYPE is the signal, not the token: a token is an opaque Symbol whose name we\n * would have to guess at, while the type is written right there and is what the class actually\n * calls. Matching happens by name against the external index, so an import that resolves to a\n * built `.d.ts` works exactly as well as one resolving to source.\n *\n * A class that IMPLEMENTS the contract is skipped — that is the vendor adapter (`GmailClient`)\n * or a test double (`InMemoryFirestore`, `MockTts`), which IS the seam rather than a caller of\n * it. Counting those would draw an edge from every service embedding a fake to a vendor it never\n * actually reaches.\n */\n private recordExternalUses(cls: ts.ClassDeclaration, acc: RelationAccumulator): void {\n const implemented = implementedTypeNames(cls);\n for (const param of constructorParamsOf(cls)) {\n const typeName = typeReferenceName(param.type);\n if (typeName === null || implemented.has(typeName)) continue;\n const info = this.sourceIndex.lookup(typeName);\n if (info === null || info.type !== 'external') continue;\n acc.addUses(info.owner, { api: info.api, type: 'external' });\n }\n }\n\n private recordCall(\n call: ts.CallExpression,\n checker: ts.TypeChecker,\n project: string,\n acc: RelationAccumulator,\n ): void {\n const method = calleeMethodName(call);\n if (method === null || call.arguments.length === 0) return;\n if (method === ADD_ROUTES_METHOD) {\n const info = this.apiInfoFromExpr(call.arguments[0], checker, project);\n if (info) acc.addImplements(info.owner, { api: info.api, type: info.type });\n return;\n }\n if (method === RPC_CLIENT_METHOD || method === PUBSUB_CLIENT_METHOD) {\n const info = this.apiInfoFromExpr(call.arguments[0], checker, project);\n if (!info) return;\n // Argument 2 names WHICH service this client talks to. Keeping it is what lets the\n // runtime graph draw ONE edge instead of one per implementer of the contract.\n const targetService = targetServiceOf(call);\n const ref: ApiRef = { api: info.api, type: info.type };\n if (targetService !== null) ref.targetService = targetService;\n acc.addUses(info.owner, ref);\n }\n }\n\n /** Resolve an expression to the API contract it names, or null if it is not one. */\n private apiInfoFromExpr(\n expr: ts.Expression,\n checker: ts.TypeChecker,\n project: string,\n ): ApiClassInfo | null {\n const decl = resolveClassDeclaration(expr, checker);\n if (!decl) return null;\n const fromSource = this.apiClassInfoFor(decl);\n return fromSource ?? this.recoverFromDeclaration(decl, expr, project);\n }\n\n /**\n * The checker landed on a BUILT declaration instead of source — the consumer has no\n * tsconfig.base `paths` entry for the api-lib, so the import went through node_modules to\n * `dist/**.d.ts`. tsc erases decorators when emitting declarations, so `@ApiPath` is simply\n * not there and never will be. Recover the contract by name from the source index; the graph\n * is then correct no matter how the consumer's tsconfig is laid out.\n */\n private recoverFromDeclaration(\n decl: ts.ClassDeclaration,\n expr: ts.Expression,\n project: string,\n ): ApiClassInfo | null {\n // An abstract class is the shape of a contract; a non-abstract argument is genuinely not one.\n if (!decl.getSourceFile().isDeclarationFile || !isAbstractClass(decl) || !decl.name)\n return null;\n const recovered = this.sourceIndex.lookup(decl.name.text);\n if (recovered) return recovered;\n // Abstract, in a .d.ts, yet no workspace source owns it — the scan is blind here. Say so.\n this.unresolvedApiCalls.push(\n new UnresolvedApiCall(\n project,\n decl.name.text,\n this.relativeLocation(expr),\n this.relativePath(decl.getSourceFile().fileName),\n ),\n );\n return null;\n }\n\n /** `path/to/file.ts:LINE` for `node`, workspace-relative, for a human-readable report. */\n private relativeLocation(node: ts.Node): string {\n const sourceFile = node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n return `${this.relativePath(sourceFile.fileName)}:${position.line + 1}`;\n }\n\n private relativePath(absFile: string): string {\n return path.relative(this.workspaceRoot, absFile);\n }\n\n /**\n * {api, owner, type, methods} when `cls` is an `abstract class` carrying `@ApiPath` IN SOURCE,\n * else null. Only the OWNER differs from the index pre-pass — here it comes from the file's\n * location rather than from the project being walked — so the contract test itself is delegated\n * to apiClassInfoFrom, keeping one definition of \"this is a contract\".\n */\n private apiClassInfoFor(cls: ts.ClassDeclaration): ApiClassInfo | null {\n const owner = this.locator.projectOf(cls.getSourceFile().fileName);\n if (owner === null) return null;\n return apiClassInfoFrom(cls, owner);\n }\n}\n\n/**\n * Run the scan and attach the derived `apiRelations` onto each graph entry in\n * place. Shared by `architecture:generate` (which then saves) and\n * `architecture:validate-architecture-unchanged` (which regenerates in memory\n * and must attach the SAME field, or it would see a phantom diff). Returns the\n * full scan so callers (validators, runtime graph) can reuse the api index.\n */\n// webpieces-disable no-function-outside-class -- module entry point, mirrors generateReducedGraph/collectBindings\nexport function scanAndAttachApiRelations(\n workspaceRoot: string,\n graph: EnhancedGraph,\n projectInfos: Map<string, ProjectInfo>,\n externalApiPaths: readonly string[] = [],\n): ApiScanResult {\n const result = new ApiUsageScanner(\n workspaceRoot,\n projectInfos,\n externalApiPaths,\n RootUnionRule.fromConfig(workspaceRoot),\n ApiDocRule.fromConfig(workspaceRoot, OPENAPI_RULE),\n ApiDocRule.fromConfig(workspaceRoot, MCP_RULE),\n WireClosureRule.fromConfig(workspaceRoot),\n ).scan();\n for (const projectName of result.relationsByProject.keys()) {\n const entry = graph[projectName];\n if (entry) entry.apiRelations = result.relationsByProject.get(projectName);\n }\n return result;\n}\n\n/**\n * The committed api contract table (one `architecture/apis/<ApiName>.json` per entry), from a\n * completed scan.\n *\n * Only contracts with ≥1 endpoint are emitted: a vendor seam has no routes, so a table entry for it\n * would be an empty shell, and its identity is already carried by the `external` refs in\n * apiRelations. Sorted by api name, methods left in declaration order, so the file is deterministic.\n *\n * THROWS on the ways an entry can be wrong-but-green, checked root cause first:\n * 1. an `@Endpoint` path the scan could not read (UnresolvedEndpointPathError) — the other half of\n * the URL a consumer computes, and the cause of most emptied contracts;\n * 2. a class that declared endpoints and kept none (EmptiedApiContractError), which would otherwise\n * leave silently through the zero-method skip above;\n * 3. a method without an explicit operation (UndeclaredEndpointOperationError);\n * 4. an `external` method that never said WHO calls it (UndeclaredExternalCallerError);\n * 5. a routed contract with no basePath (MissingBasePathError).\n * All are worse than an absent entry: a consumer joining `basePath + path` computes a\n * confidently wrong URL with no signal that anything is off, because every other entry is complete.\n * Each error aggregates EVERY offender, so a developer fixing five constants sees five in one run.\n */\n// webpieces-disable no-function-outside-class -- module entry point, mirrors scanAndAttachApiRelations\nexport function buildApiContracts(scan: ApiScanResult): ApiContracts {\n // Root cause before symptom: an unreadable path is what empties a contract, so naming the paths\n // is what the author can actually act on.\n if (scan.unresolvedEndpointPaths.length > 0)\n throw new UnresolvedEndpointPathError(scan.unresolvedEndpointPaths);\n if (scan.emptiedApiContracts.length > 0)\n throw new EmptiedApiContractError(scan.emptiedApiContracts);\n if (scan.undeclaredEndpointOperations.length > 0) {\n throw new UndeclaredEndpointOperationError(scan.undeclaredEndpointOperations);\n }\n // A shape no function-calling API will accept, read perfectly well — unlike the four above, which\n // are contracts the scan could not READ at all.\n if (!scan.rootUnions.isEmpty()) throw new RootUnionApiTypeError(scan.rootUnions);\n // Contract shapes that are not PUBLISHABLE, read by the generator's own extractor (#1011).\n // After the root union, which is the one shape no function-calling API will accept at all, and\n // before the caller checks below, which are about the architecture graph rather than a document.\n if (!scan.apiDocRules.openApi.isEmpty()) {\n throw new ApiRulesForOpenApiError(scan.apiDocRules.openApi);\n }\n if (!scan.apiDocRules.mcp.isEmpty()) {\n throw new ApiRulesForMcpError(scan.apiDocRules.mcp, scan.apiDocRules.mcpExclusions);\n }\n // After the two above: an unreadable path is what empties a contract, and a contract that lost\n // every method has no external endpoint left to complain about.\n if (scan.undeclaredExternalCallers.length > 0) {\n throw new UndeclaredExternalCallerError(scan.undeclaredExternalCallers);\n }\n const contracts: ApiContracts = {};\n const missing: string[] = [];\n for (const api of [...scan.apiIndex.keys()].sort()) {\n const info = scan.apiIndex.get(api)!;\n if (info.methods.length === 0) continue;\n if (info.basePath === undefined) {\n missing.push(`${api} (owner ${info.owner})`);\n continue;\n }\n const contract: ApiContract = {\n owner: info.owner,\n apiKind: info.type,\n basePath: info.basePath,\n methods: info.methods,\n };\n contracts[api] = contract;\n }\n if (missing.length > 0) throw new MissingBasePathError(missing);\n return contracts;\n}\n\n/**\n * Loud, actionable report for decorator arguments the scan could not reduce to a string.\n *\n * Same-module constants resolve, so anything reaching here is genuinely out of reach of a\n * parser-only pass — and every one of them silently shrinks the graph. Empty string when there is\n * nothing to say, so callers can test it without special-casing.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnresolvedApiCalls\nexport function describeNonLiteralDecoratorArgs(args: readonly NonLiteralDecoratorArg[]): string {\n if (args.length === 0) return '';\n const lines = [\n `⚠️ ${args.length} decorator argument(s) are not string literals and could not be resolved.`,\n ` Each one drops data from the graph: a missing basePath, a missing method, or a whole contract:`,\n ];\n for (const arg of args) {\n const where = arg.method === null ? arg.api : `${arg.api}.${arg.method}`;\n lines.push(` • @${arg.decorator}(${arg.argument}) on ${where} at ${arg.at}`);\n }\n lines.push(\n ` A constant declared in the SAME module resolves. One imported from another module does not —`,\n ` this scan is parser-only by design (module resolution can land on a decorator-erased .d.ts).`,\n ` Fix by inlining the string literal, or by moving the constant into the contract's own module.`,\n );\n return lines.join('\\n');\n}\n\n/**\n * Every contract method whose declared @Endpoint kind its api kind cannot deliver — an rpc method on\n * a @PubSub contract (nothing calls a queue synchronously), or a cloudtasks/cron method on an @Rpc\n * contract (naming a queue or schedule nothing could deliver to). Mirrors core-util's\n * ENDPOINT_KINDS_BY_API_KIND at BUILD time, where it can name the file instead of throwing at wiring.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnresolvedApiCalls\nexport function describeMismatchedEndpointKinds(contracts: ApiContracts): string[] {\n const allowedByKind: Record<string, readonly EndpointKind[]> = {\n rpc: ['rpc', 'external'],\n pubsub: ['cloudtasks', 'cron', 'external'],\n };\n const problems: string[] = [];\n for (const api of Object.keys(contracts)) {\n const contract = contracts[api];\n const allowed = allowedByKind[contract.apiKind];\n if (allowed === undefined) continue;\n for (const method of contract.methods) {\n if (allowed.includes(method.kind)) continue;\n problems.push(\n `${api}.${method.name} declares @Endpoint(${method.httpMethod ?? 'POST'}, '${method.path}', ${method.operation}, ${method.kind}) but ${api} is ` +\n `@${contract.apiKind === 'pubsub' ? 'PubSub' : 'Rpc'} — allowed kinds are ${allowed.join(' | ')}.`,\n );\n }\n }\n return problems;\n}\n\n/**\n * Build a program for scanning ONE project. Prefers the project's compile tsconfig; but when that\n * is a solution-style tsconfig (only `references`, no `files`/`include` — e.g. legacy-server), it\n * yields zero files, so we fall back to globbing the project's own `src/**` and reuse the resolved\n * compiler options (which carry tsconfig.base `paths` for cross-package @webpieces resolution).\n *\n * `paths` is a PREFERENCE, not a precondition: it lets imports resolve straight to source. Without\n * it they land on a decorator-erased `dist/**.d.ts`, which the source index recovers from — see\n * ApiUsageScanner.recoverFromDeclaration.\n */\n// webpieces-disable no-function-outside-class -- ts Program factory, mirrors di-graph/program.ts\nfunction createScanProgram(projectRootAbs: string): ts.Program | null {\n const configPath = findProjectTsconfig(projectRootAbs);\n if (!configPath) return buildProgramFromSrc(projectRootAbs, {});\n const host = Object.assign({}, ts.sys, {\n onUnRecoverableConfigFileDiagnostic: (): void => undefined,\n }) as ts.ParseConfigFileHost;\n const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, host);\n if (!parsed) return null;\n if (parsed.fileNames.length > 0) return ts.createProgram(parsed.fileNames, parsed.options);\n return buildProgramFromSrc(projectRootAbs, parsed.options);\n}\n\n// webpieces-disable no-function-outside-class -- ts Program factory helper, mirrors di-graph/program.ts\nfunction buildProgramFromSrc(\n projectRootAbs: string,\n options: ts.CompilerOptions,\n): ts.Program | null {\n const srcDir = path.join(projectRootAbs, 'src');\n if (!fs.existsSync(srcDir)) return null;\n const files = collectTsFiles(srcDir);\n return files.length > 0 ? ts.createProgram(files, options) : null;\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WIRE CLOSURE of a contract (#1064, D4): every named type an `@ApiPath` contract reaches must be
|
|
3
|
+
* DECLARED in a `role:api-lib` project, and must end in a suffix that project's `required-type-suffix`
|
|
4
|
+
* entry demands.
|
|
5
|
+
*
|
|
6
|
+
* Why it lives here and not in the dependency rule: `api-lib-dependencies` only sees project EDGES. A
|
|
7
|
+
* relative-path import into another library, or a DTO library that itself reaches outside, puts a type
|
|
8
|
+
* on the wire without any edge the graph rule could refuse. The extractor already follows every type a
|
|
9
|
+
* contract reaches through the compiler — the same walk `api-rules-for-openapi` / `api-rules-for-mcp`
|
|
10
|
+
* run, with no generate tag needed — so this is one more question asked of each type that walk found.
|
|
11
|
+
*
|
|
12
|
+
* Every api-lib rule before this one (`required-type-suffix`, `one-enum-spelling-in-api-lib`,
|
|
13
|
+
* `no-utility-types-in-api-lib`, `no-inline-import-in-api-lib`) reads only source files INSIDE the api
|
|
14
|
+
* library. A type declared in another package was, by construction, outside every one of them — which is
|
|
15
|
+
* how `AiProvider` and the `BrowserTelemetry` trio reached the wire from a general library unchecked.
|
|
16
|
+
*
|
|
17
|
+
* A type declared OUTSIDE the workspace (a published package under node_modules) is not judged here:
|
|
18
|
+
* its own package owns its schema, and the generator's fail-closed components check covers it.
|
|
19
|
+
*/
|
|
20
|
+
import { DocumentedType } from '@webpieces/api-doc-model';
|
|
21
|
+
import { RequiredTypeSuffixEntry } from '@webpieces/rules-config';
|
|
22
|
+
import { ProjectInfo } from '../project-info';
|
|
23
|
+
/** The `required-type-suffix` entries the wire closure enforces; empty when that rule is OFF. */
|
|
24
|
+
export declare class WireClosureRule {
|
|
25
|
+
readonly suffixEntries: readonly RequiredTypeSuffixEntry[];
|
|
26
|
+
constructor(suffixEntries: readonly RequiredTypeSuffixEntry[]);
|
|
27
|
+
/** Only the role check — what a unit test or a repo with `required-type-suffix` OFF gets. */
|
|
28
|
+
static withoutSuffixes(): WireClosureRule;
|
|
29
|
+
/** `required-type-suffix`'s entries, unless that rule is OFF or time-boxed / branch-scoped off. */
|
|
30
|
+
static fromConfig(workspaceRoot: string): WireClosureRule;
|
|
31
|
+
}
|
|
32
|
+
/** ONE wire-closure finding: what is wrong with a reached type, and what to do. */
|
|
33
|
+
export declare class WireClosureVerdict {
|
|
34
|
+
readonly what: string;
|
|
35
|
+
readonly cure: string;
|
|
36
|
+
constructor(what: string, cure: string);
|
|
37
|
+
}
|
|
38
|
+
/** Judges every type a contract reaches against the api-lib role and the suffix rule. */
|
|
39
|
+
export declare class WireClosure {
|
|
40
|
+
private readonly workspaceRoot;
|
|
41
|
+
private readonly rule;
|
|
42
|
+
private readonly roots;
|
|
43
|
+
private readonly picker;
|
|
44
|
+
constructor(workspaceRoot: string, projectInfos: Map<string, ProjectInfo>, rule: WireClosureRule);
|
|
45
|
+
/** Every verdict for ONE reached type, declared in the file `absFile`. */
|
|
46
|
+
judge(type: DocumentedType, absFile: string): WireClosureVerdict[];
|
|
47
|
+
private endsInSuffix;
|
|
48
|
+
private ownerOf;
|
|
49
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The WIRE CLOSURE of a contract (#1064, D4): every named type an `@ApiPath` contract reaches must be
|
|
4
|
+
* DECLARED in a `role:api-lib` project, and must end in a suffix that project's `required-type-suffix`
|
|
5
|
+
* entry demands.
|
|
6
|
+
*
|
|
7
|
+
* Why it lives here and not in the dependency rule: `api-lib-dependencies` only sees project EDGES. A
|
|
8
|
+
* relative-path import into another library, or a DTO library that itself reaches outside, puts a type
|
|
9
|
+
* on the wire without any edge the graph rule could refuse. The extractor already follows every type a
|
|
10
|
+
* contract reaches through the compiler — the same walk `api-rules-for-openapi` / `api-rules-for-mcp`
|
|
11
|
+
* run, with no generate tag needed — so this is one more question asked of each type that walk found.
|
|
12
|
+
*
|
|
13
|
+
* Every api-lib rule before this one (`required-type-suffix`, `one-enum-spelling-in-api-lib`,
|
|
14
|
+
* `no-utility-types-in-api-lib`, `no-inline-import-in-api-lib`) reads only source files INSIDE the api
|
|
15
|
+
* library. A type declared in another package was, by construction, outside every one of them — which is
|
|
16
|
+
* how `AiProvider` and the `BrowserTelemetry` trio reached the wire from a general library unchecked.
|
|
17
|
+
*
|
|
18
|
+
* A type declared OUTSIDE the workspace (a published package under node_modules) is not judged here:
|
|
19
|
+
* its own package owns its schema, and the generator's fail-closed components check covers it.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.WireClosure = exports.WireClosureVerdict = exports.WireClosureRule = void 0;
|
|
23
|
+
const tslib_1 = require("tslib");
|
|
24
|
+
const path = tslib_1.__importStar(require("path"));
|
|
25
|
+
const code_rules_1 = require("@webpieces/code-rules");
|
|
26
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
27
|
+
const role_resolver_1 = require("../role-resolver");
|
|
28
|
+
const rule_gate_1 = require("../rule-gate");
|
|
29
|
+
const API_LIB_ROLE = 'api-lib';
|
|
30
|
+
/** The `required-type-suffix` entries the wire closure enforces; empty when that rule is OFF. */
|
|
31
|
+
class WireClosureRule {
|
|
32
|
+
suffixEntries;
|
|
33
|
+
constructor(suffixEntries) {
|
|
34
|
+
this.suffixEntries = suffixEntries;
|
|
35
|
+
}
|
|
36
|
+
/** Only the role check — what a unit test or a repo with `required-type-suffix` OFF gets. */
|
|
37
|
+
// webpieces-disable no-function-outside-class -- static factory of this class
|
|
38
|
+
static withoutSuffixes() {
|
|
39
|
+
return new WireClosureRule([]);
|
|
40
|
+
}
|
|
41
|
+
/** `required-type-suffix`'s entries, unless that rule is OFF or time-boxed / branch-scoped off. */
|
|
42
|
+
// webpieces-disable no-function-outside-class -- static factory of this class
|
|
43
|
+
static fromConfig(workspaceRoot) {
|
|
44
|
+
if (new rule_gate_1.RuleGate().skipReason(workspaceRoot, rules_config_1.RULE_NAMES.REQUIRED_TYPE_SUFFIX, true) !== null) {
|
|
45
|
+
return WireClosureRule.withoutSuffixes();
|
|
46
|
+
}
|
|
47
|
+
const rule = (0, rules_config_1.loadAndValidate)(workspaceRoot).resolved.rules.get(rules_config_1.RULE_NAMES.REQUIRED_TYPE_SUFFIX);
|
|
48
|
+
const entries = rule?.options['entries'];
|
|
49
|
+
return new WireClosureRule(Array.isArray(entries) ? entries : []);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.WireClosureRule = WireClosureRule;
|
|
53
|
+
/** ONE wire-closure finding: what is wrong with a reached type, and what to do. */
|
|
54
|
+
class WireClosureVerdict {
|
|
55
|
+
what;
|
|
56
|
+
cure;
|
|
57
|
+
constructor(what, cure) {
|
|
58
|
+
this.what = what;
|
|
59
|
+
this.cure = cure;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.WireClosureVerdict = WireClosureVerdict;
|
|
63
|
+
/** A workspace project root, absolute, for the longest-prefix owner lookup. */
|
|
64
|
+
class OwnedRoot {
|
|
65
|
+
info;
|
|
66
|
+
abs;
|
|
67
|
+
constructor(info, abs) {
|
|
68
|
+
this.info = info;
|
|
69
|
+
this.abs = abs;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Judges every type a contract reaches against the api-lib role and the suffix rule. */
|
|
73
|
+
class WireClosure {
|
|
74
|
+
workspaceRoot;
|
|
75
|
+
rule;
|
|
76
|
+
roots;
|
|
77
|
+
picker = new code_rules_1.SuffixEntryPicker();
|
|
78
|
+
constructor(workspaceRoot, projectInfos, rule) {
|
|
79
|
+
this.workspaceRoot = workspaceRoot;
|
|
80
|
+
this.rule = rule;
|
|
81
|
+
this.roots = [...projectInfos.values()]
|
|
82
|
+
.filter((info) => info.root !== '' && info.root !== '.')
|
|
83
|
+
.map((info) => new OwnedRoot(info, path.resolve(workspaceRoot, info.root)))
|
|
84
|
+
// Longest root first so a nested project wins over its parent.
|
|
85
|
+
.sort((a, b) => b.abs.length - a.abs.length);
|
|
86
|
+
}
|
|
87
|
+
/** Every verdict for ONE reached type, declared in the file `absFile`. */
|
|
88
|
+
judge(type, absFile) {
|
|
89
|
+
const abs = path.resolve(this.workspaceRoot, absFile);
|
|
90
|
+
if (abs.split(path.sep).includes('node_modules'))
|
|
91
|
+
return [];
|
|
92
|
+
const owner = this.ownerOf(abs);
|
|
93
|
+
if (owner === null)
|
|
94
|
+
return [];
|
|
95
|
+
const relFile = path.relative(this.workspaceRoot, abs).split(path.sep).join('/');
|
|
96
|
+
const role = (0, role_resolver_1.resolveRole)(owner).role ?? 'none';
|
|
97
|
+
const declared = `${type.packageName ?? 'no package'} (project '${owner.name}', role:${role})`;
|
|
98
|
+
const verdicts = [];
|
|
99
|
+
if (role !== API_LIB_ROLE) {
|
|
100
|
+
verdicts.push(new WireClosureVerdict(`'${type.name}' goes over the wire but is declared in ${declared}, which is not a role:api-lib ` +
|
|
101
|
+
'project — every type a contract reaches must be declared in an api library', `Move '${type.name}' into a role:api-lib project — as a '…Dto' string enum when it is a ` +
|
|
102
|
+
`string-literal union. Retagging '${owner.name}' is not a way out unless it holds only ` +
|
|
103
|
+
'contracts and wire types (validate-api-lib-tag refuses a role:api-lib with an implementation).'));
|
|
104
|
+
}
|
|
105
|
+
const governing = this.picker.winner(relFile, this.rule.suffixEntries);
|
|
106
|
+
if (governing !== undefined && !this.endsInSuffix(type.name, governing.entry.suffixes)) {
|
|
107
|
+
verdicts.push(new WireClosureVerdict(`'${type.name}' goes over the wire from ${relFile} but does not end in one of ` +
|
|
108
|
+
`[${governing.entry.suffixes.join(', ')}], which the required-type-suffix entry ` +
|
|
109
|
+
`'${governing.glob}' demands of it`, `Rename '${type.name}' to end in one of ${governing.entry.suffixes.join(', ')} — the suffix tells a ` +
|
|
110
|
+
'reader which layer a type belongs to, and a wire type is the layer a partner reads.'));
|
|
111
|
+
}
|
|
112
|
+
return verdicts;
|
|
113
|
+
}
|
|
114
|
+
endsInSuffix(name, suffixes) {
|
|
115
|
+
return suffixes.some((suffix) => name.length > suffix.length && name.endsWith(suffix));
|
|
116
|
+
}
|
|
117
|
+
ownerOf(abs) {
|
|
118
|
+
for (const root of this.roots) {
|
|
119
|
+
if (abs === root.abs || abs.startsWith(root.abs + path.sep))
|
|
120
|
+
return root.info;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.WireClosure = WireClosure;
|
|
126
|
+
//# sourceMappingURL=wire-closure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-closure.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/wire-closure.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;AAEH,mDAA6B;AAE7B,sDAA0D;AAC1D,0DAA+F;AAE/F,oDAA+C;AAC/C,4CAAwC;AAExC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,iGAAiG;AACjG,MAAa,eAAe;IACI;IAA5B,YAA4B,aAAiD;QAAjD,kBAAa,GAAb,aAAa,CAAoC;IAAG,CAAC;IAEjF,6FAA6F;IAC7F,8EAA8E;IAC9E,MAAM,CAAC,eAAe;QAClB,OAAO,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,mGAAmG;IACnG,8EAA8E;IAC9E,MAAM,CAAC,UAAU,CAAC,aAAqB;QACnC,IAAI,IAAI,oBAAQ,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,yBAAU,CAAC,oBAAoB,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3F,OAAO,eAAe,CAAC,eAAe,EAAE,CAAC;QAC7C,CAAC;QACD,MAAM,IAAI,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAU,CAAC,oBAAoB,CAAC,CAAC;QAChG,MAAM,OAA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KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrF,QAAQ,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAChC,IAAI,IAAI,CAAC,IAAI,6BAA6B,OAAO,8BAA8B;gBAC3E,IAAI,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,0CAA0C;gBACjF,IAAI,SAAS,CAAC,IAAI,iBAAiB,EACvC,WAAW,IAAI,CAAC,IAAI,sBAAsB,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB;gBACjG,qFAAqF,CAC5F,CAAC,CAAC;QACP,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAEO,YAAY,CAAC,IAAY,EAAE,QAA2B;QAC1D,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACnG,CAAC;IAEO,OAAO,CAAC,GAAW;QACvB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC,IAAI,CAAC;QAClF,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA1DD,kCA0DC","sourcesContent":["/**\n * The WIRE CLOSURE of a contract (#1064, D4): every named type an `@ApiPath` contract reaches must be\n * DECLARED in a `role:api-lib` project, and must end in a suffix that project's `required-type-suffix`\n * entry demands.\n *\n * Why it lives here and not in the dependency rule: `api-lib-dependencies` only sees project EDGES. A\n * relative-path import into another library, or a DTO library that itself reaches outside, puts a type\n * on the wire without any edge the graph rule could refuse. The extractor already follows every type a\n * contract reaches through the compiler — the same walk `api-rules-for-openapi` / `api-rules-for-mcp`\n * run, with no generate tag needed — so this is one more question asked of each type that walk found.\n *\n * Every api-lib rule before this one (`required-type-suffix`, `one-enum-spelling-in-api-lib`,\n * `no-utility-types-in-api-lib`, `no-inline-import-in-api-lib`) reads only source files INSIDE the api\n * library. A type declared in another package was, by construction, outside every one of them — which is\n * how `AiProvider` and the `BrowserTelemetry` trio reached the wire from a general library unchecked.\n *\n * A type declared OUTSIDE the workspace (a published package under node_modules) is not judged here:\n * its own package owns its schema, and the generator's fail-closed components check covers it.\n */\n\nimport * as path from 'path';\nimport { DocumentedType } from '@webpieces/api-doc-model';\nimport { SuffixEntryPicker } from '@webpieces/code-rules';\nimport { loadAndValidate, RequiredTypeSuffixEntry, RULE_NAMES } from '@webpieces/rules-config';\nimport { ProjectInfo } from '../project-info';\nimport { resolveRole } from '../role-resolver';\nimport { RuleGate } from '../rule-gate';\n\nconst API_LIB_ROLE = 'api-lib';\n\n/** The `required-type-suffix` entries the wire closure enforces; empty when that rule is OFF. */\nexport class WireClosureRule {\n constructor(public readonly suffixEntries: readonly RequiredTypeSuffixEntry[]) {}\n\n /** Only the role check — what a unit test or a repo with `required-type-suffix` OFF gets. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static withoutSuffixes(): WireClosureRule {\n return new WireClosureRule([]);\n }\n\n /** `required-type-suffix`'s entries, unless that rule is OFF or time-boxed / branch-scoped off. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static fromConfig(workspaceRoot: string): WireClosureRule {\n if (new RuleGate().skipReason(workspaceRoot, RULE_NAMES.REQUIRED_TYPE_SUFFIX, true) !== null) {\n return WireClosureRule.withoutSuffixes();\n }\n const rule = loadAndValidate(workspaceRoot).resolved.rules.get(RULE_NAMES.REQUIRED_TYPE_SUFFIX);\n const entries = rule?.options['entries'];\n return new WireClosureRule(Array.isArray(entries) ? (entries as RequiredTypeSuffixEntry[]) : []);\n }\n}\n\n/** ONE wire-closure finding: what is wrong with a reached type, and what to do. */\nexport class WireClosureVerdict {\n constructor(\n public readonly what: string,\n public readonly cure: string,\n ) {}\n}\n\n/** A workspace project root, absolute, for the longest-prefix owner lookup. */\nclass OwnedRoot {\n constructor(\n public readonly info: ProjectInfo,\n public readonly abs: string,\n ) {}\n}\n\n/** Judges every type a contract reaches against the api-lib role and the suffix rule. */\nexport class WireClosure {\n private readonly roots: OwnedRoot[];\n private readonly picker = new SuffixEntryPicker();\n\n constructor(\n private readonly workspaceRoot: string,\n projectInfos: Map<string, ProjectInfo>,\n private readonly rule: WireClosureRule,\n ) {\n this.roots = [...projectInfos.values()]\n .filter((info: ProjectInfo) => info.root !== '' && info.root !== '.')\n .map((info: ProjectInfo) => new OwnedRoot(info, path.resolve(workspaceRoot, info.root)))\n // Longest root first so a nested project wins over its parent.\n .sort((a: OwnedRoot, b: OwnedRoot) => b.abs.length - a.abs.length);\n }\n\n /** Every verdict for ONE reached type, declared in the file `absFile`. */\n judge(type: DocumentedType, absFile: string): WireClosureVerdict[] {\n const abs = path.resolve(this.workspaceRoot, absFile);\n if (abs.split(path.sep).includes('node_modules')) return [];\n const owner = this.ownerOf(abs);\n if (owner === null) return [];\n const relFile = path.relative(this.workspaceRoot, abs).split(path.sep).join('/');\n const role = resolveRole(owner).role ?? 'none';\n const declared = `${type.packageName ?? 'no package'} (project '${owner.name}', role:${role})`;\n const verdicts: WireClosureVerdict[] = [];\n if (role !== API_LIB_ROLE) {\n verdicts.push(new WireClosureVerdict(\n `'${type.name}' goes over the wire but is declared in ${declared}, which is not a role:api-lib ` +\n 'project — every type a contract reaches must be declared in an api library',\n `Move '${type.name}' into a role:api-lib project — as a '…Dto' string enum when it is a ` +\n `string-literal union. Retagging '${owner.name}' is not a way out unless it holds only ` +\n 'contracts and wire types (validate-api-lib-tag refuses a role:api-lib with an implementation).',\n ));\n }\n const governing = this.picker.winner(relFile, this.rule.suffixEntries);\n if (governing !== undefined && !this.endsInSuffix(type.name, governing.entry.suffixes)) {\n verdicts.push(new WireClosureVerdict(\n `'${type.name}' goes over the wire from ${relFile} but does not end in one of ` +\n `[${governing.entry.suffixes.join(', ')}], which the required-type-suffix entry ` +\n `'${governing.glob}' demands of it`,\n `Rename '${type.name}' to end in one of ${governing.entry.suffixes.join(', ')} — the suffix tells a ` +\n 'reader which layer a type belongs to, and a wire type is the layer a partner reads.',\n ));\n }\n return verdicts;\n }\n\n private endsInSuffix(name: string, suffixes: readonly string[]): boolean {\n return suffixes.some((suffix: string) => name.length > suffix.length && name.endsWith(suffix));\n }\n\n private ownerOf(abs: string): ProjectInfo | null {\n for (const root of this.roots) {\n if (abs === root.abs || abs.startsWith(root.abs + path.sep)) return root.info;\n }\n return null;\n }\n}\n"]}
|
|
@@ -43,12 +43,16 @@ export declare class DepUsageScanner {
|
|
|
43
43
|
*/
|
|
44
44
|
isDevFile(relPath: string): boolean;
|
|
45
45
|
/**
|
|
46
|
-
* The package a bare specifier belongs to, or null for relative/absolute
|
|
47
|
-
*
|
|
46
|
+
* The package a bare specifier belongs to, or null for relative/absolute paths.
|
|
47
|
+
* `@scope/pkg/sub` → `@scope/pkg`; `pkg/sub` → `pkg`; `node:fs/promises` → `fs`.
|
|
48
|
+
*
|
|
49
|
+
* Node builtins deliberately stay in the result: api-lib-dependencies treats them as outside
|
|
50
|
+
* runtime dependencies, and one allow-list spelling must govern both `fs` and `node:fs`.
|
|
48
51
|
*/
|
|
49
52
|
toPackageName(specifier: string): string | null;
|
|
50
53
|
private walk;
|
|
51
54
|
private scanFile;
|
|
55
|
+
/** Parse real syntax so prose such as `different from "no field"` cannot become a phantom import. */
|
|
52
56
|
private extractPackageNames;
|
|
53
57
|
private readFile;
|
|
54
58
|
}
|
|
@@ -24,6 +24,7 @@ exports.DepUsageScanner = exports.DepUsage = void 0;
|
|
|
24
24
|
const tslib_1 = require("tslib");
|
|
25
25
|
const fs = tslib_1.__importStar(require("fs"));
|
|
26
26
|
const path = tslib_1.__importStar(require("path"));
|
|
27
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
27
28
|
const toError_1 = require("../toError");
|
|
28
29
|
/** Directories never worth scanning (build output, vendored code, VCS). */
|
|
29
30
|
const SKIP_DIRS = new Set([
|
|
@@ -38,16 +39,7 @@ const SKIP_DIRS = new Set([
|
|
|
38
39
|
'.angular',
|
|
39
40
|
]);
|
|
40
41
|
/** Source extensions whose imports we understand. */
|
|
41
|
-
const SOURCE_EXTENSIONS = new Set([
|
|
42
|
-
'.ts',
|
|
43
|
-
'.tsx',
|
|
44
|
-
'.mts',
|
|
45
|
-
'.cts',
|
|
46
|
-
'.js',
|
|
47
|
-
'.jsx',
|
|
48
|
-
'.mjs',
|
|
49
|
-
'.cjs',
|
|
50
|
-
]);
|
|
42
|
+
const SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs']);
|
|
51
43
|
/**
|
|
52
44
|
* Directory names whose contents SHIP to consumers as scaffolding (copied into a consumer repo by the
|
|
53
45
|
* installer), so their imports are consumer-facing PRODUCTION deps — NOT this project's own dev-time
|
|
@@ -56,9 +48,7 @@ const SOURCE_EXTENSIONS = new Set([
|
|
|
56
48
|
* `@webpieces/eslint-rules`, which those very templates import) as "test-only in dependencies".
|
|
57
49
|
* A `templates/` segment therefore short-circuits isDevFile to production, ahead of the name heuristics.
|
|
58
50
|
*/
|
|
59
|
-
const SHIPPED_DIR_NAMES = new Set([
|
|
60
|
-
'templates',
|
|
61
|
-
]);
|
|
51
|
+
const SHIPPED_DIR_NAMES = new Set(['templates']);
|
|
62
52
|
/**
|
|
63
53
|
* Directory names that make everything below them test/dev-only.
|
|
64
54
|
* Kept tight on purpose — a false "this is a test dir" would let a real
|
|
@@ -79,8 +69,6 @@ const TEST_FILE_RE = /[.-](spec|test|e2e|testkit|mock|mocks|fixture|fixtures)\.[
|
|
|
79
69
|
const DEV_CONFIG_RE = /^(vitest|vite|jest|playwright|cypress|karma|webpack|rollup|eslint|prettier)\.[\w.-]*config\.[cm]?[jt]s$/;
|
|
80
70
|
/** `jest.setup.ts`, `vitest.setup.ts`, `test-setup.ts`, ... */
|
|
81
71
|
const DEV_SETUP_RE = /^([\w-]*[.-])?(setup|test-setup)\.[cm]?[jt]s$/;
|
|
82
|
-
/** Bare-import extraction: `from 'x'`, `import 'x'`, `import('x')`, `require('x')`. */
|
|
83
|
-
const IMPORT_RE = /(?:\bfrom\s*|\bimport\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)['"]([^'"]+)['"]/g;
|
|
84
72
|
/**
|
|
85
73
|
* Which packages a project reaches from production code vs. only from test/dev code.
|
|
86
74
|
* Data-only: no logic lives here (see CLAUDE.md — data structures are classes).
|
|
@@ -141,18 +129,24 @@ class DepUsageScanner {
|
|
|
141
129
|
return false;
|
|
142
130
|
}
|
|
143
131
|
/**
|
|
144
|
-
* The package a bare specifier belongs to, or null for relative/absolute
|
|
145
|
-
*
|
|
132
|
+
* The package a bare specifier belongs to, or null for relative/absolute paths.
|
|
133
|
+
* `@scope/pkg/sub` → `@scope/pkg`; `pkg/sub` → `pkg`; `node:fs/promises` → `fs`.
|
|
134
|
+
*
|
|
135
|
+
* Node builtins deliberately stay in the result: api-lib-dependencies treats them as outside
|
|
136
|
+
* runtime dependencies, and one allow-list spelling must govern both `fs` and `node:fs`.
|
|
146
137
|
*/
|
|
147
138
|
toPackageName(specifier) {
|
|
148
139
|
if (specifier.length === 0)
|
|
149
140
|
return null;
|
|
150
141
|
if (specifier.startsWith('.') || specifier.startsWith('/'))
|
|
151
142
|
return null;
|
|
152
|
-
|
|
143
|
+
const normalized = specifier.startsWith('node:')
|
|
144
|
+
? specifier.slice('node:'.length)
|
|
145
|
+
: specifier;
|
|
146
|
+
if (normalized.length === 0)
|
|
153
147
|
return null;
|
|
154
|
-
const parts =
|
|
155
|
-
if (
|
|
148
|
+
const parts = normalized.split('/');
|
|
149
|
+
if (normalized.startsWith('@')) {
|
|
156
150
|
if (parts.length < 2)
|
|
157
151
|
return null;
|
|
158
152
|
return `${parts[0]}/${parts[1]}`;
|
|
@@ -182,20 +176,43 @@ class DepUsageScanner {
|
|
|
182
176
|
return;
|
|
183
177
|
const relPath = path.relative(projectRoot, absPath);
|
|
184
178
|
const bucket = this.isDevFile(relPath) ? usage.testPackages : usage.prodPackages;
|
|
185
|
-
for (const packageName of this.extractPackageNames(source)) {
|
|
179
|
+
for (const packageName of this.extractPackageNames(source, absPath)) {
|
|
186
180
|
bucket.add(packageName);
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
|
-
|
|
183
|
+
/** Parse real syntax so prose such as `different from "no field"` cannot become a phantom import. */
|
|
184
|
+
extractPackageNames(source, fileName) {
|
|
190
185
|
const names = [];
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true);
|
|
187
|
+
const add = (specifier) => {
|
|
188
|
+
if (specifier === undefined || !ts.isStringLiteralLike(specifier))
|
|
189
|
+
return;
|
|
190
|
+
const packageName = this.toPackageName(specifier.text);
|
|
195
191
|
if (packageName !== null)
|
|
196
192
|
names.push(packageName);
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
};
|
|
194
|
+
const visit = (node) => {
|
|
195
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
196
|
+
add(node.moduleSpecifier);
|
|
197
|
+
}
|
|
198
|
+
else if (ts.isImportEqualsDeclaration(node) &&
|
|
199
|
+
ts.isExternalModuleReference(node.moduleReference)) {
|
|
200
|
+
add(node.moduleReference.expression);
|
|
201
|
+
}
|
|
202
|
+
else if (ts.isCallExpression(node)) {
|
|
203
|
+
const isDynamicImport = node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
204
|
+
const isRequire = ts.isIdentifier(node.expression) && node.expression.text === 'require';
|
|
205
|
+
if (isDynamicImport || isRequire)
|
|
206
|
+
add(node.arguments[0]);
|
|
207
|
+
}
|
|
208
|
+
else if (ts.isImportTypeNode(node)) {
|
|
209
|
+
const argument = node.argument;
|
|
210
|
+
if (ts.isLiteralTypeNode(argument))
|
|
211
|
+
add(argument.literal);
|
|
212
|
+
}
|
|
213
|
+
ts.forEachChild(node, visit);
|
|
214
|
+
};
|
|
215
|
+
visit(sourceFile);
|
|
199
216
|
return names;
|
|
200
217
|
}
|
|
201
218
|
readFile(absPath) {
|