@anarchitects/governance-adapter-typescript 0.0.1

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.
Files changed (39) hide show
  1. package/README.md +155 -0
  2. package/dist/detect-typescript-workspace.d.ts +3 -0
  3. package/dist/detect-typescript-workspace.d.ts.map +1 -0
  4. package/dist/diagnostics.d.ts +26 -0
  5. package/dist/diagnostics.d.ts.map +1 -0
  6. package/dist/import-graph.d.ts +8 -0
  7. package/dist/import-graph.d.ts.map +1 -0
  8. package/dist/index.d.ts +10 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +1637 -0
  11. package/dist/map-imports-to-projects.d.ts +8 -0
  12. package/dist/map-imports-to-projects.d.ts.map +1 -0
  13. package/dist/normalize-path-aliases.d.ts +9 -0
  14. package/dist/normalize-path-aliases.d.ts.map +1 -0
  15. package/dist/normalize-workspace-patterns.d.ts +7 -0
  16. package/dist/normalize-workspace-patterns.d.ts.map +1 -0
  17. package/dist/parse-imports.d.ts +11 -0
  18. package/dist/parse-imports.d.ts.map +1 -0
  19. package/dist/parse-package-manager-workspace.d.ts +3 -0
  20. package/dist/parse-package-manager-workspace.d.ts.map +1 -0
  21. package/dist/parse-tsconfig.d.ts +3 -0
  22. package/dist/parse-tsconfig.d.ts.map +1 -0
  23. package/dist/project-discovery.d.ts +3 -0
  24. package/dist/project-discovery.d.ts.map +1 -0
  25. package/dist/project-naming.d.ts +9 -0
  26. package/dist/project-naming.d.ts.map +1 -0
  27. package/dist/resolve-tsconfig-extends.d.ts +13 -0
  28. package/dist/resolve-tsconfig-extends.d.ts.map +1 -0
  29. package/dist/resolve-workspace-packages.d.ts +2 -0
  30. package/dist/resolve-workspace-packages.d.ts.map +1 -0
  31. package/dist/source-file-discovery.d.ts +4 -0
  32. package/dist/source-file-discovery.d.ts.map +1 -0
  33. package/dist/tag-mapping.d.ts +10 -0
  34. package/dist/tag-mapping.d.ts.map +1 -0
  35. package/dist/types.d.ts +70 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/workspace-adapter.d.ts +22 -0
  38. package/dist/workspace-adapter.d.ts.map +1 -0
  39. package/package.json +60 -0
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # `@anarchitects/governance-adapter-typescript`
2
+
3
+ Platform-independent TypeScript workspace discovery and normalization for Governance.
4
+
5
+ ## Overview
6
+
7
+ `@anarchitects/governance-adapter-typescript` reads a TypeScript-oriented workspace as plain files and maps the result into contracts owned by `@anarchitects/governance-core`.
8
+
9
+ The package focuses on discovery and normalization, not on owning the canonical Governance model. It is intended for hosts that need to inspect a TypeScript workspace outside Nx and then feed the normalized result into Governance Core.
10
+
11
+ ## Responsibilities
12
+
13
+ This package is responsible for:
14
+
15
+ - detecting whether a repository looks like a supported TypeScript workspace
16
+ - parsing package-manager workspace configuration
17
+ - parsing `tsconfig.json` and `tsconfig.base.json` resolution state
18
+ - discovering TypeScript projects from workspace package roots
19
+ - building a static TypeScript import graph
20
+ - mapping discovered imports into Core-owned dependency inputs
21
+ - deriving project tags from naming and path rules
22
+
23
+ This package is not responsible for:
24
+
25
+ - CLI command behavior
26
+ - canonical Governance contracts
27
+ - Nx graph loading
28
+ - Nx metadata extraction
29
+ - Nx plugin runtime behavior
30
+ - Nx executors or generators
31
+
32
+ ## Supported Assumptions
33
+
34
+ The current implementation assumes:
35
+
36
+ - workspace detection based on plain package-manager files such as `pnpm-workspace.yaml` and `package.json#workspaces`
37
+ - `tsconfig` parsing through root `tsconfig.json`, `tsconfig.base.json`, and deterministic `extends` chains
38
+ - static analysis of relative imports, package-name imports, `compilerOptions.paths`, `baseUrl`, re-exports, and string-literal dynamic imports
39
+ - project discovery from package-manager workspace roots rather than from Nx graph APIs
40
+
41
+ ## Public API
42
+
43
+ The public package surface is intentionally adapter-oriented:
44
+
45
+ ```ts
46
+ import {
47
+ buildTypeScriptImportGraph,
48
+ createGovernanceWorkspaceAdapter,
49
+ createTypeScriptWorkspaceAdapter,
50
+ detectTypeScriptWorkspace,
51
+ discoverTypeScriptProjects,
52
+ deriveProjectTags,
53
+ mapTypeScriptImportsToGovernanceDependencies,
54
+ parsePackageManagerWorkspace,
55
+ parseTsConfigResolution,
56
+ type TsConfigResolutionModel,
57
+ type TypeScriptImportGraph,
58
+ type TypeScriptProjectDiscoveryResult,
59
+ type TypeScriptWorkspaceDetectionResult,
60
+ type WorkspacePackageResolution,
61
+ } from '@anarchitects/governance-adapter-typescript';
62
+ ```
63
+
64
+ The root export currently includes:
65
+
66
+ - `createTypeScriptWorkspaceAdapter(...)`
67
+ - `createGovernanceWorkspaceAdapter(...)`
68
+ - `detectTypeScriptWorkspace(...)`
69
+ - `parsePackageManagerWorkspace(...)`
70
+ - `parseTsConfigResolution(...)`
71
+ - `discoverTypeScriptProjects(...)`
72
+ - `buildTypeScriptImportGraph(...)`
73
+ - `mapTypeScriptImportsToGovernanceDependencies(...)`
74
+ - `deriveProjectTags(...)`
75
+ - exported adapter result and diagnostic types from `types.ts`
76
+
77
+ The current API is a set of composable adapter primitives. It does not expose a single all-in-one host runner.
78
+
79
+ ## Usage
80
+
81
+ The typical workflow is:
82
+
83
+ 1. detect a supported workspace
84
+ 2. resolve workspace package roots
85
+ 3. discover projects
86
+ 4. resolve TypeScript path aliases
87
+ 5. build a static import graph
88
+ 6. map that graph into Core-owned dependency inputs
89
+
90
+ ```ts
91
+ import {
92
+ buildTypeScriptImportGraph,
93
+ detectTypeScriptWorkspace,
94
+ discoverTypeScriptProjects,
95
+ mapTypeScriptImportsToGovernanceDependencies,
96
+ parsePackageManagerWorkspace,
97
+ parseTsConfigResolution,
98
+ } from '@anarchitects/governance-adapter-typescript';
99
+
100
+ const detection = detectTypeScriptWorkspace(process.cwd());
101
+
102
+ if (!detection.supported) {
103
+ throw new Error('Unsupported TypeScript workspace.');
104
+ }
105
+
106
+ const workspacePackages = parsePackageManagerWorkspace(detection.workspaceRoot);
107
+ const projectDiscovery = discoverTypeScriptProjects({
108
+ workspaceRoot: workspacePackages.workspaceRoot,
109
+ packageRoots: workspacePackages.packageRoots,
110
+ });
111
+ const tsconfig = parseTsConfigResolution(detection.workspaceRoot);
112
+ const importGraph = buildTypeScriptImportGraph({
113
+ workspaceRoot: detection.workspaceRoot,
114
+ projects: projectDiscovery.projects,
115
+ tsconfig,
116
+ });
117
+ const dependencyMapping = mapTypeScriptImportsToGovernanceDependencies({
118
+ projects: projectDiscovery.projects,
119
+ importGraph,
120
+ });
121
+ ```
122
+
123
+ ## Normalization into Governance Core
124
+
125
+ This adapter normalizes into `@anarchitects/governance-core` contracts rather than defining a parallel model.
126
+
127
+ In practice:
128
+
129
+ - project discovery produces `GovernanceProjectInput` values
130
+ - dependency mapping produces `GovernanceDependencyInput` values
131
+ - diagnostics align with Core-owned diagnostic shapes where the exported types reference them
132
+
133
+ Hosts can combine these results with Core-owned assessment, rule, signal, and extension APIs.
134
+
135
+ ## Package Boundaries
136
+
137
+ `@anarchitects/governance-adapter-typescript` is explicitly non-Nx.
138
+
139
+ That means:
140
+
141
+ - no `@nx/devkit`
142
+ - no `nx`
143
+ - no Nx graph loading
144
+ - no Nx plugin runtime assumptions
145
+ - no executor or generator ownership
146
+
147
+ The package reads repository files directly and stays usable in plain TypeScript or mixed monorepo environments without requiring Nx.
148
+
149
+ For detailed package-boundary rules and the adapter ownership model, see
150
+ [ADR 0001: Governance Package Boundaries for Core, CLI, Adapters, and Extensions](../../../docs/adr/0001-governance-package-boundaries.md).
151
+
152
+ ## Related Packages
153
+
154
+ - `@anarchitects/governance-core` owns the canonical Governance contracts and deterministic evaluation logic
155
+ - `@anarchitects/governance-cli` is a separate host/runtime package and should not be treated as part of this adapter’s public API
@@ -0,0 +1,3 @@
1
+ import { TypeScriptWorkspaceDetectionResult } from './types.js';
2
+ export declare function detectTypeScriptWorkspace(workspacePath: string): TypeScriptWorkspaceDetectionResult;
3
+ //# sourceMappingURL=detect-typescript-workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-typescript-workspace.d.ts","sourceRoot":"","sources":["../src/detect-typescript-workspace.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,kCAAkC,EAEnC,MAAM,YAAY,CAAC;AAEpB,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,GACpB,kCAAkC,CAoDpC"}
@@ -0,0 +1,26 @@
1
+ import { TypeScriptWorkspaceDetectionDiagnostic, TypeScriptWorkspaceIndicators } from './types.js';
2
+ export declare function invalidPackageJsonDiagnostic(filePath: string): TypeScriptWorkspaceDetectionDiagnostic;
3
+ export declare function partialWorkspaceDetectionDiagnostic(indicators: TypeScriptWorkspaceIndicators): TypeScriptWorkspaceDetectionDiagnostic;
4
+ export declare function noWorkspaceIndicatorsDiagnostic(): TypeScriptWorkspaceDetectionDiagnostic;
5
+ export declare function invalidWorkspaceConfigDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
6
+ export declare function unsupportedWorkspaceFormatDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
7
+ export declare function noWorkspacePackagesFoundDiagnostic(patterns: readonly string[]): TypeScriptWorkspaceDetectionDiagnostic;
8
+ export declare function invalidTsConfigDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
9
+ export declare function invalidTsConfigExtendsDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
10
+ export declare function circularTsConfigExtendsDiagnostic(path: string, chain: readonly string[]): TypeScriptWorkspaceDetectionDiagnostic;
11
+ export declare function invalidPathAliasDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
12
+ export declare function invalidDiscoveryPatternDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
13
+ export declare function discoveryPatternNoMatchesDiagnostic(pattern: string, path: string): TypeScriptWorkspaceDetectionDiagnostic;
14
+ export declare function duplicateProjectRootDiagnostic(root: string, path: string): TypeScriptWorkspaceDetectionDiagnostic;
15
+ export declare function duplicateProjectNameDiagnostic(name: string, path: string): TypeScriptWorkspaceDetectionDiagnostic;
16
+ export declare function invalidTagTemplateDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
17
+ export declare function invalidProjectNameTemplateDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
18
+ export declare function sourceFileParseErrorDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
19
+ export declare function unresolvedImportDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
20
+ export declare function nonLiteralDynamicImportDiagnostic(path: string): TypeScriptWorkspaceDetectionDiagnostic;
21
+ export declare function unsupportedImportSyntaxDiagnostic(path: string, message: string): TypeScriptWorkspaceDetectionDiagnostic;
22
+ export declare function sourceFileOutsideProjectDiagnostic(path: string, filePath: string): TypeScriptWorkspaceDetectionDiagnostic;
23
+ export declare function resolvedImportOutsideProjectDiagnostic(path: string, filePath: string): TypeScriptWorkspaceDetectionDiagnostic;
24
+ export declare function unresolvedInternalImportDiagnostic(path: string, sourceFile: string, specifier: string): TypeScriptWorkspaceDetectionDiagnostic;
25
+ export declare function ambiguousProjectMatchDiagnostic(path: string, filePath: string, projectIds: readonly string[]): TypeScriptWorkspaceDetectionDiagnostic;
26
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sCAAsC,EACtC,6BAA6B,EAC9B,MAAM,YAAY,CAAC;AAIpB,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,GACf,sCAAsC,CAOxC;AAED,wBAAgB,mCAAmC,CACjD,UAAU,EAAE,6BAA6B,GACxC,sCAAsC,CAUxC;AAED,wBAAgB,+BAA+B,IAAI,sCAAsC,CAOxF;AAED,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,sCAAsC,CAOxC;AAED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OAAO,EAAE,MAAM,GACd,sCAAsC,CAOxC;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,GACX,sCAAsC,CAQxC;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,sCAAsC,CAOxC;AAED,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,sCAAsC,CAOxC;AAED,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,sCAAsC,CAOxC;AAED,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,sCAAsC,CAOxC;AAED,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,sCAAsC,CAUxC"}
@@ -0,0 +1,8 @@
1
+ import { GovernanceProjectInput } from '@anarchitects/governance-core';
2
+ import { TsConfigResolutionModel, TypeScriptImportGraph } from './types.js';
3
+ export declare function buildTypeScriptImportGraph(options: {
4
+ workspaceRoot: string;
5
+ projects: readonly GovernanceProjectInput[];
6
+ tsconfig?: TsConfigResolutionModel;
7
+ }): TypeScriptImportGraph;
8
+ //# sourceMappingURL=import-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-graph.d.ts","sourceRoot":"","sources":["../src/import-graph.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAK5E,OAAO,KAAK,EACV,uBAAuB,EAEvB,qBAAqB,EAGtB,MAAM,YAAY,CAAC;AAIpB,wBAAgB,0BAA0B,CAAC,OAAO,EAAE;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC5C,QAAQ,CAAC,EAAE,uBAAuB,CAAC;CACpC,GAAG,qBAAqB,CAyCxB"}
@@ -0,0 +1,10 @@
1
+ export { detectTypeScriptWorkspace } from './detect-typescript-workspace.js';
2
+ export { buildTypeScriptImportGraph } from './import-graph.js';
3
+ export { DEFAULT_TYPESCRIPT_PROJECT_DISCOVERY_CONFIG, createGovernanceWorkspaceAdapter, createTypeScriptWorkspaceAdapter, governanceWorkspaceAdapter, type CreateGovernanceWorkspaceAdapterOptions, type CreateTypeScriptWorkspaceAdapterOptions, } from './workspace-adapter.js';
4
+ export { mapTypeScriptImportsToGovernanceDependencies } from './map-imports-to-projects.js';
5
+ export { parsePackageManagerWorkspace } from './parse-package-manager-workspace.js';
6
+ export { parseTsConfigResolution } from './parse-tsconfig.js';
7
+ export { discoverTypeScriptProjects } from './project-discovery.js';
8
+ export { deriveProjectTags, type DerivedProjectTags } from './tag-mapping.js';
9
+ export type { TsConfigResolutionModel, TypeScriptImportEdge, TypeScriptImportGraph, TypeScriptImportKind, TypeScriptProjectDependencyMappingResult, TypeScriptProjectDiscoveryConfig, TypeScriptProjectDiscoveryResult, TypeScriptProjectDiscoveryRule, TypeScriptSourceFileNode, TypeScriptWorkspaceDetectionDiagnostic, TypeScriptWorkspaceDetectionResult, TypeScriptWorkspaceDetectionStatus, TypeScriptWorkspaceIndicators, TypeScriptWorkspacePackageManager, WorkspacePackageResolution, } from './types.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,2CAA2C,EAC3C,gCAAgC,EAChC,gCAAgC,EAChC,0BAA0B,EAC1B,KAAK,uCAAuC,EAC5C,KAAK,uCAAuC,GAC7C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,4CAA4C,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,YAAY,EACV,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,wCAAwC,EACxC,gCAAgC,EAChC,gCAAgC,EAChC,8BAA8B,EAC9B,wBAAwB,EACxB,sCAAsC,EACtC,kCAAkC,EAClC,kCAAkC,EAClC,6BAA6B,EAC7B,iCAAiC,EACjC,0BAA0B,GAC3B,MAAM,YAAY,CAAC"}