@cplieger/deadset-ts 7.2.0-dev.4 → 8.0.0-dev.10

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 (288) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/mapper-connection.js +2 -1
  3. package/dist/bin/node-host.js +24 -5
  4. package/dist/src/analysis.js +245 -309
  5. package/dist/src/augmentations.js +124 -18
  6. package/dist/src/automatic-types.js +170 -0
  7. package/dist/src/build-scripts.js +425 -0
  8. package/dist/src/component-layer.js +4 -2
  9. package/dist/src/components.js +9 -9
  10. package/dist/src/config.js +6 -81
  11. package/dist/src/configuration-files.js +78 -188
  12. package/dist/src/configured-declarations.js +15 -20
  13. package/dist/src/conformance-record.js +2 -2
  14. package/dist/src/consumers.js +3 -30
  15. package/dist/src/contextual-uses.js +56 -9
  16. package/dist/src/contract/config.generated.js +558 -0
  17. package/dist/src/contract/contract.generated.js +1244 -0
  18. package/dist/src/contract/report.generated.js +862 -0
  19. package/dist/src/convention-rows.js +146 -1
  20. package/dist/src/conventions.js +136 -70
  21. package/dist/src/decorator.js +21 -18
  22. package/dist/src/dependencies.js +280 -62
  23. package/dist/src/edges.js +38 -122
  24. package/dist/src/element-access.js +4 -6
  25. package/dist/src/entry-point-gaps.js +9 -18
  26. package/dist/src/entry-points.js +106 -21
  27. package/dist/src/enum-group.js +3 -10
  28. package/dist/src/erased-stores.js +4 -6
  29. package/dist/src/exempt-classes.js +1 -63
  30. package/dist/src/exempt.js +21 -40
  31. package/dist/src/failure.js +36 -0
  32. package/dist/src/file-facts.js +2 -25
  33. package/dist/src/findings/completion.js +225 -63
  34. package/dist/src/findings/dependencies-and-module-machinery.js +72 -27
  35. package/dist/src/findings/emitters.js +6 -6
  36. package/dist/src/findings/interfaces.js +4 -5
  37. package/dist/src/findings/intra-function.js +53 -19
  38. package/dist/src/findings/non-code-artifacts.js +71 -39
  39. package/dist/src/findings/reads-and-writes.js +16 -13
  40. package/dist/src/findings/self-check.js +10 -12
  41. package/dist/src/findings/unused-declarations.js +57 -28
  42. package/dist/src/findings/visibility-narrowing.js +40 -18
  43. package/dist/src/findings-pass.js +8 -15
  44. package/dist/src/framework-lifecycle.js +7 -7
  45. package/dist/src/fs/document.js +52 -0
  46. package/dist/src/fs/manifest.js +72 -0
  47. package/dist/src/fs/tree.js +88 -0
  48. package/dist/src/generated-file.js +18 -4
  49. package/dist/src/git-ignore.js +99 -0
  50. package/dist/src/graph.js +9 -4
  51. package/dist/src/html-entries.js +6 -33
  52. package/dist/src/import-bindings.js +97 -0
  53. package/dist/src/in-operands.js +2 -1
  54. package/dist/src/index.js +1 -1
  55. package/dist/src/indexed-access.js +130 -28
  56. package/dist/src/injection-container.js +1 -1
  57. package/dist/src/interface-satisfaction.js +30 -12
  58. package/dist/src/intra-function-parts.js +341 -69
  59. package/dist/src/inventory.js +54 -29
  60. package/dist/src/javascript-file.js +33 -0
  61. package/dist/src/json-document.js +198 -67
  62. package/dist/src/keyof-comparisons.js +4 -6
  63. package/dist/src/kinds.js +3 -366
  64. package/dist/src/load/classify.js +270 -0
  65. package/dist/src/load/diagnostics.js +80 -0
  66. package/dist/src/load/discover.js +277 -0
  67. package/dist/src/{emit-map.js → load/emit-map.js} +1 -1
  68. package/dist/src/load/expected-module.js +136 -0
  69. package/dist/src/load/load.js +27 -0
  70. package/dist/src/load/module-lookup.js +37 -0
  71. package/dist/src/load/plan.js +313 -0
  72. package/dist/src/load/specifiers.js +115 -0
  73. package/dist/src/load/synthesize.js +140 -0
  74. package/dist/src/load/test-globals.js +207 -0
  75. package/dist/src/load/test-joins.js +82 -0
  76. package/dist/src/{workspace-manifests.js → load/workspace-manifests.js} +4 -4
  77. package/dist/src/{workspace-programs.js → load/workspace-programs.js} +88 -61
  78. package/dist/src/{workspace-resolution.js → load/workspace-resolution.js} +60 -59
  79. package/dist/src/{workspace-run.js → load/workspace-run.js} +7 -7
  80. package/dist/src/{workspace.js → load/workspace.js} +62 -124
  81. package/dist/src/manifest.js +49 -54
  82. package/dist/src/matrix.js +94 -13
  83. package/dist/src/mdx-entries.js +174 -0
  84. package/dist/src/module-declarations.js +9 -13
  85. package/dist/src/outside-tests.js +1 -1
  86. package/dist/src/overrides.js +41 -10
  87. package/dist/src/partial.js +2 -1
  88. package/dist/src/paths.js +26 -15
  89. package/dist/src/position.js +2 -1
  90. package/dist/src/print.js +11 -78
  91. package/dist/src/product.js +13 -0
  92. package/dist/src/query.js +1 -0
  93. package/dist/src/ref.js +11 -0
  94. package/dist/src/references.js +52 -31
  95. package/dist/src/report-schema.js +51 -0
  96. package/dist/src/report.js +59 -41
  97. package/dist/src/reporters/annotations.js +15 -8
  98. package/dist/src/reporters/sarif.js +16 -10
  99. package/dist/src/reporters/template.js +4 -19
  100. package/dist/src/resolve.js +245 -727
  101. package/dist/src/roots.js +374 -116
  102. package/dist/src/run.js +66 -77
  103. package/dist/src/schema.js +320 -342
  104. package/dist/src/scope.js +38 -115
  105. package/dist/src/serialization-contract.js +649 -29
  106. package/dist/src/session.js +41 -29
  107. package/dist/src/source-files.js +40 -15
  108. package/dist/src/suppress-file.js +34 -29
  109. package/dist/src/suppress-inline.js +21 -4
  110. package/dist/src/suppress.js +40 -56
  111. package/dist/src/sweep.js +32 -17
  112. package/dist/src/symbol-keys.js +105 -6
  113. package/dist/src/template-field.js +9 -19
  114. package/dist/src/test-support.js +119 -18
  115. package/dist/src/text/compare.js +26 -0
  116. package/dist/src/text/glob.js +194 -0
  117. package/dist/src/text/named-files.js +54 -0
  118. package/dist/src/text/shell.js +159 -0
  119. package/dist/src/text/yaml.js +393 -0
  120. package/dist/src/type-errors.js +27 -221
  121. package/dist/src/type-parameter-reads.js +172 -0
  122. package/dist/src/unseen-loads.js +100 -0
  123. package/dist/src/unwrap.js +23 -0
  124. package/dist/src/usage.js +10 -0
  125. package/dist/src/verbs/analyze.js +181 -125
  126. package/dist/src/verbs/describe.js +9 -16
  127. package/dist/src/verbs/explain.js +14 -9
  128. package/dist/src/verbs/print-config.js +2 -1
  129. package/dist/src/verbs/print-projects.js +6 -4
  130. package/dist/src/verbs/print-retained.js +4 -2
  131. package/dist/src/verbs/print-roots.js +4 -2
  132. package/dist/src/verbs/verb.js +1 -5
  133. package/dist/src/verbs/version.js +14 -3
  134. package/dist/src/workflow-steps.js +128 -33
  135. package/jsr.json +1 -1
  136. package/package.json +5 -4
  137. package/src/analysis.ts +333 -457
  138. package/src/augmentations.ts +152 -23
  139. package/src/automatic-types.ts +228 -0
  140. package/src/build-scripts.ts +543 -0
  141. package/src/component-layer.ts +4 -2
  142. package/src/components.ts +9 -10
  143. package/src/config.ts +31 -299
  144. package/src/configuration-files.ts +100 -191
  145. package/src/configured-declarations.ts +18 -23
  146. package/src/conformance-record.ts +2 -2
  147. package/src/consumers.ts +6 -57
  148. package/src/contextual-uses.ts +64 -12
  149. package/src/contract/config.generated.ts +818 -0
  150. package/src/contract/contract.generated.ts +1308 -0
  151. package/src/contract/report.generated.ts +1237 -0
  152. package/src/convention-rows.ts +186 -1
  153. package/src/conventions.ts +166 -90
  154. package/src/decorator.ts +28 -18
  155. package/src/dependencies.ts +356 -78
  156. package/src/edges.ts +41 -140
  157. package/src/element-access.ts +4 -7
  158. package/src/entry-point-gaps.ts +11 -20
  159. package/src/entry-points.ts +124 -28
  160. package/src/enum-group.ts +2 -11
  161. package/src/erased-stores.ts +3 -7
  162. package/src/exempt-classes.ts +1 -75
  163. package/src/exempt.ts +36 -50
  164. package/src/failure.ts +63 -0
  165. package/src/file-facts.ts +9 -24
  166. package/src/finding.ts +24 -9
  167. package/src/findings/boundary.ts +2 -0
  168. package/src/findings/completion.ts +297 -77
  169. package/src/findings/dependencies-and-module-machinery.ts +90 -31
  170. package/src/findings/emitter.ts +8 -9
  171. package/src/findings/emitters.ts +8 -8
  172. package/src/findings/interfaces.ts +4 -6
  173. package/src/findings/intra-function.ts +64 -20
  174. package/src/findings/non-code-artifacts.ts +88 -50
  175. package/src/findings/reads-and-writes.ts +20 -16
  176. package/src/findings/self-check.ts +11 -17
  177. package/src/findings/unused-declarations.ts +65 -28
  178. package/src/findings/visibility-narrowing.ts +51 -19
  179. package/src/findings-pass.ts +10 -19
  180. package/src/framework-lifecycle.ts +7 -7
  181. package/src/fs/document.ts +70 -0
  182. package/src/fs/manifest.ts +92 -0
  183. package/src/fs/tree.ts +110 -0
  184. package/src/generated-file.ts +23 -4
  185. package/src/git-ignore.ts +122 -0
  186. package/src/graph.ts +11 -3
  187. package/src/host.ts +17 -14
  188. package/src/html-entries.ts +6 -33
  189. package/src/import-bindings.ts +128 -0
  190. package/src/in-operands.ts +2 -1
  191. package/src/index.ts +1 -1
  192. package/src/indexed-access.ts +152 -30
  193. package/src/injection-container.ts +1 -1
  194. package/src/interface-satisfaction.ts +33 -13
  195. package/src/intra-function-parts.ts +449 -85
  196. package/src/inventory.ts +73 -27
  197. package/src/javascript-file.ts +37 -0
  198. package/src/json-document.ts +241 -76
  199. package/src/keyof-comparisons.ts +3 -7
  200. package/src/kinds.ts +5 -413
  201. package/src/load/classify.ts +397 -0
  202. package/src/load/diagnostics.ts +144 -0
  203. package/src/load/discover.ts +455 -0
  204. package/src/{emit-map.ts → load/emit-map.ts} +1 -1
  205. package/src/load/expected-module.ts +188 -0
  206. package/src/load/load.ts +73 -0
  207. package/src/load/module-lookup.ts +50 -0
  208. package/src/load/plan.ts +504 -0
  209. package/src/load/specifiers.ts +168 -0
  210. package/src/load/synthesize.ts +211 -0
  211. package/src/load/test-globals.ts +251 -0
  212. package/src/load/test-joins.ts +98 -0
  213. package/src/{workspace-manifests.ts → load/workspace-manifests.ts} +5 -5
  214. package/src/{workspace-programs.ts → load/workspace-programs.ts} +127 -80
  215. package/src/{workspace-resolution.ts → load/workspace-resolution.ts} +73 -64
  216. package/src/{workspace-run.ts → load/workspace-run.ts} +18 -16
  217. package/src/{workspace.ts → load/workspace.ts} +90 -134
  218. package/src/manifest.ts +81 -75
  219. package/src/matrix.ts +154 -18
  220. package/src/mdx-entries.ts +218 -0
  221. package/src/module-declarations.ts +11 -13
  222. package/src/outside-tests.ts +1 -1
  223. package/src/overrides.ts +51 -12
  224. package/src/partial.ts +3 -2
  225. package/src/paths.ts +27 -15
  226. package/src/position.ts +2 -1
  227. package/src/print.ts +12 -91
  228. package/src/product.ts +18 -0
  229. package/src/query.ts +11 -0
  230. package/src/ref.ts +13 -0
  231. package/src/references.ts +62 -32
  232. package/src/report-schema.ts +68 -0
  233. package/src/report.ts +105 -215
  234. package/src/reporters/annotations.ts +22 -11
  235. package/src/reporters/json.ts +1 -1
  236. package/src/reporters/reporter.ts +2 -4
  237. package/src/reporters/reporters.ts +1 -1
  238. package/src/reporters/sarif.ts +29 -16
  239. package/src/reporters/template.ts +4 -20
  240. package/src/reporters/text.ts +3 -3
  241. package/src/resolve.ts +283 -1111
  242. package/src/roots.ts +490 -137
  243. package/src/run.ts +75 -91
  244. package/src/schema.ts +391 -387
  245. package/src/scope.ts +46 -138
  246. package/src/serialization-contract.ts +818 -26
  247. package/src/session.ts +77 -54
  248. package/src/source-files.ts +67 -17
  249. package/src/suppress-file.ts +36 -34
  250. package/src/suppress-inline.ts +20 -3
  251. package/src/suppress.ts +52 -63
  252. package/src/sweep.ts +53 -18
  253. package/src/symbol-keys.ts +131 -7
  254. package/src/template-field.ts +15 -25
  255. package/src/test-support.ts +155 -18
  256. package/src/text/compare.ts +27 -0
  257. package/src/text/glob.ts +210 -0
  258. package/src/text/named-files.inputs.json +1522 -0
  259. package/src/text/named-files.ts +68 -0
  260. package/src/text/shell.ts +161 -0
  261. package/src/text/yaml.ts +423 -0
  262. package/src/type-errors.ts +35 -273
  263. package/src/type-parameter-reads.ts +227 -0
  264. package/src/unseen-loads.ts +134 -0
  265. package/src/unwrap.ts +34 -0
  266. package/src/usage.ts +10 -0
  267. package/src/verbs/analyze.ts +245 -161
  268. package/src/verbs/describe.ts +14 -15
  269. package/src/verbs/explain.ts +15 -13
  270. package/src/verbs/print-config.ts +2 -1
  271. package/src/verbs/print-projects.ts +6 -4
  272. package/src/verbs/print-retained.ts +4 -2
  273. package/src/verbs/print-roots.ts +4 -2
  274. package/src/verbs/verb.ts +2 -8
  275. package/src/verbs/version.ts +15 -3
  276. package/src/workflow-steps.ts +149 -34
  277. package/dist/src/discover.js +0 -347
  278. package/dist/src/glob.js +0 -65
  279. package/dist/src/pnpm-workspace.js +0 -120
  280. package/dist/src/setup-failure.js +0 -23
  281. package/dist/src/test-joins.js +0 -101
  282. package/dist/src/version.js +0 -7
  283. package/src/discover.ts +0 -510
  284. package/src/glob.ts +0 -67
  285. package/src/pnpm-workspace.ts +0 -135
  286. package/src/setup-failure.ts +0 -39
  287. package/src/test-joins.ts +0 -120
  288. package/src/version.ts +0 -7
