@cplieger/deadset-ts 8.0.0-dev.8 → 8.0.0-dev.9

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 (75) hide show
  1. package/dist/src/analysis.js +84 -288
  2. package/dist/src/configuration-files.js +2 -9
  3. package/dist/src/consumers.js +1 -28
  4. package/dist/src/contract/contract.generated.js +20 -10
  5. package/dist/src/conventions.js +3 -8
  6. package/dist/src/failure.js +36 -0
  7. package/dist/src/fs/document.js +21 -28
  8. package/dist/src/fs/manifest.js +7 -0
  9. package/dist/src/load/classify.js +236 -0
  10. package/dist/src/load/diagnostics.js +79 -0
  11. package/dist/src/load/discover.js +230 -0
  12. package/dist/src/{emit-map.js → load/emit-map.js} +1 -1
  13. package/dist/src/load/expected-module.js +136 -0
  14. package/dist/src/load/load.js +22 -0
  15. package/dist/src/load/module-lookup.js +37 -0
  16. package/dist/src/load/plan.js +155 -0
  17. package/dist/src/{test-globals.js → load/test-globals.js} +51 -56
  18. package/dist/src/load/test-joins.js +82 -0
  19. package/dist/src/{workspace-manifests.js → load/workspace-manifests.js} +3 -3
  20. package/dist/src/{workspace-programs.js → load/workspace-programs.js} +37 -40
  21. package/dist/src/{workspace-resolution.js → load/workspace-resolution.js} +21 -59
  22. package/dist/src/{workspace-run.js → load/workspace-run.js} +4 -3
  23. package/dist/src/{workspace.js → load/workspace.js} +21 -17
  24. package/dist/src/outside-tests.js +1 -1
  25. package/dist/src/run.js +20 -26
  26. package/dist/src/scope.js +11 -19
  27. package/dist/src/session.js +22 -28
  28. package/dist/src/source-files.js +1 -1
  29. package/dist/src/type-errors.js +11 -216
  30. package/dist/src/verbs/analyze.js +90 -109
  31. package/dist/src/verbs/describe.js +5 -12
  32. package/dist/src/verbs/version.js +12 -2
  33. package/jsr.json +1 -1
  34. package/package.json +1 -1
  35. package/src/analysis.ts +68 -437
  36. package/src/configuration-files.ts +8 -10
  37. package/src/consumers.ts +2 -53
  38. package/src/contract/contract.generated.ts +20 -10
  39. package/src/conventions.ts +6 -12
  40. package/src/failure.ts +63 -0
  41. package/src/fs/document.ts +23 -27
  42. package/src/fs/manifest.ts +8 -0
  43. package/src/load/classify.ts +352 -0
  44. package/src/load/diagnostics.ts +141 -0
  45. package/src/load/discover.ts +378 -0
  46. package/src/{emit-map.ts → load/emit-map.ts} +1 -1
  47. package/src/load/expected-module.ts +188 -0
  48. package/src/load/load.ts +61 -0
  49. package/src/load/module-lookup.ts +50 -0
  50. package/src/load/plan.ts +258 -0
  51. package/src/{test-globals.ts → load/test-globals.ts} +59 -65
  52. package/src/load/test-joins.ts +98 -0
  53. package/src/{workspace-manifests.ts → load/workspace-manifests.ts} +4 -4
  54. package/src/{workspace-programs.ts → load/workspace-programs.ts} +59 -53
  55. package/src/{workspace-resolution.ts → load/workspace-resolution.ts} +31 -78
  56. package/src/{workspace-run.ts → load/workspace-run.ts} +14 -11
  57. package/src/{workspace.ts → load/workspace.ts} +28 -21
  58. package/src/outside-tests.ts +1 -1
  59. package/src/partial.ts +1 -1
  60. package/src/run.ts +26 -25
  61. package/src/scope.ts +15 -21
  62. package/src/session.ts +52 -53
  63. package/src/source-files.ts +1 -1
  64. package/src/type-errors.ts +18 -288
  65. package/src/verbs/analyze.ts +129 -136
  66. package/src/verbs/describe.ts +4 -11
  67. package/src/verbs/version.ts +13 -2
  68. package/dist/src/base-url.js +0 -18
  69. package/dist/src/discover.js +0 -374
  70. package/dist/src/setup-failure.js +0 -19
  71. package/dist/src/test-joins.js +0 -101
  72. package/src/base-url.ts +0 -24
  73. package/src/discover.ts +0 -548
  74. package/src/setup-failure.ts +0 -37
  75. package/src/test-joins.ts +0 -118
