@codependix/file-imports 0.0.0-stage → 0.0.4
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +469 -2
- package/dist/src/index.d.ts +504 -0
- package/dist/src/index.js +461 -0
- package/package.json +61 -3
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { default as default_2 } from 'typescript';
|
|
2
|
+
|
|
3
|
+
/** Header declaring the mermaid diagram type and its default layout direction. */
|
|
4
|
+
export declare const FILE_IMPORTS_WORKSPACE_GRAPH_MERMAID_HEADER = "graph LR";
|
|
5
|
+
|
|
6
|
+
/** Rendered in place of a diagram for a workspace with no internal file imports at all. */
|
|
7
|
+
export declare const FILE_IMPORTS_WORKSPACE_GRAPH_UNCONNECTED = "_This workspace has no internal file imports, in any project._";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The whole-workspace file-level import graph: every TypeScript and Python
|
|
11
|
+
* project's own internal import graph, combined into one.
|
|
12
|
+
*
|
|
13
|
+
* Exported once at the workspace root rather than once per project — see
|
|
14
|
+
* `codependix-nx-projects`'s `WorkspaceGraph`, which this mirrors. A file name
|
|
15
|
+
* alone is not unique across the workspace the way a project name is, so
|
|
16
|
+
* every node here is qualified with the project it belongs to (see
|
|
17
|
+
* `WorkspaceGraphService.qualifyFileName`) rather than reused as-is from a
|
|
18
|
+
* single project's `TypescriptImportGraph`/`PythonImportGraph`.
|
|
19
|
+
*/
|
|
20
|
+
export declare interface FileImportsWorkspaceGraph {
|
|
21
|
+
/** Every drawn import relationship, sorted so the diagram never churns. */
|
|
22
|
+
readonly edges: FileImportsWorkspaceGraphEdge[];
|
|
23
|
+
/** Every file in the graph, qualified by project and sorted. */
|
|
24
|
+
readonly fileNames: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One file importing another, both qualified by the project they belong to. */
|
|
28
|
+
export declare interface FileImportsWorkspaceGraphEdge {
|
|
29
|
+
readonly source: string;
|
|
30
|
+
readonly target: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Provides the whole-workspace file-level import graph builder. */
|
|
34
|
+
export declare class FileImportsWorkspaceGraphModule {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Builds the whole-workspace file-level import graph — every TypeScript and
|
|
39
|
+
* Python project's own internal import graph, combined into one — exported
|
|
40
|
+
* once at the workspace root rather than once per project.
|
|
41
|
+
*
|
|
42
|
+
* Combines both languages into one graph rather than two, matching how
|
|
43
|
+
* `fileImports` reads as one merged concept everywhere else in codependix:
|
|
44
|
+
* `boundaries.fileImports` is the only place the two still separate, because
|
|
45
|
+
* a Python file can never import a TypeScript file or vice versa and the rule
|
|
46
|
+
* vocabularies differ — nothing like that applies to simply drawing both
|
|
47
|
+
* languages' already-built graphs on one page.
|
|
48
|
+
*
|
|
49
|
+
* A file name alone is only unique within its own project, unlike an Nx
|
|
50
|
+
* project name, which is unique workspace-wide — so every node is qualified
|
|
51
|
+
* with the project it belongs to before the two languages' graphs are
|
|
52
|
+
* combined, mirroring `codependix-nx-projects`'s `WorkspaceGraphService`
|
|
53
|
+
* without reusing its code, since the two build genuinely different kinds of
|
|
54
|
+
* graph from genuinely different sources.
|
|
55
|
+
*/
|
|
56
|
+
export declare class FileImportsWorkspaceGraphService {
|
|
57
|
+
constructor();
|
|
58
|
+
/** Sorts edges by source then target so a rendered diagram never churns. */
|
|
59
|
+
private compareEdges;
|
|
60
|
+
/** Qualifies a project-relative file name with the project it belongs to. */
|
|
61
|
+
private qualifyFileName;
|
|
62
|
+
/** Renders one qualified file name as a mermaid node. */
|
|
63
|
+
private renderNode;
|
|
64
|
+
/** Sorts names into a stable order. */
|
|
65
|
+
private sortNames;
|
|
66
|
+
/** Turns a qualified file name into an identifier mermaid accepts. */
|
|
67
|
+
private toNodeIdentifier;
|
|
68
|
+
/**
|
|
69
|
+
* Builds the whole-workspace file-level import graph from every discovered
|
|
70
|
+
* TypeScript and Python project's own already-built import graph.
|
|
71
|
+
*/
|
|
72
|
+
buildWorkspaceGraph(args: {
|
|
73
|
+
pythonGraphs: PythonImportGraph[];
|
|
74
|
+
typescriptGraphs: TypescriptImportGraph[];
|
|
75
|
+
}): FileImportsWorkspaceGraph;
|
|
76
|
+
/** Renders the whole-workspace file-level import graph as a mermaid diagram. */
|
|
77
|
+
renderMermaid(workspaceGraph: FileImportsWorkspaceGraph): string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A Python project's internal file-level import Graph: which of its own
|
|
82
|
+
* files import which other of its own files.
|
|
83
|
+
*
|
|
84
|
+
* Shaped identically to the `typescript` module's `TypescriptImportGraph`,
|
|
85
|
+
* kept as its own type rather than shared: the two modules build the same
|
|
86
|
+
* kind of graph from entirely different sources — a `ts.Program` versus a
|
|
87
|
+
* hand-rolled statement parser — the same independence `codependix-nx-projects` and
|
|
88
|
+
* `codependix-nestjs-modules` already keep from each other and from
|
|
89
|
+
* `codependix-file-imports`.
|
|
90
|
+
*/
|
|
91
|
+
export declare interface PythonImportGraph {
|
|
92
|
+
/** Every drawn import relationship, sorted so the diagram never churns. */
|
|
93
|
+
readonly edges: PythonImportGraphEdge[];
|
|
94
|
+
/** Every source file in the graph, project-relative and sorted. */
|
|
95
|
+
readonly fileNames: string[];
|
|
96
|
+
/** Files left with no drawn edge in either direction. */
|
|
97
|
+
readonly isolatedFileNames: string[];
|
|
98
|
+
/** The project the graph was built from. */
|
|
99
|
+
readonly projectName: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** One file importing another, both paths project-relative. */
|
|
103
|
+
export declare interface PythonImportGraphEdge {
|
|
104
|
+
readonly source: string;
|
|
105
|
+
readonly target: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Builds a Python project's internal file-level import Graph, and renders it.
|
|
110
|
+
*
|
|
111
|
+
* Every source file's top-level import statements are read through
|
|
112
|
+
* `PythonImportParserService`, then each specifier is resolved to a real
|
|
113
|
+
* file with `resolveSpecifierPath` — the closest Python equivalent of
|
|
114
|
+
* `ts.resolveModuleName`, since Python has no compiler API to delegate to.
|
|
115
|
+
* An absolute specifier (`from src.grammars import Grammar`) resolves
|
|
116
|
+
* relative to the project root; a relative one (`from .grammars import Grammar`)
|
|
117
|
+
* resolves relative to the importing file's own directory, ascended once per
|
|
118
|
+
* extra leading dot. An edge is kept only when it resolves to a file this
|
|
119
|
+
* project owns, the same rule `TypescriptImportGraphService.buildGraph` applies.
|
|
120
|
+
*/
|
|
121
|
+
export declare class PythonImportGraphService {
|
|
122
|
+
private readonly pythonImportParserService;
|
|
123
|
+
private readonly pythonProjectService;
|
|
124
|
+
constructor(pythonImportParserService: PythonImportParserService, pythonProjectService: PythonProjectService);
|
|
125
|
+
/** Walks a directory upward a number of levels. */
|
|
126
|
+
private ascendDirectories;
|
|
127
|
+
/** Collects every internal import edge one source file declares. */
|
|
128
|
+
private collectEdgesForFile;
|
|
129
|
+
/** Sorts edges by source then target so a rendered diagram never churns. */
|
|
130
|
+
private compareEdges;
|
|
131
|
+
/** Drops duplicate edges, keeping the sorted order they were built in. */
|
|
132
|
+
private dedupeEdges;
|
|
133
|
+
/** Renders one file as a mermaid node, labelled with its relative path. */
|
|
134
|
+
private renderNode;
|
|
135
|
+
/**
|
|
136
|
+
* Resolves an import specifier to an absolute file path, checked against
|
|
137
|
+
* the filesystem — the closest Python has to `ts.resolveModuleName`
|
|
138
|
+
* checking against a compiler host.
|
|
139
|
+
*
|
|
140
|
+
* A specifier with no module path (`from . import name`) resolves the
|
|
141
|
+
* package directory itself — its `__init__.py` — since there is no
|
|
142
|
+
* standalone file a bare relative import could otherwise name.
|
|
143
|
+
*/
|
|
144
|
+
private resolveSpecifierPath;
|
|
145
|
+
/** Turns a relative file path into an identifier mermaid accepts. */
|
|
146
|
+
private toNodeIdentifier;
|
|
147
|
+
/** Expresses an absolute file path relative to its project, POSIX-style. */
|
|
148
|
+
private toRelativePath;
|
|
149
|
+
/** Builds a Python project's internal file-level import Graph. */
|
|
150
|
+
buildGraph(project: PythonProject): PythonImportGraph;
|
|
151
|
+
/** Renders an import graph as a fenced mermaid diagram. */
|
|
152
|
+
renderMermaid(graph: PythonImportGraph): string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Parses a Python source file's top-level `import`/`from ... import`
|
|
157
|
+
* statements into the module each one names.
|
|
158
|
+
*
|
|
159
|
+
* There is no `ast`-equivalent compiler API available from Node the way
|
|
160
|
+
* `ts.isImportDeclaration` walks a real `ts.Program`, so statements are
|
|
161
|
+
* recognized with a small hand-rolled scanner instead: comments and quoted
|
|
162
|
+
* strings are stripped so a `#` or a quote character inside either never
|
|
163
|
+
* confuses the parser, a statement's continuation lines are rejoined by
|
|
164
|
+
* tracking parenthesis depth and trailing backslashes, and only statements
|
|
165
|
+
* starting at column zero are considered — an import nested inside a
|
|
166
|
+
* function or a conditional is deliberately not walked, the same way a
|
|
167
|
+
* TypeScript `import` declaration can only ever appear at module scope.
|
|
168
|
+
*/
|
|
169
|
+
export declare class PythonImportParserService {
|
|
170
|
+
constructor();
|
|
171
|
+
/**
|
|
172
|
+
* Rejoins a statement's continuation lines starting at `startIndex` into
|
|
173
|
+
* one line, tracking parenthesis depth and trailing backslashes.
|
|
174
|
+
*/
|
|
175
|
+
private collectStatement;
|
|
176
|
+
/** Counts how many times a single character appears in a line. */
|
|
177
|
+
private countCharacter;
|
|
178
|
+
/** Whether a raw line starts a module-level `import`/`from` statement. */
|
|
179
|
+
private isTopLevelImportStart;
|
|
180
|
+
/** Counts a raw line's leading whitespace. */
|
|
181
|
+
private measureIndent;
|
|
182
|
+
/** Parses a joined `from <dots><module> import ...` statement. */
|
|
183
|
+
private parseFromStatement;
|
|
184
|
+
/** Parses a joined `import <specifiers>` statement. */
|
|
185
|
+
private parseImportStatement;
|
|
186
|
+
/** Parses one joined statement into the module(s) it names. */
|
|
187
|
+
private parseStatement;
|
|
188
|
+
/** Strips a trailing `#` comment, ignoring one found inside a quoted string. */
|
|
189
|
+
private stripComment;
|
|
190
|
+
/** Parses every module-level import statement in a Python source file. */
|
|
191
|
+
parseImportSpecifiers(source: string): PythonImportSpecifier[];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* One module a Python `import`/`from ... import` statement names.
|
|
196
|
+
*
|
|
197
|
+
* Only the module being imported from is kept — which names a `from`
|
|
198
|
+
* statement pulls out of it is irrelevant to a file-level import graph, the
|
|
199
|
+
* same way `codependix-file-imports` resolves only a TypeScript import
|
|
200
|
+
* declaration's `moduleSpecifier` and never looks at what it binds.
|
|
201
|
+
*/
|
|
202
|
+
declare interface PythonImportSpecifier {
|
|
203
|
+
/**
|
|
204
|
+
* How many leading dots a `from` statement's module carried.
|
|
205
|
+
*
|
|
206
|
+
* `0` for an absolute import (`import`, or `from x import y`); `1` for
|
|
207
|
+
* `from . import y` or `from .x import y`; `2` for `from .. import y`;
|
|
208
|
+
* and so on.
|
|
209
|
+
*/
|
|
210
|
+
readonly level: number;
|
|
211
|
+
/**
|
|
212
|
+
* The dotted module path, with dots left in (`"src.grammars"`), or an
|
|
213
|
+
* empty string for a bare relative import (`from . import y`).
|
|
214
|
+
*/
|
|
215
|
+
readonly modulePath: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Provides the `python` module's public surface, `PythonService`.
|
|
220
|
+
*
|
|
221
|
+
* `PythonProjectService`, `PythonImportParserService`, and
|
|
222
|
+
* `PythonImportGraphService` stay internal collaborators — not exported —
|
|
223
|
+
* so a consumer of this package reaches every Python capability through one
|
|
224
|
+
* facade.
|
|
225
|
+
*/
|
|
226
|
+
export declare class PythonModule {
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* A workspace project tagged `language:python`, discovered from the Nx
|
|
231
|
+
* project graph the same way `codependix-nestjs-modules`'s `NestjsProject` is —
|
|
232
|
+
* Python has no per-project marker file as reliable as a NestJS project's
|
|
233
|
+
* root module, since every Python project shares one workspace-root
|
|
234
|
+
* `pyproject.toml` (see the `write-python` skill) even when it also carries
|
|
235
|
+
* its own.
|
|
236
|
+
*/
|
|
237
|
+
export declare interface PythonProject {
|
|
238
|
+
/** Absolute path of the project directory. */
|
|
239
|
+
readonly absoluteRoot: string;
|
|
240
|
+
/** Project directory name, which is also the Nx project name. */
|
|
241
|
+
readonly name: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Discovers the workspace's Python projects and lists each one's source
|
|
246
|
+
* files.
|
|
247
|
+
*
|
|
248
|
+
* Discovery reads each project's own `language:python` tag, the same
|
|
249
|
+
* way `codependix-nestjs-modules`'s `NestjsProjectService` reads `framework:nestjs` —
|
|
250
|
+
* rather than probing for a marker file, since a Python project's own
|
|
251
|
+
* `pyproject.toml` is optional (every project is already a member of the
|
|
252
|
+
* workspace root's, per the `write-python` skill).
|
|
253
|
+
*/
|
|
254
|
+
export declare class PythonProjectService {
|
|
255
|
+
constructor();
|
|
256
|
+
/** Recursively lists every `.py` file beneath a directory, depth first. */
|
|
257
|
+
private listSourceFilesInDirectory;
|
|
258
|
+
/** Describes a project by its directory and Nx project name. */
|
|
259
|
+
describeProject(absoluteRoot: string, name: string): PythonProject;
|
|
260
|
+
/**
|
|
261
|
+
* Filters an already-read list of Nx projects down to the ones tagged
|
|
262
|
+
* `language:python`, and describes each one.
|
|
263
|
+
*
|
|
264
|
+
* Projects are returned in the order they were given, which callers keep
|
|
265
|
+
* sorted by name — the same order `TypescriptProjectService.discoverProjects`
|
|
266
|
+
* preserves.
|
|
267
|
+
*/
|
|
268
|
+
discoverProjects(projects: {
|
|
269
|
+
absoluteRoot: string;
|
|
270
|
+
name: string;
|
|
271
|
+
tags: string[];
|
|
272
|
+
}[]): PythonProject[];
|
|
273
|
+
/** Reports whether a project's Nx tags mark it as a Python project. */
|
|
274
|
+
isPythonProject(project: {
|
|
275
|
+
tags: string[];
|
|
276
|
+
}): boolean;
|
|
277
|
+
/** Lists a project's own source files, absolute and sorted. */
|
|
278
|
+
listSourceFileNames(project: PythonProject): string[];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The `python` module's public surface: discovers the workspace's Python
|
|
283
|
+
* projects, and builds and renders one project's file-level import Graph.
|
|
284
|
+
*
|
|
285
|
+
* A thin facade over `PythonProjectService` (project discovery and
|
|
286
|
+
* source-file listing) and `PythonImportGraphService` (parsing those files'
|
|
287
|
+
* imports into a graph, itself backed by `PythonImportParserService`) —
|
|
288
|
+
* kept as separate collaborators internally so each stays focused, with
|
|
289
|
+
* this class the one file this repository's conformetry template for a
|
|
290
|
+
* NestJS service module expects a flat module to expose.
|
|
291
|
+
*/
|
|
292
|
+
export declare class PythonService {
|
|
293
|
+
private readonly pythonImportGraphService;
|
|
294
|
+
private readonly pythonProjectService;
|
|
295
|
+
constructor(pythonImportGraphService: PythonImportGraphService, pythonProjectService: PythonProjectService);
|
|
296
|
+
/** Builds a Python project's internal file-level import Graph. */
|
|
297
|
+
buildGraph(project: PythonProject): PythonImportGraph;
|
|
298
|
+
/**
|
|
299
|
+
* Filters an already-read list of Nx projects down to the ones tagged
|
|
300
|
+
* `language:python`, and describes each one.
|
|
301
|
+
*/
|
|
302
|
+
discoverProjects(projects: {
|
|
303
|
+
absoluteRoot: string;
|
|
304
|
+
name: string;
|
|
305
|
+
tags: string[];
|
|
306
|
+
}[]): PythonProject[];
|
|
307
|
+
/** Renders an import graph as a fenced mermaid diagram. */
|
|
308
|
+
renderMermaid(graph: PythonImportGraph): string;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* A TypeScript project's internal file-level import Graph: which of its own
|
|
313
|
+
* files import which other of its own files.
|
|
314
|
+
*
|
|
315
|
+
* Only edges resolving to a file inside the project are kept — an import of
|
|
316
|
+
* an external package or of another workspace project resolves outside
|
|
317
|
+
* `fileNames` and is left out, the same way `Neighborhood` only draws edges
|
|
318
|
+
* between projects it already knows about.
|
|
319
|
+
*/
|
|
320
|
+
export declare interface TypescriptImportGraph {
|
|
321
|
+
/** Every drawn import relationship, sorted so the diagram never churns. */
|
|
322
|
+
readonly edges: TypescriptImportGraphEdge[];
|
|
323
|
+
/** Every source file in the graph, project-relative and sorted. */
|
|
324
|
+
readonly fileNames: string[];
|
|
325
|
+
/** Files left with no drawn edge in either direction. */
|
|
326
|
+
readonly isolatedFileNames: string[];
|
|
327
|
+
/** The project the graph was built from. */
|
|
328
|
+
readonly projectName: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** One file importing another, both paths project-relative. */
|
|
332
|
+
export declare interface TypescriptImportGraphEdge {
|
|
333
|
+
readonly source: string;
|
|
334
|
+
readonly target: string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Builds a project's internal file-level import Graph from a `ts.Program`,
|
|
339
|
+
* and renders it.
|
|
340
|
+
*
|
|
341
|
+
* Every import specifier is resolved through `ts.resolveModuleName`, called
|
|
342
|
+
* with the exact compiler options and host `TypescriptProjectService` built
|
|
343
|
+
* the program with — the compiler's own module resolution, so this
|
|
344
|
+
* workspace's TypeScript path aliases and NodeNext `.js`-extension imports
|
|
345
|
+
* resolve to the real `.ts` source file they point at, rather than through a
|
|
346
|
+
* hand-written path heuristic. Import declarations are detected the same way
|
|
347
|
+
* `codometer-cli`'s `TypescriptService.handleImport` does: `ts.isImportDeclaration`
|
|
348
|
+
* on a string-literal module specifier.
|
|
349
|
+
*/
|
|
350
|
+
export declare class TypescriptImportGraphService {
|
|
351
|
+
private readonly typescriptProjectService;
|
|
352
|
+
constructor(typescriptProjectService: TypescriptProjectService);
|
|
353
|
+
/** Collects every internal import edge one source file declares. */
|
|
354
|
+
private collectEdgesForFile;
|
|
355
|
+
/** Sorts edges by source then target so a rendered diagram never churns. */
|
|
356
|
+
private compareEdges;
|
|
357
|
+
/** Drops duplicate edges, keeping the sorted order they were built in. */
|
|
358
|
+
private dedupeEdges;
|
|
359
|
+
/**
|
|
360
|
+
* Lists a program's own source files, excluding declaration files.
|
|
361
|
+
*
|
|
362
|
+
* `program.getRootFileNames()` is the same file list
|
|
363
|
+
* `TypescriptProjectService.buildProgram` handed to `ts.createProgram` —
|
|
364
|
+
* the project's own files, not the ones it merely pulls in as
|
|
365
|
+
* dependencies.
|
|
366
|
+
*/
|
|
367
|
+
private listOwnedSourceFileNames;
|
|
368
|
+
/** Renders one file as a mermaid node, labelled with its relative path. */
|
|
369
|
+
private renderNode;
|
|
370
|
+
/** Resolves an import specifier to a real, absolute file path. */
|
|
371
|
+
private resolveImportTarget;
|
|
372
|
+
/** Resolves the real, absolute file names a program owns. */
|
|
373
|
+
private resolveOwnedFileNames;
|
|
374
|
+
/** Turns a relative file path into an identifier mermaid accepts. */
|
|
375
|
+
private toNodeIdentifier;
|
|
376
|
+
/** Expresses an absolute file path relative to its project, POSIX-style. */
|
|
377
|
+
private toRelativePath;
|
|
378
|
+
/** Builds a project's internal file-level import Graph from its program. */
|
|
379
|
+
buildGraph(projectProgram: TypescriptProjectProgram): TypescriptImportGraph;
|
|
380
|
+
/** Renders an import graph as a fenced mermaid diagram. */
|
|
381
|
+
renderMermaid(graph: TypescriptImportGraph): string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Provides the `typescript` module's public surface, `TypescriptService`.
|
|
386
|
+
*
|
|
387
|
+
* `TypescriptProjectService` and `TypescriptImportGraphService` stay
|
|
388
|
+
* internal collaborators — not exported — so a consumer of this package
|
|
389
|
+
* reaches every TypeScript capability through one facade.
|
|
390
|
+
*/
|
|
391
|
+
export declare class TypescriptModule {
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* A workspace project whose own `tsconfig.json` can be turned into a program.
|
|
396
|
+
*
|
|
397
|
+
* Every workspace project is a candidate, unlike `codependix-nestjs-modules`'s
|
|
398
|
+
* `NestjsProject`, which is gated to projects tagged `framework:nestjs` — a
|
|
399
|
+
* file-level import graph is meaningful for any TypeScript project.
|
|
400
|
+
*/
|
|
401
|
+
export declare interface TypescriptProject {
|
|
402
|
+
/** Absolute path of the project directory. */
|
|
403
|
+
readonly absoluteRoot: string;
|
|
404
|
+
/** Project directory name, which is also the Nx project name. */
|
|
405
|
+
readonly name: string;
|
|
406
|
+
/** Absolute path of the project's `tsconfig.json`. */
|
|
407
|
+
readonly tsconfigPath: string;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* One project's program together with the compiler host and options that
|
|
412
|
+
* built it.
|
|
413
|
+
*
|
|
414
|
+
* The host and options travel with the program rather than being rebuilt by
|
|
415
|
+
* `TypescriptImportGraphService`: resolving an import specifier through
|
|
416
|
+
* `ts.resolveModuleName` needs the exact same host and options the program
|
|
417
|
+
* itself was built with, or module resolution could silently disagree with
|
|
418
|
+
* what the program actually parsed.
|
|
419
|
+
*/
|
|
420
|
+
export declare interface TypescriptProjectProgram {
|
|
421
|
+
readonly host: default_2.CompilerHost;
|
|
422
|
+
readonly options: default_2.CompilerOptions;
|
|
423
|
+
readonly program: default_2.Program;
|
|
424
|
+
readonly project: TypescriptProject;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Discovers the workspace's TypeScript projects and builds a `ts.Program`
|
|
429
|
+
* for each one.
|
|
430
|
+
*
|
|
431
|
+
* Every project carrying its own `tsconfig.json` is a candidate — unlike
|
|
432
|
+
* `codependix-nestjs-modules`'s `NestjsProjectService`, discovery reads no Nx tag,
|
|
433
|
+
* since a file-level import graph is meaningful for any TypeScript project.
|
|
434
|
+
* `ts.createProgram` is built the same way `callidescope-cli`'s
|
|
435
|
+
* `ProgramService` builds one: reading and fully resolving the project's own
|
|
436
|
+
* `tsconfig.json` through `ts.parseJsonSourceFileConfigFileContent`, so the
|
|
437
|
+
* program's module resolution — and therefore
|
|
438
|
+
* `TypescriptImportGraphService`'s — agrees with what `tsc` itself would resolve for
|
|
439
|
+
* this workspace's path aliases and NodeNext `.js`-extension imports.
|
|
440
|
+
*/
|
|
441
|
+
export declare class TypescriptProjectService {
|
|
442
|
+
constructor();
|
|
443
|
+
/**
|
|
444
|
+
* Reads and fully resolves one project's compiler options.
|
|
445
|
+
*
|
|
446
|
+
* The configuration file name is passed as the fifth argument so that
|
|
447
|
+
* TypeScript follows the `extends` chain to the shared base config and
|
|
448
|
+
* reports diagnostics against the right file, mirroring
|
|
449
|
+
* `callidescope-cli`'s `ProgramService.parseConfiguration`.
|
|
450
|
+
*/
|
|
451
|
+
private parseConfiguration;
|
|
452
|
+
/** Builds one project's program, keeping the host and options alongside it. */
|
|
453
|
+
buildProgram(project: TypescriptProject): TypescriptProjectProgram;
|
|
454
|
+
/** Describes a project by its directory and Nx project name. */
|
|
455
|
+
describeProject(absoluteRoot: string, name: string): TypescriptProject;
|
|
456
|
+
/**
|
|
457
|
+
* Filters an already-read list of Nx projects down to the ones carrying
|
|
458
|
+
* their own `tsconfig.json`, and describes each one.
|
|
459
|
+
*
|
|
460
|
+
* Projects are returned in the order they were given, which callers keep
|
|
461
|
+
* sorted by name — the same order `codependix-nx-projects`'s `NeighborhoodService`
|
|
462
|
+
* reads the Nx project graph's own projects in.
|
|
463
|
+
*/
|
|
464
|
+
discoverProjects(projects: {
|
|
465
|
+
absoluteRoot: string;
|
|
466
|
+
name: string;
|
|
467
|
+
}[]): TypescriptProject[];
|
|
468
|
+
/** Resolves a path through symlinks, which is how pnpm workspaces link. */
|
|
469
|
+
toRealPath(filePath: string): string;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* The `typescript` module's public surface: discovers the workspace's
|
|
474
|
+
* TypeScript projects, builds each one's `ts.Program`, and builds and
|
|
475
|
+
* renders its file-level import Graph.
|
|
476
|
+
*
|
|
477
|
+
* A thin facade over `TypescriptProjectService` (project discovery and
|
|
478
|
+
* `ts.Program` construction) and `TypescriptImportGraphService` (walking
|
|
479
|
+
* that program into a graph) — kept as two separate collaborators
|
|
480
|
+
* internally so each stays focused, with this class the one file this
|
|
481
|
+
* repository's conformetry template for a NestJS service module expects a
|
|
482
|
+
* flat module to expose.
|
|
483
|
+
*/
|
|
484
|
+
export declare class TypescriptService {
|
|
485
|
+
private readonly typescriptImportGraphService;
|
|
486
|
+
private readonly typescriptProjectService;
|
|
487
|
+
constructor(typescriptImportGraphService: TypescriptImportGraphService, typescriptProjectService: TypescriptProjectService);
|
|
488
|
+
/** Builds a project's internal file-level import Graph from its program. */
|
|
489
|
+
buildGraph(projectProgram: TypescriptProjectProgram): TypescriptImportGraph;
|
|
490
|
+
/** Builds one project's program, keeping the host and options alongside it. */
|
|
491
|
+
buildProgram(project: TypescriptProject): TypescriptProjectProgram;
|
|
492
|
+
/**
|
|
493
|
+
* Filters an already-read list of Nx projects down to the ones carrying
|
|
494
|
+
* their own `tsconfig.json`, and describes each one.
|
|
495
|
+
*/
|
|
496
|
+
discoverProjects(projects: {
|
|
497
|
+
absoluteRoot: string;
|
|
498
|
+
name: string;
|
|
499
|
+
}[]): TypescriptProject[];
|
|
500
|
+
/** Renders an import graph as a fenced mermaid diagram. */
|
|
501
|
+
renderMermaid(graph: TypescriptImportGraph): string;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export { }
|