package/src/discover.ts DELETED
@@ -1,510 +0,0 @@
1
- import { DiagnosticCategory } from "@typescript/native/sync";
2
- import type { Diagnostic } from "@typescript/native/sync";
3
- import type { BuildConfiguration, ProjectConfiguration } from "./config.ts";
4
- import type { Host } from "./host.ts";
5
- import { dirnamePath, joinPath, relativePath, resolvePath } from "./paths.ts";
6
- import type { Scope } from "./scope.ts";
7
- import { SetupError } from "./setup-failure.ts";
8
- import type { Engine, ProjectDiagnostics } from "./session.ts";
9
-
10
- /** Directory names discovery does not descend into. */
11
- export const IGNORED_DIRECTORIES: ReadonlySet<string> = new Set(["node_modules", ".git"]);
12
-
13
- /** A compiler configuration file discovery recognises under a root. */
14
- const CONFIG_FILE = /^tsconfig.*\.json$/u;
15
-
16
- /**
17
- * A run that cannot read what it was asked to analyze. It ends the run with the
18
- * failure code and no finding list: a configuration file the compiler cannot read,
19
- * or a project carrying an error, leaves the analysis without the type information
20
- * every answer rests on, and a partial answer is never printed as a complete one.
21
- */
22
- export class DiscoveryError extends Error {
23
- /** The diagnostics the compiler reported, in the order it reported them. */
24
- readonly diagnostics: readonly LocatedDiagnostic[];
25
-
26
- constructor(message: string, diagnostics: readonly LocatedDiagnostic[]) {
27
- super(message);
28
- this.name = "DiscoveryError";
29
- this.diagnostics = diagnostics;
30
- }
31
- }
32
-
33
- /** The category an error diagnostic carries, which the protocol sends as a number. */
34
- const ERROR_CATEGORY: number = DiagnosticCategory.Error;
35
-
36
- /** Whether one diagnostic is an error, which is what fails a run closed. */
37
- function isError(diagnostic: Diagnostic): boolean {
38
- return diagnostic.category === ERROR_CATEGORY;
39
- }
40
-
41
- /** One diagnostic, with the line and column its offset falls on where it names a file. */
42
- export interface LocatedDiagnostic {
43
- readonly diagnostic: Diagnostic;
44
- /** Where the diagnostic starts, counted from one; absent where it names no position. */
45
- readonly at?: { readonly line: number; readonly column: number } | undefined;
46
- }
47
-
48
- /**
49
- * One diagnostic as a line naming its file, its line and column, its code and its
50
- * message: `path:line:column: TScode: message`, the position left out where the
51
- * diagnostic names none and the file where it names none. `display` spells the
52
- * file's path; it answers the path itself where it is not given.
53
- */
54
- export function renderDiagnostic(
55
- located: LocatedDiagnostic,
56
- display: (path: string) => string = (path) => path,
57
- ): string {
58
- const { diagnostic, at } = located;
59
- const message = `TS${String(diagnostic.code)}: ${diagnostic.text}`;
60
- if (diagnostic.fileName === undefined) {
61
- return message;
62
- }
63
- const where = display(diagnostic.fileName);
64
- return at === undefined
65
- ? `${where}: ${message}`
66
- : `${where}:${String(at.line)}:${String(at.column)}: ${message}`;
67
- }
68
-
69
- /** Each diagnostic with the line and column its offset falls on. */
70
- function locatedIn(
71
- diagnostics: readonly Diagnostic[],
72
- locate: (fileName: string, offset: number) => { line: number; column: number } | undefined,
73
- ): readonly LocatedDiagnostic[] {
74
- return diagnostics.map((diagnostic) => ({
75
- diagnostic,
76
- at: diagnostic.fileName === undefined ? undefined : locate(diagnostic.fileName, diagnostic.pos),
77
- }));
78
- }
79
-
80
- /**
81
- * Every error a project's three diagnostic sets carry, in the order the compiler
82
- * reported them: a configuration whose options do not parse, a file whose syntax
83
- * does not, and a program that does not type-check. A resolved configuration
84
- * carries no diagnostics of its own, so a configuration written with an unreadable
85
- * option resolves and is refused here, once its project is open.
86
- */
87
- export function diagnosticErrors(sets: {
88
- readonly syntactic: readonly Diagnostic[];
89
- readonly semantic: readonly Diagnostic[];
90
- readonly configParsing: readonly Diagnostic[];
91
- }): readonly Diagnostic[] {
92
- return [...sets.configParsing, ...sets.syntactic, ...sets.semantic].filter(isError);
93
- }
94
-
95
- /** Why one open project cannot be analyzed, split by whether it loaded at all. */
96
- interface ProjectErrors {
97
- /**
98
- * The errors in the configuration itself, and the errors the compiler places in no file
99
- * that leave its checker without a type it needs: no input matched, an option that
100
- * does not parse, a missing global type. A project carrying one did not load, whatever
101
- * its files say.
102
- */
103
- readonly load: readonly LocatedDiagnostic[];
104
- /** The errors in the files of a project that loaded: their syntax and their types. */
105
- readonly check: readonly LocatedDiagnostic[];
106
- /**
107
- * The libraries the configuration names that the compiler cannot find, which leave it
108
- * loaded: a use of a name only such a library declares is an error in its file.
109
- */
110
- readonly unfound: readonly LocatedDiagnostic[];
111
- }
112
-
113
- /**
114
- * The codes of a type library and a lib the configuration names that the compiler
115
- * cannot find, which it reports while it gathers the program's files:
116
- * https://github.com/microsoft/typescript-go/blob/89d5d5b2849a0db0957065889ca58536fa6d2e4a/internal/compiler/processingDiagnostic.go
117
- */
118
- const UNFOUND_LIBRARY: ReadonlySet<number> = new Set([2688, 2726, 2727]);
119
-
120
- /** The errors one open project carries, each located in the file it names. */
121
- export function projectErrors(sets: ProjectDiagnostics): ProjectErrors {
122
- // The compiler numbers its semantic messages from 2000 and its option messages from
123
- // 5000. A file-less option error, a removed option or an output layout, leaves the
124
- // program whole, and the compiler checks it all the same:
125
- // https://github.com/microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-message-codes
126
- const semantic = sets.unplaced.filter(
127
- (diagnostic) => isError(diagnostic) && diagnostic.code >= 2000 && diagnostic.code < 3000,
128
- );
129
- const unfound = semantic.filter(({ code }) => UNFOUND_LIBRARY.has(code));
130
- const load = [
131
- ...sets.configParsing.filter(isError),
132
- ...semantic.filter(({ code }) => !UNFOUND_LIBRARY.has(code)),
133
- ];
134
- return {
135
- load: locatedIn(load, sets.locate),
136
- check: load.length > 0 ? [] : locatedIn(diagnosticErrors(sets), sets.locate),
137
- unfound: load.length > 0 ? [] : locatedIn(unfound, sets.locate),
138
- };
139
- }
140
-
141
- /** One project a run analyzes. */
142
- interface DiscoveredProject {
143
- /**
144
- * The name a run gives the project: the identifier the build matrix declares for
145
- * it, or, for a project discovery derived, its configuration file's path below the
146
- * target root. A derived project whose file is not below the target root is named
147
- * by the file's absolute path, the one spelling it has.
148
- */
149
- readonly id: string;
150
- /** The compiler configuration file the project is opened from, absolute. */
151
- readonly configFile: string;
152
- }
153
-
154
- /**
155
- * One project discovery derived and the run could not build, with the first line of
156
- * the error that dropped it.
157
- */
158
- export interface NotBuilt {
159
- /** The name the project would have carried, as {@link DiscoveredProject.id} spells it. */
160
- readonly id: string;
161
- /** The compiler configuration file, absolute. */
162
- readonly configFile: string;
163
- /**
164
- * The error's first line, every path below the target root spelled relative to it, so
165
- * a report naming it carries no path of the machine it ran on.
166
- */
167
- readonly error: string;
168
- }
169
-
170
- /**
171
- * The first line of one error about the target, every mention of the target root
172
- * spelled relative to it: a path below the root loses the root and its separator, and
173
- * the root itself is `.`.
174
- */
175
- export function targetRelative(text: string, targetRoot: string): string {
176
- const root = targetRoot.endsWith("/") ? targetRoot.slice(0, -1) : targetRoot;
177
- const [first = ""] = text.split(/\r?\n/u);
178
- const spelled = first.split(`${root}/`).join("").split(root).join(".").trim();
179
- return spelled === "" ? "the configuration could not be built" : spelled;
180
- }
181
-
182
- /**
183
- * Whether one configuration is the analyzer's own guess: discovery derived it and the
184
- * scope did not name it. A guess that does not load is dropped; any other ends the run.
185
- */
186
- export function isGuess(discovery: Discovery, configFile: string): boolean {
187
- return discovery.derived && !discovery.fromScope.includes(configFile);
188
- }
189
-
190
- /** Every project discovery found, and where each came from. */
191
- interface Discovery {
192
- /** The projects, in discovery order, each once. */
193
- readonly projects: readonly DiscoveredProject[];
194
- /**
195
- * Whether discovery derived the projects rather than reading them from a declared
196
- * matrix. A derived project that fails to load is dropped and named in
197
- * {@link Discovery.notBuilt}; a declared one ends the run.
198
- */
199
- readonly derived: boolean;
200
- /** The derived configurations the compiler could not read, in discovery order. */
201
- readonly notBuilt: readonly NotBuilt[];
202
- /** The configuration file of each project, in the same order. */
203
- readonly configFiles: readonly string[];
204
- /**
205
- * The files the scope named, which are the ones a derivation reads first. A
206
- * declared matrix reads none of them.
207
- */
208
- readonly fromScope: readonly string[];
209
- }
210
-
211
- /**
212
- * The configuration files below `root`, in ascending path order, skipping an
213
- * ignored directory. A directory that cannot be read is skipped: a tree the
214
- * analysis may not enter names no project.
215
- */
216
- function configFilesUnder(host: Host, root: string): string[] {
217
- const found: string[] = [];
218
- const pending = [root];
219
- while (pending.length > 0) {
220
- const dir = pending.pop();
221
- if (dir === undefined) {
222
- break;
223
- }
224
- let entries: readonly { readonly name: string; readonly directory: boolean }[];
225
- try {
226
- entries = host.readDirectory(dir);
227
- } catch {
228
- continue;
229
- }
230
- for (const entry of [...entries].sort((a, b) => (a.name < b.name ? -1 : 1))) {
231
- const path = joinPath(dir, entry.name);
232
- if (entry.directory) {
233
- if (!IGNORED_DIRECTORIES.has(entry.name)) {
234
- pending.push(path);
235
- }
236
- continue;
237
- }
238
- if (CONFIG_FILE.test(entry.name)) {
239
- found.push(path);
240
- }
241
- }
242
- }
243
- return found.sort();
244
- }
245
-
246
- /**
247
- * The configuration file the scope names for the target directly, where its path
248
- * names one rather than a directory. A target naming a directory is reached by the
249
- * walk over that directory instead. A consumer's projects are a consumer's, never the
250
- * target's, so no consumer path is read here.
251
- */
252
- function scopeConfigFiles(host: Host, scope: Scope): string[] {
253
- return [scope.target.path]
254
- .filter((path) => path.endsWith(".json"))
255
- .map((path) => resolvePath(host.workingDirectory(), path));
256
- }
257
-
258
- /**
259
- * Every configuration file reached from `pending`, in the order discovery reads them:
260
- * each once, each followed by the configurations it references that `follows` admits,
261
- * transitively. A configuration the compiler cannot read ends the run naming it, unless
262
- * `unreadable` is given, which is then told the configuration and why, and the walk
263
- * goes on without it.
264
- */
265
- function derivedFrom(
266
- engine: Engine,
267
- host: Host,
268
- pending: string[],
269
- follows: (reference: string) => boolean,
270
- unreadable?: (configFile: string, reason: string) => void,
271
- ): string[] {
272
- const seen = new Set<string>();
273
- const found: string[] = [];
274
- while (pending.length > 0) {
275
- const configFile = pending.shift();
276
- if (configFile === undefined) {
277
- break;
278
- }
279
- const path = resolvePath(host.workingDirectory(), configFile);
280
- if (seen.has(path)) {
281
- continue;
282
- }
283
- seen.add(path);
284
- const read = readConfiguration(engine, path);
285
- if ("reason" in read) {
286
- if (unreadable === undefined) {
287
- throw new DiscoveryError(
288
- `${path} cannot be read as a compiler configuration: ${read.reason}`,
289
- [],
290
- );
291
- }
292
- unreadable(path, read.reason);
293
- continue;
294
- }
295
- found.push(path);
296
- pending.push(...read.references.filter(follows));
297
- }
298
- return found;
299
- }
300
-
301
- /**
302
- * The compiler configurations one consumer is loaded through: every one under its
303
- * root that is not inside an ignored directory, and the configurations each of those
304
- * references, transitively, in that order. A root that is absent, that is no
305
- * directory, or that holds no configuration ends the run naming it, because a
306
- * finding computed without a declared consumer would claim a reference set the run
307
- * never read.
308
- */
309
- export function consumerProjects(engine: Engine, host: Host, root: string): readonly string[] {
310
- const kind = host.kindOf(root);
311
- if (kind === "absent") {
312
- throw new SetupError([
313
- {
314
- setupClass: "missing-consumer",
315
- detail: `the scope declares the consumer ${root}, and nothing is at that path: check the consumer out at ${root} and install its dependencies`,
316
- },
317
- ]);
318
- }
319
- if (kind !== "directory") {
320
- throw new DiscoveryError(`the consumer ${root} is not a directory`, []);
321
- }
322
- const found = derivedFrom(engine, host, configFilesUnder(host, root), () => true);
323
- if (found.length === 0) {
324
- throw new DiscoveryError(
325
- `the consumer ${root} holds no compiler configuration, so none of its references can be read`,
326
- [],
327
- );
328
- }
329
- return found;
330
- }
331
-
332
- /**
333
- * The name a derived project carries: its configuration file's path below the target
334
- * root, or the absolute path of a file outside it.
335
- */
336
- function derivedId(targetRoot: string, configFile: string): string {
337
- return relativePath(targetRoot, configFile) ?? configFile;
338
- }
339
-
340
- /**
341
- * The configuration files one configuration's `references` name, or why the compiler
342
- * cannot read the configuration.
343
- */
344
- function readConfiguration(
345
- engine: Engine,
346
- configFile: string,
347
- ): { readonly references: readonly string[] } | { readonly reason: string } {
348
- try {
349
- const parsed = engine.parseConfigFile(configFile);
350
- // The parse answers a directory reference as the directory; the compiler reads a
351
- // path not ending `.json` as its `tsconfig.json`:
352
- // https://github.com/microsoft/typescript-go/blob/89d5d5b2849a0db0957065889ca58536fa6d2e4a/internal/core/projectreference.go#L18
353
- return {
354
- references: (parsed.projectReferences ?? []).map(({ path }) =>
355
- path.endsWith(".json") ? path : joinPath(path, "tsconfig.json"),
356
- ),
357
- };
358
- } catch (error: unknown) {
359
- return { reason: error instanceof Error ? error.message : String(error) };
360
- }
361
- }
362
-
363
- /**
364
- * The references of one compiler configuration file, or ends the run naming it: a
365
- * project opened from a configuration the compiler cannot read would be analyzed with
366
- * no type information.
367
- */
368
- function parseOrRefuse(engine: Engine, configFile: string, named: string): readonly string[] {
369
- const read = readConfiguration(engine, configFile);
370
- if ("reason" in read) {
371
- throw new DiscoveryError(
372
- `${named} cannot be read as a compiler configuration: ${read.reason}`,
373
- [],
374
- );
375
- }
376
- return read.references;
377
- }
378
-
379
- /**
380
- * The projects a build matrix declares, in its order, each entry a file below the target
381
- * root: an entry naming an absent file, a directory or a file the compiler cannot read
382
- * ends the run naming it, and one naming an earlier entry's file adds nothing. A
383
- * reference below the root the matrix does not name ends the run naming both, because the
384
- * compiler builds a referenced project's sources into the referencing program without
385
- * reporting their diagnostics. A reference outside the root is an outside project.
386
- */
387
- function declaredProjects(
388
- engine: Engine,
389
- host: Host,
390
- targetRoot: string,
391
- entries: readonly ProjectConfiguration[],
392
- ): Discovery {
393
- const seen = new Set<string>();
394
- const projects: DiscoveredProject[] = [];
395
- const references = new Map<string, readonly string[]>();
396
- for (const entry of entries) {
397
- const configFile = joinPath(targetRoot, entry.project);
398
- const named = `the project ${JSON.stringify(entry.id)} (${configFile})`;
399
- const kind = host.kindOf(configFile);
400
- if (kind !== "file") {
401
- throw new DiscoveryError(
402
- kind === "absent"
403
- ? `${named} does not exist`
404
- : `${named} is a directory, and a project names its compiler configuration file`,
405
- [],
406
- );
407
- }
408
- if (seen.has(configFile)) {
409
- continue;
410
- }
411
- seen.add(configFile);
412
- references.set(configFile, parseOrRefuse(engine, configFile, named));
413
- projects.push({ id: entry.id, configFile });
414
- }
415
- for (const project of projects) {
416
- const unnamed = references
417
- .get(project.configFile)
418
- ?.find((path) => !seen.has(path) && relativePath(targetRoot, path) !== undefined);
419
- if (unnamed !== undefined) {
420
- throw new DiscoveryError(
421
- `the project ${JSON.stringify(project.id)} (${project.configFile}) references ` +
422
- `${unnamed}, which the build matrix does not name. A referenced project is built ` +
423
- "into the program that references it, so the matrix names it too",
424
- [],
425
- );
426
- }
427
- }
428
- return {
429
- projects,
430
- derived: false,
431
- notBuilt: [],
432
- configFiles: projects.map((project) => project.configFile),
433
- fromScope: [],
434
- };
435
- }
436
-
437
- /**
438
- * The projects a run derives where the matrix declares none, in discovery order: the
439
- * paths the scope names, every compiler configuration under the target root outside an
440
- * ignored directory, then each configuration below the root those reference,
441
- * transitively, each once. A reference outside the root is an outside project, whose
442
- * sources the compiler builds into the referencing program. A configuration the scope
443
- * names ends the run where it cannot be read; one the walk found is dropped and named.
444
- */
445
- function derivedProjects(engine: Engine, host: Host, scope: Scope): Discovery {
446
- const targetRoot = scope.target.path;
447
- const fromScope = scopeConfigFiles(host, scope);
448
- const notBuilt: NotBuilt[] = [];
449
- const rootDir = resolvePath(
450
- host.workingDirectory(),
451
- fromScope.length > 0 ? dirnamePath(targetRoot) : targetRoot,
452
- );
453
- const configFiles = derivedFrom(
454
- engine,
455
- host,
456
- [...fromScope, ...configFilesUnder(host, targetRoot)],
457
- (reference) => relativePath(rootDir, reference) !== undefined,
458
- (configFile, reason) => {
459
- if (fromScope.includes(configFile)) {
460
- throw new DiscoveryError(
461
- `${configFile} cannot be read as a compiler configuration: ${reason}`,
462
- [],
463
- );
464
- }
465
- notBuilt.push({
466
- id: derivedId(targetRoot, configFile),
467
- configFile,
468
- error: targetRelative(reason, resolvePath(host.workingDirectory(), targetRoot)),
469
- });
470
- },
471
- );
472
- const projects = configFiles.map((configFile) => ({
473
- id: derivedId(targetRoot, configFile),
474
- configFile,
475
- }));
476
- return { projects, derived: true, notBuilt, configFiles, fromScope };
477
- }
478
-
479
- /**
480
- * Every project one run analyzes.
481
- *
482
- * The project entries of the build matrix, where it holds any, are the projects:
483
- * exactly those, in the order the matrix lists them, each named by its declared
484
- * identifier, as {@link declaredProjects} reads them. A matrix holding no project
485
- * entry, the empty one included, leaves discovery to derive the projects from the
486
- * scope and the target tree. A platform entry names a configuration of another
487
- * language and plays no part here.
488
- *
489
- * A configuration file the compiler cannot read is never analyzed. One the matrix or
490
- * the scope names ends the run with the failure code; a guess is dropped and named in
491
- * {@link Discovery.notBuilt}. What a configuration's own contents say is read once its
492
- * project is open, by {@link diagnosticErrors}, because a resolution carries none.
493
- *
494
- * Nothing reads a build output: a project is the files its configuration names, so a
495
- * package whose sources ship as TypeScript is analyzed as it stands.
496
- */
497
- export function discoverProjects(
498
- engine: Engine,
499
- host: Host,
500
- scope: Scope,
501
- configurations: readonly BuildConfiguration[] = [],
502
- ): Discovery {
503
- const declared = configurations.filter(
504
- (entry): entry is ProjectConfiguration => entry.shape === "project",
505
- );
506
- if (declared.length > 0) {
507
- return declaredProjects(engine, host, scope.target.path, declared);
508
- }
509
- return derivedProjects(engine, host, scope);
510
- }
package/src/glob.ts DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * Glob patterns over the paths of the target's own files, as the configuration
3
- * writes them. Both `ts.test_files` and `ts.entry_files` name files this way, and
4
- * one grammar answers for both.
5
- *
6
- * A configured root is not written in this grammar. It names a symbol reference
7
- * rather than a path, `*` there spans the solidus and a brace list means nothing,
8
- * so that rule is written where it is read.
9
- */
10
-
11
- /**
12
- * One literal run of a pattern, with every character the expression syntax claims
13
- * escaped.
14
- *
15
- * The set is the syntax characters and the solidus, and it is closed: an escape of any
16
- * other character is refused outright by the expression syntax under the unicode flag,
17
- * so escaping a hyphen, which needs none outside a character class, would refuse every
18
- * pattern that names a hyphenated path.
19
- */
20
- function quoted(text: string): string {
21
- return text.replaceAll(/[.*+?^${}()|[\]\\/]/gu, (character) => `\\${character}`);
22
- }
23
-
24
- /**
25
- * The expression one glob pattern denotes. `**` spans path separators while `*` and `?`
26
- * do not, a brace list is an alternation of its members, and every other character
27
- * stands for itself.
28
- */
29
- export function globExpression(pattern: string): RegExp {
30
- let source = "^";
31
- let at = 0;
32
- while (at < pattern.length) {
33
- const rest = pattern.slice(at);
34
- if (rest.startsWith("**/")) {
35
- source += "(?:[^/]*/)*";
36
- at += 3;
37
- continue;
38
- }
39
- if (rest.startsWith("**")) {
40
- source += ".*";
41
- at += 2;
42
- continue;
43
- }
44
- const character = pattern[at] ?? "";
45
- at += 1;
46
- if (character === "*") {
47
- source += "[^/]*";
48
- continue;
49
- }
50
- if (character === "?") {
51
- source += "[^/]";
52
- continue;
53
- }
54
- if (character === "{") {
55
- const close = pattern.indexOf("}", at);
56
- if (close < 0) {
57
- source += "\\{";
58
- continue;
59
- }
60
- source += `(?:${pattern.slice(at, close).split(",").map(quoted).join("|")})`;
61
- at = close + 1;
62
- continue;
63
- }
64
- source += quoted(character);
65
- }
66
- return new RegExp(`${source}$`, "u");
67
- }