package/src/discover.ts DELETED
@@ -1,548 +0,0 @@
1
- import { DiagnosticCategory } from "@typescript/native/sync";
2
- import type { Diagnostic } from "@typescript/native/sync";
3
- import { baseUrlPaths } from "./base-url.ts";
4
- import type { BuildConfiguration, ProjectConfiguration } from "./config.ts";
5
- import type { Host } from "./host.ts";
6
- import { dirnamePath, joinPath, relativePath, resolvePath } from "./paths.ts";
7
- import type { Scope } from "./scope.ts";
8
- import { SetupError } from "./setup-failure.ts";
9
- import type { Engine, ProjectDiagnostics } from "./session.ts";
10
- import { writtenPath, type WorkspaceProgram } from "./workspace-programs.ts";
11
- import { filesBelow } from "./fs/tree.ts";
12
- import { LANGUAGE, message } from "./product.ts";
13
- import { LANGUAGE_ROWS } from "./contract/contract.generated.ts";
14
- import { globExpression } from "./text/glob.ts";
15
-
16
- const MARKERS = LANGUAGE_ROWS[LANGUAGE].markers.map(globExpression);
17
-
18
- /** Whether one file name is a compiler configuration's: one of the language row's markers. */
19
- export function isConfigFile(name: string): boolean {
20
- return MARKERS.some((marker) => marker.test(name));
21
- }
22
-
23
- /**
24
- * A run that cannot read what it was asked to analyze. It ends the run with the
25
- * failure code and no finding list: a configuration file the compiler cannot read,
26
- * or a project carrying an error, leaves the analysis without the type information
27
- * every answer rests on, and a partial answer is never printed as a complete one.
28
- */
29
- export class DiscoveryError extends Error {
30
- /** The diagnostics the compiler reported, in the order it reported them. */
31
- readonly diagnostics: readonly LocatedDiagnostic[];
32
-
33
- constructor(message: string, diagnostics: readonly LocatedDiagnostic[]) {
34
- super(message);
35
- this.name = "DiscoveryError";
36
- this.diagnostics = diagnostics;
37
- }
38
- }
39
-
40
- /** The category an error diagnostic carries, which the protocol sends as a number. */
41
- const ERROR_CATEGORY: number = DiagnosticCategory.Error;
42
-
43
- /** Whether one diagnostic is an error, which is what fails a run closed. */
44
- function isError(diagnostic: Diagnostic): boolean {
45
- return diagnostic.category === ERROR_CATEGORY;
46
- }
47
-
48
- /** One diagnostic, with the line and column its offset falls on where it names a file. */
49
- export interface LocatedDiagnostic {
50
- readonly diagnostic: Diagnostic;
51
- /** Where the diagnostic starts, counted from one; absent where it names no position. */
52
- readonly at?: { readonly line: number; readonly column: number } | undefined;
53
- }
54
-
55
- /**
56
- * One diagnostic as a line naming its file, its line and column, its code and its
57
- * message: `path:line:column: TScode: message`, the position left out where the
58
- * diagnostic names none and the file where it names none. `display` spells the
59
- * file's path; it answers the path itself where it is not given.
60
- */
61
- export function renderDiagnostic(
62
- located: LocatedDiagnostic,
63
- display: (path: string) => string = (path) => path,
64
- ): string {
65
- const { diagnostic, at } = located;
66
- const message = `TS${String(diagnostic.code)}: ${diagnostic.text}`;
67
- if (diagnostic.fileName === undefined) {
68
- return message;
69
- }
70
- const where = display(diagnostic.fileName);
71
- return at === undefined
72
- ? `${where}: ${message}`
73
- : `${where}:${String(at.line)}:${String(at.column)}: ${message}`;
74
- }
75
-
76
- /** Each diagnostic with the line and column its offset falls on. */
77
- function locatedIn(
78
- diagnostics: readonly Diagnostic[],
79
- locate: (fileName: string, offset: number) => { line: number; column: number } | undefined,
80
- ): readonly LocatedDiagnostic[] {
81
- return diagnostics.map((diagnostic) => ({
82
- diagnostic,
83
- at: diagnostic.fileName === undefined ? undefined : locate(diagnostic.fileName, diagnostic.pos),
84
- }));
85
- }
86
-
87
- /**
88
- * Every error a project's three diagnostic sets carry, in the order the compiler
89
- * reported them: a configuration whose options do not parse, a file whose syntax
90
- * does not, and a program that does not type-check. A resolved configuration
91
- * carries no diagnostics of its own, so a configuration written with an unreadable
92
- * option resolves and is refused here, once its project is open.
93
- */
94
- export function diagnosticErrors(sets: {
95
- readonly syntactic: readonly Diagnostic[];
96
- readonly semantic: readonly Diagnostic[];
97
- readonly configParsing: readonly Diagnostic[];
98
- }): readonly Diagnostic[] {
99
- return [...sets.configParsing, ...sets.syntactic, ...sets.semantic].filter(isError);
100
- }
101
-
102
- /** Why one open project cannot be analyzed, split by whether it loaded at all. */
103
- interface ProjectErrors {
104
- /**
105
- * The errors in the configuration itself, and the errors the compiler places in no file
106
- * that leave its checker without a type it needs: no input matched, an option that
107
- * does not parse, a missing global type. A project carrying one did not load, whatever
108
- * its files say.
109
- */
110
- readonly load: readonly LocatedDiagnostic[];
111
- /** The errors in the files of a project that loaded: their syntax and their types. */
112
- readonly check: readonly LocatedDiagnostic[];
113
- /**
114
- * The libraries the configuration names that the compiler cannot find, which leave it
115
- * loaded: a use of a name only such a library declares is an error in its file.
116
- */
117
- readonly unfound: readonly LocatedDiagnostic[];
118
- }
119
-
120
- /**
121
- * The codes of a type library and a lib the configuration names that the compiler
122
- * cannot find, which it reports while it gathers the program's files,
123
- * https://github.com/microsoft/typescript-go/blob/89d5d5b2849a0db0957065889ca58536fa6d2e4a/internal/compiler/processingDiagnostic.go,
124
- * and {@link MISSING_GLOBAL_TYPE}, which the checker reports.
125
- */
126
- const UNFOUND_LIBRARY: ReadonlySet<number> = new Set([2318, 2688, 2726, 2727]);
127
-
128
- /**
129
- * The code of a global type the checker finds in no library the program holds. The checker
130
- * types every use of one against nothing and places no error in the file, so the analysis
131
- * skips each file of such a project whole.
132
- */
133
- export const MISSING_GLOBAL_TYPE = 2318;
134
-
135
- /** The errors one open project carries, each located in the file it names. */
136
- export function projectErrors(sets: ProjectDiagnostics): ProjectErrors {
137
- // The compiler numbers its semantic messages from 2000 and its option messages from
138
- // 5000. A file-less option error, a removed option or an output layout, leaves the
139
- // program whole, and the compiler checks it all the same:
140
- // https://github.com/microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-message-codes
141
- const semantic = sets.unplaced.filter(
142
- (diagnostic) => isError(diagnostic) && diagnostic.code >= 2000 && diagnostic.code < 3000,
143
- );
144
- const unfound = semantic.filter(({ code }) => UNFOUND_LIBRARY.has(code));
145
- const load = [
146
- ...sets.configParsing.filter(isError),
147
- ...semantic.filter(({ code }) => !UNFOUND_LIBRARY.has(code)),
148
- ];
149
- return {
150
- load: locatedIn(load, sets.locate),
151
- check: load.length > 0 ? [] : locatedIn(diagnosticErrors(sets), sets.locate),
152
- unfound: load.length > 0 ? [] : locatedIn(unfound, sets.locate),
153
- };
154
- }
155
-
156
- /** One project a run analyzes. */
157
- interface DiscoveredProject {
158
- /**
159
- * The name a run gives the project: the identifier the build matrix declares for
160
- * it, or, for a project discovery derived, its configuration file's path below the
161
- * target root. A derived project whose file is not below the target root is named
162
- * by the file's absolute path, the one spelling it has.
163
- */
164
- readonly id: string;
165
- /** The compiler configuration file the project is opened from, absolute. */
166
- readonly configFile: string;
167
- }
168
-
169
- /**
170
- * One project discovery derived and the run could not build, with the first line of
171
- * the error that dropped it.
172
- */
173
- export interface NotBuilt {
174
- /** The name the project would have carried, as {@link DiscoveredProject.id} spells it. */
175
- readonly id: string;
176
- /** The compiler configuration file, absolute. */
177
- readonly configFile: string;
178
- /**
179
- * The error's first line, every path below the target root spelled relative to it, so
180
- * a report naming it carries no path of the machine it ran on.
181
- */
182
- readonly error: string;
183
- }
184
-
185
- /**
186
- * The first line of one error about the target, every mention of the target root
187
- * spelled relative to it: a path below the root loses the root and its separator, and
188
- * the root itself is `.`.
189
- */
190
- export function targetRelative(text: string, targetRoot: string): string {
191
- const root = targetRoot.endsWith("/") ? targetRoot.slice(0, -1) : targetRoot;
192
- const [first = ""] = text.split(/\r?\n/u);
193
- const spelled = first.split(`${root}/`).join("").split(root).join(".").trim();
194
- return spelled === "" ? "the configuration could not be built" : spelled;
195
- }
196
-
197
- /**
198
- * Whether one configuration is the analyzer's own guess: discovery derived it and the
199
- * scope did not name it. A guess that does not load is dropped; any other ends the run.
200
- */
201
- export function isGuess(discovery: Discovery, configFile: string): boolean {
202
- return discovery.derived && !discovery.fromScope.includes(configFile);
203
- }
204
-
205
- /** Every project discovery found, and where each came from. */
206
- interface Discovery {
207
- /** The projects, in discovery order, each once. */
208
- readonly projects: readonly DiscoveredProject[];
209
- /**
210
- * Whether discovery derived the projects rather than reading them from a declared
211
- * matrix. A derived project that fails to load is dropped and named in
212
- * {@link Discovery.notBuilt}; a declared one ends the run.
213
- */
214
- readonly derived: boolean;
215
- /** The derived configurations the compiler could not read, in discovery order. */
216
- readonly notBuilt: readonly NotBuilt[];
217
- /** The configuration file of each project, in the same order. */
218
- readonly configFiles: readonly string[];
219
- /**
220
- * The files the scope named, which are the ones a derivation reads first. A
221
- * declared matrix reads none of them.
222
- */
223
- readonly fromScope: readonly string[];
224
- }
225
-
226
- /** The configuration files below `root`, by absolute path in ascending order. */
227
- function configFilesUnder(host: Host, root: string): readonly string[] {
228
- return filesBelow(host, root, isConfigFile).map((path) => joinPath(root, path));
229
- }
230
-
231
- /**
232
- * The configuration file the scope names for the target directly, where its path
233
- * names one rather than a directory. A target naming a directory is reached by the
234
- * walk over that directory instead. A consumer's projects are a consumer's, never the
235
- * target's, so no consumer path is read here.
236
- */
237
- function scopeConfigFiles(host: Host, scope: Scope): string[] {
238
- return [scope.target.path]
239
- .filter((path) => path.endsWith(".json"))
240
- .map((path) => resolvePath(host.workingDirectory(), path));
241
- }
242
-
243
- /**
244
- * Every configuration file reached from `pending`, in the order discovery reads them:
245
- * each once, each followed by the configurations it references that `follows` admits,
246
- * transitively. A configuration the compiler cannot read ends the run naming it, unless
247
- * `unreadable` is given, which is then told the configuration and why, and the walk
248
- * goes on without it.
249
- */
250
- function derivedFrom(
251
- engine: Engine,
252
- host: Host,
253
- pending: string[],
254
- follows: (reference: string) => boolean,
255
- unreadable?: (configFile: string, reason: string) => void,
256
- ): string[] {
257
- const seen = new Set<string>();
258
- const found: string[] = [];
259
- while (pending.length > 0) {
260
- const configFile = pending.shift();
261
- if (configFile === undefined) {
262
- break;
263
- }
264
- const path = resolvePath(host.workingDirectory(), configFile);
265
- if (seen.has(path)) {
266
- continue;
267
- }
268
- seen.add(path);
269
- const read = readConfiguration(engine, path);
270
- if ("reason" in read) {
271
- if (unreadable === undefined) {
272
- throw new DiscoveryError(
273
- `${path} cannot be read as a compiler configuration: ${read.reason}`,
274
- [],
275
- );
276
- }
277
- unreadable(path, read.reason);
278
- continue;
279
- }
280
- found.push(path);
281
- pending.push(...read.references.filter(follows));
282
- }
283
- return found;
284
- }
285
-
286
- /**
287
- * The compiler configurations one consumer is loaded through: every one under its
288
- * root that is not inside an ignored directory, and the configurations each of those
289
- * references, transitively, in that order. A root that is absent, that is no
290
- * directory, or that holds no configuration ends the run naming it, because a
291
- * finding computed without a declared consumer would claim a reference set the run
292
- * never read.
293
- */
294
- export function consumerProjects(engine: Engine, host: Host, root: string): readonly string[] {
295
- const kind = host.kindOf(root);
296
- if (kind === "absent") {
297
- throw new SetupError([
298
- {
299
- setupClass: "missing-consumer",
300
- detail: `the scope declares the consumer ${root}, and nothing is at that path: check the consumer out at ${root} and install its dependencies`,
301
- },
302
- ]);
303
- }
304
- if (kind !== "directory") {
305
- throw new DiscoveryError(`the consumer ${root} is not a directory`, []);
306
- }
307
- const found = derivedFrom(engine, host, [...configFilesUnder(host, root)], () => true);
308
- if (found.length === 0) {
309
- throw new DiscoveryError(
310
- `the consumer ${root} holds no compiler configuration, so none of its references can be read`,
311
- [],
312
- );
313
- }
314
- return found;
315
- }
316
-
317
- /**
318
- * The name a derived project carries: its configuration file's path below the target
319
- * root, or the absolute path of a file outside it.
320
- */
321
- function derivedId(targetRoot: string, configFile: string): string {
322
- return relativePath(targetRoot, configFile) ?? configFile;
323
- }
324
-
325
- type Parsed = ReturnType<Engine["parseConfigFile"]>;
326
-
327
- /** The configuration files one parsed configuration's `references` name. */
328
- function referencesOf(parsed: Parsed): readonly string[] {
329
- // The parse answers a directory reference as the directory; the compiler reads a
330
- // path not ending `.json` as its `tsconfig.json`:
331
- // https://github.com/microsoft/typescript-go/blob/89d5d5b2849a0db0957065889ca58536fa6d2e4a/internal/core/projectreference.go#L18
332
- return (parsed.projectReferences ?? []).map(({ path }) =>
333
- path.endsWith(".json") ? path : joinPath(path, "tsconfig.json"),
334
- );
335
- }
336
-
337
- /**
338
- * The code of a configuration whose `extends` chain returns to a configuration it already
339
- * passed. A snapshot that opens two configurations whose `extends` chains reach one such
340
- * cycle panics (`OwnerCache.AddOwner: entry not found`, typescript 7.1.0-dev.20261014.1),
341
- * so the analysis refuses one before any snapshot is asked to open it.
342
- */
343
- const CIRCULAR_EXTENDS = 18000;
344
-
345
- /**
346
- * The configurations one configuration file's `references` name, or why it cannot be read:
347
- * the compiler throws, or its parse reports the `extends` chain circular.
348
- */
349
- function readConfiguration(
350
- engine: Engine,
351
- configFile: string,
352
- ): { readonly references: readonly string[] } | { readonly reason: string } {
353
- try {
354
- const parsed = engine.parseConfigFile(configFile);
355
- const circular = parsed.errors.find(({ code }) => code === CIRCULAR_EXTENDS);
356
- // The compiler leaves the message's `{0}` unfilled:
357
- // https://github.com/microsoft/TypeScript/pull/64755
358
- return circular === undefined
359
- ? { references: referencesOf(parsed) }
360
- : { reason: `TS${String(circular.code)}: ${circular.text.replace("{0}", () => configFile)}` };
361
- } catch (error: unknown) {
362
- return { reason: message(error) };
363
- }
364
- }
365
-
366
- /**
367
- * The references of one compiler configuration file, or ends the run naming it: a
368
- * project opened from a configuration the compiler cannot read would be analyzed with
369
- * no type information.
370
- */
371
- function parseOrRefuse(engine: Engine, configFile: string, named: string): readonly string[] {
372
- const read = readConfiguration(engine, configFile);
373
- if ("reason" in read) {
374
- throw new DiscoveryError(
375
- `${named} cannot be read as a compiler configuration: ${read.reason}`,
376
- [],
377
- );
378
- }
379
- return read.references;
380
- }
381
-
382
- /**
383
- * The projects a build matrix declares, in its order, each entry a file below the target
384
- * root: an entry naming an absent file, a directory or a file the compiler cannot read
385
- * ends the run naming it, and one naming an earlier entry's file adds nothing. A
386
- * reference below the root the matrix does not name ends the run naming both, because the
387
- * compiler builds a referenced project's sources into the referencing program without
388
- * reporting their diagnostics. A reference outside the root is an outside project.
389
- */
390
- function declaredProjects(
391
- engine: Engine,
392
- host: Host,
393
- targetRoot: string,
394
- entries: readonly ProjectConfiguration[],
395
- ): Discovery {
396
- const seen = new Set<string>();
397
- const projects: DiscoveredProject[] = [];
398
- const references = new Map<string, readonly string[]>();
399
- for (const entry of entries) {
400
- const configFile = joinPath(targetRoot, entry.project);
401
- const named = `the project ${JSON.stringify(entry.id)} (${configFile})`;
402
- const kind = host.kindOf(configFile);
403
- if (kind !== "file") {
404
- throw new DiscoveryError(
405
- kind === "absent"
406
- ? `${named} does not exist`
407
- : `${named} is a directory, and a project names its compiler configuration file`,
408
- [],
409
- );
410
- }
411
- if (seen.has(configFile)) {
412
- continue;
413
- }
414
- seen.add(configFile);
415
- references.set(configFile, parseOrRefuse(engine, configFile, named));
416
- projects.push({ id: entry.id, configFile });
417
- }
418
- for (const project of projects) {
419
- const unnamed = references
420
- .get(project.configFile)
421
- ?.find((path) => !seen.has(path) && relativePath(targetRoot, path) !== undefined);
422
- if (unnamed !== undefined) {
423
- throw new DiscoveryError(
424
- `the project ${JSON.stringify(project.id)} (${project.configFile}) references ` +
425
- `${unnamed}, which the build matrix does not name. A referenced project is built ` +
426
- "into the program that references it, so the matrix names it too",
427
- [],
428
- );
429
- }
430
- }
431
- return {
432
- projects,
433
- derived: false,
434
- notBuilt: [],
435
- configFiles: projects.map((project) => project.configFile),
436
- fromScope: [],
437
- };
438
- }
439
-
440
- /**
441
- * The projects a run derives where the matrix declares none, in discovery order: the
442
- * paths the scope names, every compiler configuration under the target root outside an
443
- * ignored directory, then each configuration below the root those reference,
444
- * transitively, each once. A reference outside the root is an outside project, whose
445
- * sources the compiler builds into the referencing program. A configuration the scope
446
- * names ends the run where it cannot be read; one the walk found is dropped and named.
447
- */
448
- function derivedProjects(engine: Engine, host: Host, scope: Scope): Discovery {
449
- const targetRoot = scope.target.path;
450
- const fromScope = scopeConfigFiles(host, scope);
451
- const notBuilt: NotBuilt[] = [];
452
- const rootDir = resolvePath(
453
- host.workingDirectory(),
454
- fromScope.length > 0 ? dirnamePath(targetRoot) : targetRoot,
455
- );
456
- const configFiles = derivedFrom(
457
- engine,
458
- host,
459
- [...fromScope, ...configFilesUnder(host, targetRoot)],
460
- (reference) => relativePath(rootDir, reference) !== undefined,
461
- (configFile, reason) => {
462
- if (fromScope.includes(configFile)) {
463
- throw new DiscoveryError(
464
- `${configFile} cannot be read as a compiler configuration: ${reason}`,
465
- [],
466
- );
467
- }
468
- notBuilt.push({
469
- id: derivedId(targetRoot, configFile),
470
- configFile,
471
- error: targetRelative(reason, resolvePath(host.workingDirectory(), targetRoot)),
472
- });
473
- },
474
- );
475
- const projects = configFiles.map((configFile) => ({
476
- id: derivedId(targetRoot, configFile),
477
- configFile,
478
- }));
479
- return { projects, derived: true, notBuilt, configFiles, fromScope };
480
- }
481
-
482
- /**
483
- * Every project one run analyzes.
484
- *
485
- * The project entries of the build matrix, where it holds any, are the projects:
486
- * exactly those, in the order the matrix lists them, each named by its declared
487
- * identifier, as {@link declaredProjects} reads them. A matrix holding no project
488
- * entry, the empty one included, leaves discovery to derive the projects from the
489
- * scope and the target tree. A platform entry names a configuration of another
490
- * language and plays no part here.
491
- *
492
- * A configuration file the compiler cannot read is never analyzed. One the matrix or
493
- * the scope names ends the run with the failure code; a guess is dropped and named in
494
- * {@link Discovery.notBuilt}. What a configuration's own contents say is read once its
495
- * project is open, by {@link diagnosticErrors}, because a resolution carries none.
496
- *
497
- * Nothing reads a build output: a project is the files its configuration names, so a
498
- * package whose sources ship as TypeScript is analyzed as it stands.
499
- */
500
- export function discoverProjects(
501
- engine: Engine,
502
- host: Host,
503
- scope: Scope,
504
- configurations: readonly BuildConfiguration[] = [],
505
- ): Discovery {
506
- const declared = configurations.filter(
507
- (entry): entry is ProjectConfiguration => "project" in entry,
508
- );
509
- if (declared.length > 0) {
510
- return declaredProjects(engine, host, scope.target.path, declared);
511
- }
512
- return derivedProjects(engine, host, scope);
513
- }
514
-
515
- /**
516
- * How the snapshot reads each configuration of `configFiles` that sets `baseUrl` and
517
- * `programs` does not already describe: a configuration only the snapshot holds, which
518
- * extends it and states the `paths` {@link baseUrlPaths} gives, so its imports resolve as
519
- * the compilers before version 7 resolve them. A configuration the compiler cannot read is
520
- * left for its project to refuse.
521
- */
522
- export function withBaseUrlPaths(
523
- engine: Engine,
524
- host: Host,
525
- configFiles: readonly string[],
526
- programs: ReadonlyMap<string, WorkspaceProgram>,
527
- ): ReadonlyMap<string, WorkspaceProgram> {
528
- const found = new Map(programs);
529
- for (const configFile of configFiles) {
530
- if (found.has(configFile)) {
531
- continue;
532
- }
533
- let paths: Record<string, string[]> | undefined;
534
- try {
535
- paths = baseUrlPaths(engine.parseConfigFile(configFile).options);
536
- } catch {
537
- continue;
538
- }
539
- if (paths !== undefined) {
540
- found.set(configFile, {
541
- kind: "configuration",
542
- file: writtenPath(host, configFile),
543
- text: `${JSON.stringify({ extends: configFile, compilerOptions: { paths } }, null, 2)}\n`,
544
- });
545
- }
546
- }
547
- return found;
548
- }
@@ -1,37 +0,0 @@
1
- import { SETUP_FAILURE_PREFIX, type SETUP_CLASSES } from "./contract/contract.generated.ts";
2
-
3
- /**
4
- * A setup failure: a file or a component the analysis needs and the project does not
5
- * provide. Each one names what is missing and the fix, on one line of the error stream
6
- * that starts with its class.
7
- */
8
-
9
- /** A class of setup failure the Contract names. */
10
- type SetupClass = (typeof SETUP_CLASSES)[number]["class"];
11
-
12
- export interface SetupFailure {
13
- readonly setupClass: SetupClass;
14
- /** What is missing and the fix, on one line. */
15
- readonly detail: string;
16
- }
17
-
18
- /** The failure as the one line of the error stream that names it. */
19
- export function setupLine(failure: SetupFailure): string {
20
- return `${SETUP_FAILURE_PREFIX}${failure.setupClass}: ${failure.detail}`;
21
- }
22
-
23
- /**
24
- * A run that met a setup failure where none may be dropped: in a configuration the
25
- * configuration document or the scope declares, in a declared consumer, or in every
26
- * configuration discovery derived. It ends the run with the failure code and no finding
27
- * list.
28
- */
29
- export class SetupError extends Error {
30
- readonly failures: readonly SetupFailure[];
31
-
32
- constructor(failures: readonly SetupFailure[]) {
33
- super(failures.map(setupLine).join("\n"));
34
- this.name = "SetupError";
35
- this.failures = failures;
36
- }
37
- }