@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
@@ -0,0 +1,397 @@
1
+ import type { SourceFile } from "@typescript/native/ast";
2
+ import { conventionFailuresFor } from "../conventions.ts";
3
+ import type { Host } from "../host.ts";
4
+ import { relativePath, resolvePath } from "../paths.ts";
5
+ import { diagnosticsOf, ownedAs, type Engine, type ProjectView } from "../session.ts";
6
+ import { skipAt, type Skip } from "../type-errors.ts";
7
+ import {
8
+ classOf,
9
+ MISSING_GLOBAL_TYPE,
10
+ projectErrors,
11
+ renderDiagnostic,
12
+ type LocatedDiagnostic,
13
+ } from "./diagnostics.ts";
14
+ import { targetRelative, type LoadedConsumer, type NotBuilt, type Origin } from "./discover.ts";
15
+ import { missingModule, pathsOf, type ModuleContext } from "./expected-module.ts";
16
+ import { FailureExit, failureLine, type Failure } from "../failure.ts";
17
+ import type { ProgramPlan, RunPlan } from "./plan.ts";
18
+ import { JAVASCRIPT_FILE } from "../javascript-file.ts";
19
+ import { readSpecifiers, type UnresolvedSpecifier } from "./specifiers.ts";
20
+ import { ownErrors } from "./workspace-run.ts";
21
+
22
+ /** What keeps one configuration from being analyzed. */
23
+ type Failed =
24
+ /** Its project carries an error that leaves it unloaded. */
25
+ | { readonly kind: "load"; readonly errors: readonly [LocatedDiagnostic, ...LocatedDiagnostic[]] }
26
+ | { readonly kind: "setup"; readonly failures: readonly [Failure, ...Failure[]] }
27
+ /** The snapshot opened no project for it. */
28
+ | { readonly kind: "unopened" };
29
+
30
+ /** What a failure ends or drops, by where the configuration comes from. */
31
+ const POLICY: Readonly<Record<Origin, Readonly<Record<Failed["kind"], "drop" | "end">>>> = {
32
+ declared: { load: "end", setup: "end", unopened: "end" },
33
+ scope: { load: "end", setup: "end", unopened: "end" },
34
+ derived: { load: "drop", setup: "drop", unopened: "drop" },
35
+ consumer: { load: "end", setup: "end", unopened: "end" },
36
+ };
37
+
38
+ /** One library an analyzed configuration names that the compiler cannot find. */
39
+ export interface LibraryUnfound {
40
+ readonly configFile: string;
41
+ /** The compiler's error, rendered as a dropped configuration's is. */
42
+ readonly error: string;
43
+ }
44
+
45
+ /** One target project the run analyzes, as classification leaves it. */
46
+ interface Analyzed<Brand> {
47
+ readonly plan: ProgramPlan;
48
+ /** The project, its own files the target's. */
49
+ readonly project: ProjectView<Brand>;
50
+ /** Every type error of its own files, with the unit it skips. */
51
+ readonly skips: readonly Skip[];
52
+ /** Whether it holds one file only for the references that file makes. */
53
+ readonly referenceOnly: (file: string) => boolean;
54
+ /** The relative specifiers of its unchecked JavaScript files that resolve to no file. */
55
+ readonly unresolved: readonly UnresolvedSpecifier[];
56
+ }
57
+
58
+ /** One consumer project the run reads the references of. */
59
+ interface Consumed<Brand> {
60
+ readonly project: ProjectView<Brand>;
61
+ readonly consumer: LoadedConsumer;
62
+ }
63
+
64
+ /** Every opened project of a run that may be read, and what the run notes about the others. */
65
+ export interface Classified {
66
+ readonly analyzed: readonly Analyzed<unknown>[];
67
+ readonly consumed: readonly Consumed<unknown>[];
68
+ /** The derived configurations dropped, discovery's first, then in configuration order. */
69
+ readonly notBuilt: readonly NotBuilt[];
70
+ readonly librariesUnfound: readonly LibraryUnfound[];
71
+ /** The unresolved specifiers of every analyzed project, each once, in configuration order. */
72
+ readonly unresolvedSpecifiers: readonly UnresolvedSpecifier[];
73
+ }
74
+
75
+ /**
76
+ * The errors of one project's own files: an import of a module the project expects and
77
+ * nothing provides is a setup failure, every other error a type error skipping its unit.
78
+ * Where `plan`'s options do not check JavaScript, an unfound module of a JavaScript file is
79
+ * none of them, a file `// @ts-check` checks included: {@link readSpecifiers} reads it.
80
+ */
81
+ function readErrors<Brand>(
82
+ project: ProjectView<Brand>,
83
+ plan: ProgramPlan,
84
+ errors: readonly LocatedDiagnostic[],
85
+ context: ModuleContext,
86
+ ): { readonly missing: readonly Failure[]; readonly skips: readonly Skip[] } {
87
+ const files = new Map<string, SourceFile>(
88
+ project.ownSourceFiles().map((file) => [file.fileName, file]),
89
+ );
90
+ const missing: Failure[] = [];
91
+ const skips: Skip[] = [];
92
+ for (const { diagnostic, at } of errors) {
93
+ const file = diagnostic.fileName === undefined ? undefined : files.get(diagnostic.fileName);
94
+ const kind = classOf(diagnostic, true);
95
+ if (
96
+ file === undefined ||
97
+ kind === "ignored" ||
98
+ ((kind === "module-not-found" || kind === "side-effect-module-not-found") &&
99
+ !checksJavaScript(plan) &&
100
+ JAVASCRIPT_FILE.test(file.fileName))
101
+ ) {
102
+ continue;
103
+ }
104
+
105
+ const line = at?.line ?? 1;
106
+ const path = relativePath(context.targetRoot, file.fileName) ?? file.fileName;
107
+ const expected =
108
+ kind === "module-not-found" ? missingModule(context, file, diagnostic.pos) : undefined;
109
+ if (expected !== undefined) {
110
+ missing.push({
111
+ failureClass: "missing-module",
112
+ detail: `${path}:${String(line)}: ${path} imports ${JSON.stringify(expected.specifier)}, ${expected.reason}`,
113
+ });
114
+ continue;
115
+ }
116
+ const skip = skipAt(file, diagnostic.pos, line, diagnostic.text, context.targetRoot);
117
+ if (skip !== undefined) {
118
+ skips.push(skip);
119
+ }
120
+ }
121
+ return { missing, skips };
122
+ }
123
+
124
+ function checksJavaScript(plan: ProgramPlan): boolean {
125
+ return plan.options.checkJs === true;
126
+ }
127
+
128
+ function nonEmpty<T>(items: readonly T[]): readonly [T, ...T[]] | undefined {
129
+ const [first, ...rest] = items;
130
+ return first === undefined ? undefined : [first, ...rest];
131
+ }
132
+
133
+ /** One target project read for what keeps it from being analyzed, or the skips it is analyzed with. */
134
+ function classifyTarget<Brand>(
135
+ engine: Engine,
136
+ host: Host,
137
+ run: RunPlan,
138
+ plan: ProgramPlan,
139
+ view: ProjectView<Brand>,
140
+ unfound: LibraryUnfound[],
141
+ ): Failed | Analyzed<Brand> {
142
+ const { workspace, root } = run;
143
+ const unbuildable = workspace?.unbuildable(plan.configFile);
144
+ if (unbuildable !== undefined) {
145
+ return {
146
+ kind: "setup",
147
+ failures: [{ failureClass: "workspace-member-without-source", detail: unbuildable }],
148
+ };
149
+ }
150
+ const referenceOnly =
151
+ workspace === undefined
152
+ ? () => false
153
+ : workspace.referenceOnly(plan.configFile, view.rootFiles);
154
+ // A file outside the target root that a program reaches is no file of the target's, so no
155
+ // position below the root names it.
156
+ const project = ownedAs(
157
+ view,
158
+ (file, external) =>
159
+ relativePath(root, file) !== undefined &&
160
+ (workspace === undefined ? !external : workspace.ownFile(file, external)),
161
+ );
162
+ const raw = projectErrors(diagnosticsOf(project));
163
+ const load = nonEmpty(raw.load);
164
+ if (load !== undefined) {
165
+ return { kind: "load", errors: load };
166
+ }
167
+ const reading = readErrors(project, plan, ownErrors(raw.check, referenceOnly), {
168
+ host,
169
+ targetRoot: root,
170
+ paths: pathsOf(plan.configFile, plan.parsed.options),
171
+ member: (manifest) => workspace?.workspace.memberOf(manifest) !== undefined,
172
+ });
173
+ const specifiers = readSpecifiers(engine, host, project, {
174
+ checked: checksJavaScript(plan),
175
+ root,
176
+ outputs: run.outputs,
177
+ });
178
+ const failures =
179
+ nonEmpty(reading.missing) ??
180
+ nonEmpty(specifiers.uninstalled === undefined ? [] : [specifiers.uninstalled]) ??
181
+ nonEmpty(
182
+ conventionFailuresFor(
183
+ run.conventions,
184
+ plan.configFile,
185
+ project.ownSourceFiles().map((file) => file.fileName),
186
+ ),
187
+ );
188
+ if (failures !== undefined) {
189
+ return { kind: "setup", failures };
190
+ }
191
+ const display = (path: string): string => relativePath(root, path) ?? path;
192
+ unfound.push(
193
+ ...raw.unfound.map((one) => ({
194
+ configFile: plan.configFile,
195
+ error: renderDiagnostic(one, display),
196
+ })),
197
+ );
198
+ const missingGlobal = raw.unfound.find(
199
+ ({ diagnostic }) => diagnostic.code === MISSING_GLOBAL_TYPE,
200
+ );
201
+ // The checker types every use of a missing global against nothing and places no error in
202
+ // a file, so every file of the project is skipped whole.
203
+ const skips =
204
+ missingGlobal === undefined
205
+ ? reading.skips
206
+ : [
207
+ ...reading.skips,
208
+ ...project.ownSourceFiles().map((file) => ({
209
+ record: {
210
+ path: display(file.fileName),
211
+ line: 1,
212
+ message: missingGlobal.diagnostic.text,
213
+ },
214
+ file,
215
+ unit: file,
216
+ })),
217
+ ];
218
+ return { plan, project, skips, referenceOnly, unresolved: specifiers.unresolved };
219
+ }
220
+
221
+ /**
222
+ * One consumer project read for what keeps its references from being read: a missing module, or
223
+ * JavaScript whose imported dependencies are none of them installed, as a target's are. A workspace
224
+ * declaration that cannot be read fails it where an import asks whether a package is a member.
225
+ */
226
+ function classifyConsumer<Brand>(
227
+ engine: Engine,
228
+ host: Host,
229
+ run: RunPlan,
230
+ plan: ProgramPlan,
231
+ consumer: LoadedConsumer,
232
+ project: ProjectView<Brand>,
233
+ ): Failed | Consumed<Brand> {
234
+ const place = run.consumerWorkspaces.get(consumer.path);
235
+ const consumerRoot = resolvePath(host.workingDirectory(), consumer.path);
236
+ const raw = projectErrors(diagnosticsOf(project));
237
+ const load = nonEmpty(raw.load);
238
+ if (load !== undefined) {
239
+ return { kind: "load", errors: load };
240
+ }
241
+ let faulted: string | undefined;
242
+ const reading = readErrors(project, plan, raw.check, {
243
+ host,
244
+ targetRoot: consumerRoot,
245
+ paths: pathsOf(plan.configFile, plan.parsed.options),
246
+ member: (manifest) => {
247
+ if (place !== undefined && "fault" in place) {
248
+ faulted = place.fault;
249
+ return false;
250
+ }
251
+ return place?.workspace?.memberOf(manifest) !== undefined;
252
+ },
253
+ });
254
+ const { uninstalled } = readSpecifiers(engine, host, project, {
255
+ checked: checksJavaScript(plan),
256
+ root: consumerRoot,
257
+ outputs: run.outputs,
258
+ });
259
+ const details =
260
+ faulted === undefined
261
+ ? [...reading.missing, ...(uninstalled === undefined ? [] : [uninstalled])].map(
262
+ (one) =>
263
+ `the consumer ${consumer.path} does not build, its dependencies not installed: ${one.detail}`,
264
+ )
265
+ : [
266
+ `the consumer ${consumer.path} imports a dependency a package below it declares, and its workspace declaration cannot be read to tell whether that package is a member: ${faulted}`,
267
+ ];
268
+ const failures = nonEmpty(
269
+ details.map((detail) => ({ failureClass: "missing-consumer" as const, detail })),
270
+ );
271
+ return failures === undefined ? { project, consumer } : { kind: "setup", failures };
272
+ }
273
+
274
+ /** The setup failure one failed configuration ends the run with, its located errors printed first. */
275
+ function ending(plan: ProgramPlan, failed: Failed, root: string): readonly Failure[] {
276
+ if (failed.kind === "setup") {
277
+ return failed.failures;
278
+ }
279
+ const what =
280
+ failed.kind === "load"
281
+ ? `the configuration ${relativePath(root, plan.configFile) ?? plan.configFile} does not load, its errors printed above`
282
+ : `the compiler opened no project for ${plan.configFile}`;
283
+ return plan.consumer === undefined
284
+ ? [
285
+ {
286
+ failureClass: "no-program",
287
+ detail: `${what}: correct the configuration, or name the configurations to analyze`,
288
+ },
289
+ ]
290
+ : [
291
+ {
292
+ failureClass: "missing-consumer",
293
+ detail: `${what}, for the consumer ${plan.consumer.path}: check the consumer out at ${plan.consumer.path} and install its dependencies`,
294
+ },
295
+ ];
296
+ }
297
+
298
+ /** The first line of the error that drops one derived configuration. */
299
+ function droppedBy(failed: Failed, root: string): string {
300
+ return failed.kind === "load"
301
+ ? targetRelative(
302
+ renderDiagnostic(failed.errors[0], (path) => relativePath(root, path) ?? path),
303
+ root,
304
+ )
305
+ : failed.kind === "setup"
306
+ ? targetRelative(failureLine(failed.failures[0]), root)
307
+ : "the compiler opened no project for the configuration";
308
+ }
309
+
310
+ /**
311
+ * Every opened project of the run classified as analyzed, dropped or failing by the policy
312
+ * table, before any stage reads one. A failure that ends the run is one {@link FailureExit}, by
313
+ * this precedence: a configuration the snapshot opened nothing for, then the setup failures,
314
+ * then the configurations that did not load with their errors, then, where every derived
315
+ * configuration was dropped, their setup failures or the first reason.
316
+ */
317
+ export function classify(
318
+ engine: Engine,
319
+ host: Host,
320
+ run: RunPlan,
321
+ views: ReadonlyMap<string, ProjectView<unknown>>,
322
+ ): Classified {
323
+ const { root } = run;
324
+ const notBuilt: NotBuilt[] = [...run.discovery.notBuilt];
325
+ const librariesUnfound: LibraryUnfound[] = [];
326
+ const analyzed: Analyzed<unknown>[] = [];
327
+ const consumed: Consumed<unknown>[] = [];
328
+ const ended = new Map<Failed["kind"], { plan: ProgramPlan; failed: Failed }[]>();
329
+ const dropped: Failed[] = [];
330
+ const unopened = run.plans.filter((plan) => !views.has(plan.configFile));
331
+ const outcomes = [
332
+ ...run.plans.flatMap((plan) => {
333
+ const view = views.get(plan.configFile);
334
+ return view === undefined
335
+ ? []
336
+ : [
337
+ {
338
+ plan,
339
+ outcome:
340
+ plan.consumer === undefined
341
+ ? classifyTarget(engine, host, run, plan, view, librariesUnfound)
342
+ : classifyConsumer(engine, host, run, plan, plan.consumer, view),
343
+ },
344
+ ];
345
+ }),
346
+ ...unopened.map((plan) => ({ plan, outcome: { kind: "unopened" } as const })),
347
+ ];
348
+ for (const { plan, outcome } of outcomes) {
349
+ if (!("kind" in outcome)) {
350
+ if ("consumer" in outcome) {
351
+ consumed.push(outcome);
352
+ } else {
353
+ analyzed.push(outcome);
354
+ }
355
+ } else if (POLICY[plan.origin][outcome.kind] === "end") {
356
+ ended.set(outcome.kind, [...(ended.get(outcome.kind) ?? []), { plan, failed: outcome }]);
357
+ } else {
358
+ dropped.push(outcome);
359
+ notBuilt.push({ id: plan.id, configFile: plan.configFile, error: droppedBy(outcome, root) });
360
+ }
361
+ }
362
+ for (const kind of ["unopened", "setup", "load"] as const) {
363
+ const all = ended.get(kind) ?? [];
364
+ const failures = nonEmpty(all.flatMap(({ plan, failed }) => ending(plan, failed, root)));
365
+ if (failures !== undefined) {
366
+ throw new FailureExit(
367
+ kind === "unopened" ? [failures[0]] : failures,
368
+ all.flatMap(({ failed }) => (failed.kind === "load" ? failed.errors : [])),
369
+ );
370
+ }
371
+ }
372
+ const setupDropped = nonEmpty(
373
+ dropped.flatMap((one) => (one.kind === "setup" ? one.failures : [])),
374
+ );
375
+ const [first] = notBuilt;
376
+ if (analyzed.length === 0 && first !== undefined) {
377
+ throw new FailureExit(
378
+ setupDropped ?? [
379
+ {
380
+ failureClass: "no-program",
381
+ detail: `no configuration discovery derived could be built; ${first.id}: ${first.error}`,
382
+ },
383
+ ],
384
+ );
385
+ }
386
+ const unresolvedSpecifiers = [
387
+ ...new Map(
388
+ analyzed
389
+ .flatMap((one) => one.unresolved)
390
+ .map((one) => {
391
+ const { path, line, column } = one.position;
392
+ return [JSON.stringify([path, line, column, one.specifier]), one] as const;
393
+ }),
394
+ ).values(),
395
+ ];
396
+ return { analyzed, consumed, notBuilt, librariesUnfound, unresolvedSpecifiers };
397
+ }
@@ -0,0 +1,144 @@
1
+ import { DiagnosticCategory } from "@typescript/native/sync";
2
+ import type { Diagnostic } from "@typescript/native/sync";
3
+ import type { ProjectDiagnostics } from "../session.ts";
4
+
5
+ /** What one error diagnostic of an opened project does to the run. */
6
+ type DiagnosticClass =
7
+ /** The project did not load, whatever its files say. */
8
+ | "load"
9
+ /** A library the configuration names that the compiler cannot find; the project loads. */
10
+ | "unfound-library"
11
+ /** An import of a module the compiler cannot find, a setup failure where the project expects it. */
12
+ | "module-not-found"
13
+ /** A side-effect import of a module the compiler cannot find, a type error in a TypeScript file. */
14
+ | "side-effect-module-not-found"
15
+ /** A type error: the unit holding it is skipped. */
16
+ | "type-error"
17
+ /** No error of the program's: the compiler checks the whole program all the same. */
18
+ | "ignored";
19
+
20
+ /** One row of the diagnostic table: the codes it covers, for errors placed in a file or in none. */
21
+ interface DiagnosticRow {
22
+ readonly placed: boolean;
23
+ readonly codes: ReadonlySet<number> | { readonly from: number; readonly below: number };
24
+ readonly class: DiagnosticClass;
25
+ }
26
+
27
+ /** The code of a global type the checker finds in no library the program holds. */
28
+ export const MISSING_GLOBAL_TYPE = 2318;
29
+
30
+ /**
31
+ * What each error diagnostic does, first matching row first. In no file: an unfound type library
32
+ * or lib (https://github.com/microsoft/typescript-go/blob/89d5d5b2849a0db0957065889ca58536fa6d2e4a/internal/compiler/processingDiagnostic.go),
33
+ * then the semantic band from 2000; the option band from 5000 leaves the program whole
34
+ * (https://github.com/microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-message-codes).
35
+ * In a file: an unfound module, and where the configuration places the file (5055, 5056, 6059,
36
+ * 6307), which changes no type a statement carries.
37
+ */
38
+ const DIAGNOSTIC_TABLE: readonly DiagnosticRow[] = [
39
+ {
40
+ placed: false,
41
+ codes: new Set([MISSING_GLOBAL_TYPE, 2688, 2726, 2727]),
42
+ class: "unfound-library",
43
+ },
44
+ { placed: false, codes: { from: 2000, below: 3000 }, class: "load" },
45
+ { placed: true, codes: new Set([2307, 2792]), class: "module-not-found" },
46
+ { placed: true, codes: new Set([2882]), class: "side-effect-module-not-found" },
47
+ { placed: true, codes: new Set([5055, 5056, 6059, 6307]), class: "ignored" },
48
+ ];
49
+
50
+ /** The category an error diagnostic carries, which the protocol sends as a number. */
51
+ const ERROR_CATEGORY: number = DiagnosticCategory.Error;
52
+
53
+ function isError(diagnostic: Diagnostic): boolean {
54
+ return diagnostic.category === ERROR_CATEGORY;
55
+ }
56
+
57
+ /**
58
+ * What one diagnostic does, placed in one of the project's own files or in none. A diagnostic
59
+ * the compiler marks as reporting unnecessary code in a file is no error of the program's.
60
+ */
61
+ export function classOf(diagnostic: Diagnostic, placed: boolean): DiagnosticClass {
62
+ if (!isError(diagnostic) || (placed && diagnostic.reportsUnnecessary === true)) {
63
+ return "ignored";
64
+ }
65
+ const row = DIAGNOSTIC_TABLE.find(
66
+ ({ placed: where, codes }) =>
67
+ where === placed &&
68
+ ("has" in codes
69
+ ? codes.has(diagnostic.code)
70
+ : diagnostic.code >= codes.from && diagnostic.code < codes.below),
71
+ );
72
+ return row?.class ?? (placed ? "type-error" : "ignored");
73
+ }
74
+
75
+ /** One diagnostic, with the line and column its offset falls on where it names a file. */
76
+ export interface LocatedDiagnostic {
77
+ readonly diagnostic: Diagnostic;
78
+ /** Where the diagnostic starts, counted from one; absent where it names no position. */
79
+ readonly at?: { readonly line: number; readonly column: number } | undefined;
80
+ }
81
+
82
+ /**
83
+ * One diagnostic as `path:line:column: TScode: message`, the position left out where it names
84
+ * none and the file where it names none. `display` spells the file's path.
85
+ */
86
+ export function renderDiagnostic(
87
+ located: LocatedDiagnostic,
88
+ display: (path: string) => string = (path) => path,
89
+ ): string {
90
+ const { diagnostic, at } = located;
91
+ const message = `TS${String(diagnostic.code)}: ${diagnostic.text}`;
92
+ if (diagnostic.fileName === undefined) {
93
+ return message;
94
+ }
95
+ const where = display(diagnostic.fileName);
96
+ return at === undefined
97
+ ? `${where}: ${message}`
98
+ : `${where}:${String(at.line)}:${String(at.column)}: ${message}`;
99
+ }
100
+
101
+ function locatedIn(
102
+ diagnostics: readonly Diagnostic[],
103
+ locate: ProjectDiagnostics["locate"],
104
+ ): readonly LocatedDiagnostic[] {
105
+ return diagnostics.map((diagnostic) => ({
106
+ diagnostic,
107
+ at: diagnostic.fileName === undefined ? undefined : locate(diagnostic.fileName, diagnostic.pos),
108
+ }));
109
+ }
110
+
111
+ /**
112
+ * Every error a project's three diagnostic sets carry, in the order the compiler reported
113
+ * them. A resolved configuration carries no diagnostics of its own, so a configuration written
114
+ * with an unreadable option resolves and is refused here, once its project is open.
115
+ */
116
+ export function diagnosticErrors(sets: {
117
+ readonly syntactic: readonly Diagnostic[];
118
+ readonly semantic: readonly Diagnostic[];
119
+ readonly configParsing: readonly Diagnostic[];
120
+ }): readonly Diagnostic[] {
121
+ return [...sets.configParsing, ...sets.syntactic, ...sets.semantic].filter(isError);
122
+ }
123
+
124
+ /** Why one open project cannot be analyzed as it stands, split by whether it loaded at all. */
125
+ interface ProjectErrors {
126
+ /** The configuration's own errors and the errors in no file the table reads as a load failure. */
127
+ readonly load: readonly LocatedDiagnostic[];
128
+ /** The errors in the files of a project that loaded. */
129
+ readonly check: readonly LocatedDiagnostic[];
130
+ /** The libraries the configuration names that the compiler cannot find, of a project that loaded. */
131
+ readonly unfound: readonly LocatedDiagnostic[];
132
+ }
133
+
134
+ /** The errors one open project carries, each located in the file it names. */
135
+ export function projectErrors(sets: ProjectDiagnostics): ProjectErrors {
136
+ const unplaced = (kind: DiagnosticClass): readonly Diagnostic[] =>
137
+ sets.unplaced.filter((diagnostic) => classOf(diagnostic, false) === kind);
138
+ const load = [...sets.configParsing.filter(isError), ...unplaced("load")];
139
+ return {
140
+ load: locatedIn(load, sets.locate),
141
+ check: load.length > 0 ? [] : locatedIn(diagnosticErrors(sets), sets.locate),
142
+ unfound: load.length > 0 ? [] : locatedIn(unplaced("unfound-library"), sets.locate),
143
+ };
144
+ }