@cplieger/deadset-ts 8.0.0-dev.7 → 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 (137) hide show
  1. package/dist/bin/node-host.js +21 -3
  2. package/dist/src/analysis.js +94 -299
  3. package/dist/src/config.js +6 -83
  4. package/dist/src/configuration-files.js +2 -9
  5. package/dist/src/configured-declarations.js +15 -20
  6. package/dist/src/consumers.js +3 -30
  7. package/dist/src/contract/config.generated.js +544 -0
  8. package/dist/src/contract/contract.generated.js +20 -10
  9. package/dist/src/contract/report.generated.js +3 -2
  10. package/dist/src/conventions.js +3 -8
  11. package/dist/src/edges.js +36 -112
  12. package/dist/src/exempt-classes.js +0 -2
  13. package/dist/src/exempt.js +1 -1
  14. package/dist/src/failure.js +36 -0
  15. package/dist/src/findings/completion.js +5 -4
  16. package/dist/src/findings/emitters.js +1 -1
  17. package/dist/src/findings/intra-function.js +1 -1
  18. package/dist/src/findings/non-code-artifacts.js +2 -2
  19. package/dist/src/findings/unused-declarations.js +1 -1
  20. package/dist/src/findings/visibility-narrowing.js +2 -2
  21. package/dist/src/findings-pass.js +1 -1
  22. package/dist/src/framework-lifecycle.js +7 -7
  23. package/dist/src/fs/document.js +52 -0
  24. package/dist/src/fs/manifest.js +7 -0
  25. package/dist/src/injection-container.js +1 -1
  26. package/dist/src/json-document.js +194 -67
  27. package/dist/src/kinds.js +0 -7
  28. package/dist/src/load/classify.js +236 -0
  29. package/dist/src/load/diagnostics.js +79 -0
  30. package/dist/src/load/discover.js +230 -0
  31. package/dist/src/{emit-map.js → load/emit-map.js} +1 -1
  32. package/dist/src/load/expected-module.js +136 -0
  33. package/dist/src/load/load.js +22 -0
  34. package/dist/src/load/module-lookup.js +37 -0
  35. package/dist/src/load/plan.js +155 -0
  36. package/dist/src/{test-globals.js → load/test-globals.js} +51 -56
  37. package/dist/src/load/test-joins.js +82 -0
  38. package/dist/src/{workspace-manifests.js → load/workspace-manifests.js} +3 -3
  39. package/dist/src/{workspace-programs.js → load/workspace-programs.js} +37 -40
  40. package/dist/src/{workspace-resolution.js → load/workspace-resolution.js} +21 -59
  41. package/dist/src/{workspace-run.js → load/workspace-run.js} +4 -3
  42. package/dist/src/{workspace.js → load/workspace.js} +21 -17
  43. package/dist/src/outside-tests.js +1 -1
  44. package/dist/src/print.js +10 -79
  45. package/dist/src/report-schema.js +3 -224
  46. package/dist/src/resolve.js +245 -715
  47. package/dist/src/run.js +59 -72
  48. package/dist/src/schema.js +320 -344
  49. package/dist/src/scope.js +37 -113
  50. package/dist/src/serialization-contract.js +1 -1
  51. package/dist/src/session.js +22 -28
  52. package/dist/src/source-files.js +1 -1
  53. package/dist/src/suppress-file.js +15 -17
  54. package/dist/src/suppress.js +3 -3
  55. package/dist/src/template-field.js +4 -4
  56. package/dist/src/type-errors.js +11 -216
  57. package/dist/src/usage.js +10 -0
  58. package/dist/src/verbs/analyze.js +100 -122
  59. package/dist/src/verbs/describe.js +5 -12
  60. package/dist/src/verbs/explain.js +3 -3
  61. package/dist/src/verbs/print-projects.js +2 -2
  62. package/dist/src/verbs/version.js +12 -2
  63. package/jsr.json +1 -1
  64. package/package.json +1 -1
  65. package/src/analysis.ts +95 -460
  66. package/src/config.ts +31 -298
  67. package/src/configuration-files.ts +8 -10
  68. package/src/configured-declarations.ts +18 -23
  69. package/src/consumers.ts +6 -57
  70. package/src/contract/config.generated.ts +798 -0
  71. package/src/contract/contract.generated.ts +20 -10
  72. package/src/contract/report.generated.ts +3 -2
  73. package/src/conventions.ts +6 -12
  74. package/src/edges.ts +39 -124
  75. package/src/exempt-classes.ts +0 -5
  76. package/src/exempt.ts +4 -4
  77. package/src/failure.ts +63 -0
  78. package/src/findings/completion.ts +5 -6
  79. package/src/findings/emitter.ts +2 -2
  80. package/src/findings/emitters.ts +1 -1
  81. package/src/findings/intra-function.ts +1 -1
  82. package/src/findings/non-code-artifacts.ts +4 -4
  83. package/src/findings/unused-declarations.ts +1 -1
  84. package/src/findings/visibility-narrowing.ts +2 -2
  85. package/src/findings-pass.ts +3 -3
  86. package/src/framework-lifecycle.ts +7 -7
  87. package/src/fs/document.ts +70 -0
  88. package/src/fs/manifest.ts +8 -0
  89. package/src/host.ts +12 -5
  90. package/src/injection-container.ts +1 -1
  91. package/src/json-document.ts +236 -76
  92. package/src/kinds.ts +0 -8
  93. package/src/load/classify.ts +352 -0
  94. package/src/load/diagnostics.ts +141 -0
  95. package/src/load/discover.ts +378 -0
  96. package/src/{emit-map.ts → load/emit-map.ts} +1 -1
  97. package/src/load/expected-module.ts +188 -0
  98. package/src/load/load.ts +61 -0
  99. package/src/load/module-lookup.ts +50 -0
  100. package/src/load/plan.ts +258 -0
  101. package/src/{test-globals.ts → load/test-globals.ts} +59 -65
  102. package/src/load/test-joins.ts +98 -0
  103. package/src/{workspace-manifests.ts → load/workspace-manifests.ts} +4 -4
  104. package/src/{workspace-programs.ts → load/workspace-programs.ts} +59 -53
  105. package/src/{workspace-resolution.ts → load/workspace-resolution.ts} +31 -78
  106. package/src/{workspace-run.ts → load/workspace-run.ts} +14 -11
  107. package/src/{workspace.ts → load/workspace.ts} +28 -21
  108. package/src/outside-tests.ts +1 -1
  109. package/src/partial.ts +1 -1
  110. package/src/print.ts +11 -92
  111. package/src/report-schema.ts +3 -299
  112. package/src/resolve.ts +281 -1105
  113. package/src/run.ts +68 -80
  114. package/src/schema.ts +391 -389
  115. package/src/scope.ts +45 -131
  116. package/src/serialization-contract.ts +1 -1
  117. package/src/session.ts +52 -53
  118. package/src/source-files.ts +1 -1
  119. package/src/suppress-file.ts +15 -20
  120. package/src/suppress.ts +3 -3
  121. package/src/template-field.ts +10 -7
  122. package/src/type-errors.ts +18 -288
  123. package/src/usage.ts +10 -0
  124. package/src/verbs/analyze.ts +139 -157
  125. package/src/verbs/describe.ts +4 -11
  126. package/src/verbs/explain.ts +3 -7
  127. package/src/verbs/print-projects.ts +2 -2
  128. package/src/verbs/verb.ts +2 -2
  129. package/src/verbs/version.ts +13 -2
  130. package/dist/src/base-url.js +0 -18
  131. package/dist/src/discover.js +0 -374
  132. package/dist/src/setup-failure.js +0 -19
  133. package/dist/src/test-joins.js +0 -101
  134. package/src/base-url.ts +0 -24
  135. package/src/discover.ts +0 -548
  136. package/src/setup-failure.ts +0 -37
  137. package/src/test-joins.ts +0 -118
package/src/config.ts CHANGED
@@ -1,12 +1,6 @@
1
- import {
2
- CONTRACT_VERSION,
3
- type Confidence,
4
- type Format,
5
- type Language,
6
- type Severity,
7
- } from "./contract/contract.generated.ts";
8
- import type { ExemptionClass } from "./exempt-classes.ts";
9
- import { LANGUAGE, PRODUCT } from "./product.ts";
1
+ import type { ResolvedConfig } from "./contract/config.generated.ts";
2
+ import { SEVERITIES, type Severity } from "./contract/contract.generated.ts";
3
+ import { LANGUAGE } from "./product.ts";
10
4
 
11
5
  /**
12
6
  * The name of the repository configuration at the target root, which is also the
@@ -15,254 +9,32 @@ import { LANGUAGE, PRODUCT } from "./product.ts";
15
9
  */
16
10
  export const REPOSITORY_DOCUMENT = "deadset.json";
17
11
 
18
- /**
19
- * Whether the target is an application, whose every caller is in the analyzed
20
- * graph, or a library, whose published API has callers outside it.
21
- */
22
- export type TargetKind = "application" | "library";
12
+ export type { PartialConfig, ResolvedConfig } from "./contract/config.generated.ts";
23
13
 
24
- /** The target kind as a source writes it: one kind for every language, or one per language. */
25
- export type TargetKindSetting = TargetKind | { readonly go: TargetKind; readonly ts: TargetKind };
14
+ /** Whether the target is an application or a library. */
15
+ export type TargetKind = Extract<ResolvedConfig["target"]["kind"], string>;
16
+ export type DeclarationEntry = ResolvedConfig["ts"]["serializers"][number];
17
+ export type LifecycleContract = ResolvedConfig["ts"]["lifecycle_contracts"][number];
18
+ export type BuildConfiguration = ResolvedConfig["analysis"]["configurations"][number];
19
+ export type ProjectConfiguration = Extract<BuildConfiguration, { readonly project: string }>;
20
+ export type TemplateDelimiters = ResolvedConfig["analysis"]["template_delimiters"];
21
+ export type Sort = ResolvedConfig["reporters"]["sort"];
22
+ export type Cascade = ResolvedConfig["reporters"]["cascade"];
26
23
 
27
- /** The kind a target kind setting gives one language's declarations. */
28
- export function kindOf(setting: TargetKindSetting, language: Language): TargetKind {
29
- return typeof setting === "string" ? setting : setting[language];
24
+ /** The kind a target kind setting gives this analyzer's declarations. */
25
+ export function kindOf(kind: ResolvedConfig["target"]["kind"]): TargetKind {
26
+ return typeof kind === "string" ? kind : kind[LANGUAGE];
30
27
  }
31
28
 
32
- /** Whether declarations in generated files are analyzed. */
33
- export type GeneratedFiles = "exclude" | "include";
34
-
35
- /** How a reference from a consumer's test file counts. */
36
- export type ConsumerTests = "test" | "production";
37
-
38
- /** The severities ranked, the strongest highest. */
39
- const SEVERITY_RANK: Readonly<Record<Severity, number>> = { allow: 0, warn: 1, deny: 2 };
40
-
41
29
  /** Whether a finding at one severity fails a run under the failing severity. */
42
30
  export function fails(severity: Severity, failOn: Severity): boolean {
43
- return SEVERITY_RANK[severity] >= SEVERITY_RANK[failOn];
44
- }
45
-
46
- /** The order findings are rendered in. */
47
- export type Sort = "position" | "size";
48
-
49
- /** How much of a dead component a rendering names. */
50
- export type Cascade = "roots" | "full";
51
-
52
- /**
53
- * A platform configuration: an operating system, an architecture and the build
54
- * tags in effect. It is the shape a language built under build constraints reads,
55
- * and this analyzer leaves it to that analysis.
56
- */
57
- interface PlatformConfiguration {
58
- readonly shape: "platform";
59
- readonly id: string;
60
- readonly os: string;
61
- readonly arch: string;
62
- readonly tags: readonly string[];
63
- }
64
-
65
- /**
66
- * A project configuration: one compiler configuration file, as a path below the
67
- * target root with `/` between segments.
68
- */
69
- export interface ProjectConfiguration {
70
- readonly shape: "project";
71
- readonly id: string;
72
- readonly project: string;
73
- }
74
-
75
- /**
76
- * One entry of the build matrix: a configuration the target builds under, in
77
- * exactly one of the two shapes the matrix admits.
78
- */
79
- export type BuildConfiguration = PlatformConfiguration | ProjectConfiguration;
80
-
81
- /**
82
- * The pair of action delimiters a template is parsed with. Both members are
83
- * required once a document names the object, so the pair is one setting rather
84
- * than two.
85
- */
86
- export interface TemplateDelimiters {
87
- readonly left: string;
88
- readonly right: string;
89
- }
90
-
91
- /** How the analysis is scoped and filtered. */
92
- export interface Analysis {
93
- readonly languages: readonly Language[];
94
- readonly minConfidence: Confidence;
95
- readonly generatedFiles: GeneratedFiles;
96
- readonly consumerTests: ConsumerTests;
97
- readonly configurations: readonly BuildConfiguration[];
98
- readonly matrixComplete: boolean;
99
- readonly templateDirs: readonly string[];
100
- readonly templateDelimiters: TemplateDelimiters;
101
- }
102
-
103
- /** How findings are rendered. */
104
- interface Reporters {
105
- readonly formats: readonly Format[];
106
- readonly sort: Sort;
107
- readonly cascade: Cascade;
108
- readonly maxFindings: number;
109
- readonly failOn: Severity;
110
- }
111
-
112
- /**
113
- * One declaration a configuration entry names, in exactly one of three shapes: a
114
- * declaration of the analyzed program by its stable symbol reference, a declaration a
115
- * module exports by the bare specifier an import writes for the module and the
116
- * declaration's path from its exports, or a declaration of the global scope by its
117
- * path from that scope. A path joins the name and each member with dots and spells a
118
- * static member with `:static` after it.
119
- */
120
- export type DeclarationEntry =
121
- | { readonly shape: "symbol"; readonly symbol: string }
122
- | { readonly shape: "module"; readonly module: string; readonly name: string }
123
- | { readonly shape: "global"; readonly global: string };
124
-
125
- /**
126
- * One framework's lifecycle contract: the declarations whose use makes a class one of
127
- * the framework's components, the classes whose subclasses are its components, and the
128
- * names of the members the framework calls on a component, each spelled as the last
129
- * component of a member's stable symbol reference.
130
- */
131
- export interface LifecycleContract {
132
- readonly components: readonly DeclarationEntry[];
133
- readonly bases: readonly DeclarationEntry[];
134
- readonly members: readonly string[];
135
- }
136
-
137
- /**
138
- * One analyzer the orchestrator may run, in exactly one of two shapes: an installed
139
- * analyzer, named by its command alone, or an acquirable one, which also names the
140
- * artifact acquisition fetches and verifies. This analyzer validates and prints the
141
- * list and runs nothing from it.
142
- */
143
- export type Provider =
144
- | {
145
- readonly shape: "installed";
146
- readonly name: string;
147
- readonly languages: readonly Language[];
148
- readonly command: string;
149
- }
150
- | {
151
- readonly shape: "acquirable";
152
- readonly name: string;
153
- readonly languages: readonly Language[];
154
- readonly command: string;
155
- readonly source: string;
156
- readonly version: string;
157
- readonly digest: string;
158
- };
159
-
160
- /** The analyzers the orchestrator runs. */
161
- interface Providers {
162
- readonly analyzers: readonly Provider[];
163
- }
164
-
165
- /** The section the TypeScript analyzer owns. */
166
- export interface TSSection {
167
- readonly testFiles: readonly string[];
168
- readonly entryFiles: readonly string[];
169
- readonly componentExtensions: readonly string[];
170
- readonly disabledConventions: readonly string[];
171
- readonly injectionRegistrations: readonly DeclarationEntry[];
172
- readonly lifecycleContracts: readonly LifecycleContract[];
173
- readonly serializers: readonly DeclarationEntry[];
174
- /** Whether the maintainer declares the roots the analysis finds every root the target has. */
175
- readonly rootsComplete: boolean;
176
- }
177
-
178
- /**
179
- * The resolved configuration: the closed key list of the Contract's
180
- * configuration schema, decoded, with every default applied.
181
- *
182
- * `targetKind` is empty exactly in the configuration every default states, which
183
- * is not a configuration a run may use: the field has no default and resolution
184
- * refuses a result that carries none.
185
- *
186
- * `severity` is a map rather than an object because its keys come from a
187
- * document, and an object keyed by document text answers for names it never
188
- * held. The order it is written in is the emitter's, not the map's.
189
- */
190
- export interface Config {
191
- readonly contractVersion: string;
192
- readonly targetKind: TargetKindSetting | "";
193
- readonly analysis: Analysis;
194
- readonly consumersComplete: boolean;
195
- readonly rootPatterns: readonly string[];
196
- readonly severity: ReadonlyMap<string, Severity>;
197
- readonly exemptionsDisabled: readonly ExemptionClass[];
198
- readonly reporters: Reporters;
199
- readonly providers: Providers;
200
- readonly ts: TSSection;
201
- }
202
-
203
- /**
204
- * The configuration every documented default states. `targetKind` is empty: the
205
- * field has no default and is never inferred.
206
- */
207
- export function defaultConfig(): Config {
208
- return {
209
- contractVersion: CONTRACT_VERSION,
210
- targetKind: "",
211
- analysis: {
212
- languages: [],
213
- minConfidence: "probable",
214
- generatedFiles: "exclude",
215
- consumerTests: "test",
216
- configurations: [],
217
- matrixComplete: false,
218
- templateDirs: [],
219
- templateDelimiters: { left: "{{", right: "}}" },
220
- },
221
- consumersComplete: false,
222
- rootPatterns: [],
223
- severity: new Map(),
224
- exemptionsDisabled: [],
225
- reporters: {
226
- formats: ["text"],
227
- sort: "position",
228
- cascade: "roots",
229
- maxFindings: 0,
230
- failOn: "deny",
231
- },
232
- providers: {
233
- analyzers: [
234
- { shape: "installed", name: "deadset-go", languages: ["go"], command: "deadset-go" },
235
- { shape: "installed", name: PRODUCT, languages: [LANGUAGE], command: PRODUCT },
236
- ],
237
- },
238
- ts: {
239
- testFiles: [
240
- "**/*.test.{ts,tsx,mts,cts}",
241
- "**/*.test-d.{ts,tsx,mts,cts}",
242
- "**/*.spec-d.{ts,tsx,mts,cts}",
243
- "**/*.spec.*",
244
- "**/__tests__/**",
245
- "**/__mocks__/**",
246
- "**/test-d/**",
247
- ],
248
- entryFiles: [],
249
- componentExtensions: [".vue", ".svelte", ".astro"],
250
- disabledConventions: [],
251
- injectionRegistrations: [],
252
- lifecycleContracts: [],
253
- serializers: [],
254
- rootsComplete: false,
255
- },
256
- };
31
+ return SEVERITIES.indexOf(severity) >= SEVERITIES.indexOf(failOn);
257
32
  }
258
33
 
259
34
  /** Where a resolved setting came from, in the order the sources outrank each other. */
260
35
  export type Source = "flag" | "repository" | "central" | "default";
261
36
 
262
- /**
263
- * One setting's source together with the file or flag that supplied it. `label`
264
- * is empty exactly when `source` is `"default"`.
265
- */
37
+ /** One setting's source with the file or flag that supplied it, empty for a default. */
266
38
  export interface Origin {
267
39
  readonly source: Source;
268
40
  readonly label: string;
@@ -277,63 +49,24 @@ export function renderOrigin(origin: Origin): string {
277
49
  }
278
50
 
279
51
  /**
280
- * The origin of each resolved setting, keyed by the setting's dotted path. A
281
- * section holds no value of its own and has no entry; the severity object
282
- * carries one entry per code it names, or the entry `severity` alone when it is
283
- * empty.
52
+ * The origin of each resolved setting, keyed by the setting's dotted path. A section
53
+ * has no entry; a keyed section carries one entry per member it names, or one for
54
+ * itself when it is empty.
284
55
  */
285
56
  export type Provenance = ReadonlyMap<string, Origin>;
286
57
 
287
- /**
288
- * The configuration documents one invocation reads, each the document's text or
289
- * absent. `repositoryLabel` names the document `repository` holds and
290
- * `centralLabel` the one `central` holds; `flagLabels` names the flag that
291
- * supplied each setting `flags` names, keyed by dotted setting path.
292
- */
293
- export interface Inputs {
294
- readonly flags?: string;
295
- readonly repository?: string;
296
- readonly central?: string;
297
- readonly repositoryLabel?: string;
298
- readonly centralLabel?: string;
299
- readonly flagLabels?: ReadonlyMap<string, string>;
58
+ /** One configuration document: its text and the path it was read from. */
59
+ export interface Document {
60
+ readonly text: string;
61
+ readonly label: string;
300
62
  }
301
63
 
302
- /** Which refusal a {@link ConfigError} carries. */
303
- type ErrorKind =
304
- /**
305
- * A document that is not one JSON instance of the closed key list: a syntax
306
- * error, a value of the wrong type, a value outside the closed set a key
307
- * declares, or a member written twice at one level.
308
- */
309
- | "malformed"
310
- /**
311
- * A key the closed key list does not declare, or a severity key naming no live
312
- * kind or a kind whose severity the Contract fixes.
313
- */
314
- | "unimplemented-key"
315
- /** A resolved configuration no source supplied a target kind for. */
316
- | "missing-target-kind";
317
-
318
64
  /**
319
- * Every refusal configuration resolution makes. Each maps to the usage exit
320
- * code, and each is thrown rather than returned: a refusal ends the run, and the
321
- * one caller that turns it into an exit code is the command line.
65
+ * The configuration sources one invocation carries. `flags` holds the text each
66
+ * setting option was given, by the setting's dotted path.
322
67
  */
323
- export class ConfigError extends Error {
324
- /** Which refusal this is. */
325
- readonly kind: ErrorKind;
326
-
327
- /**
328
- * The key or field the message names, spelled as the document spells it. It is
329
- * empty when the refusal names none.
330
- */
331
- readonly key: string;
332
-
333
- constructor(kind: ErrorKind, key: string, message: string) {
334
- super(message);
335
- this.name = "ConfigError";
336
- this.kind = kind;
337
- this.key = key;
338
- }
68
+ export interface Inputs {
69
+ readonly flags?: ReadonlyMap<string, string>;
70
+ readonly repository?: Document;
71
+ readonly central?: Document;
339
72
  }
@@ -24,7 +24,13 @@ import type { SourceFiles } from "./source-files.ts";
24
24
  import { bytewise } from "./text/compare.ts";
25
25
  import { isRecord } from "./json-document.ts";
26
26
  import { filesIn } from "./fs/tree.ts";
27
- import { holdsManifest, inInstalledPackages, manifestAt, readJSON } from "./fs/manifest.ts";
27
+ import {
28
+ DEPENDENCY_SECTIONS,
29
+ holdsManifest,
30
+ inInstalledPackages,
31
+ manifestAt,
32
+ readJSON,
33
+ } from "./fs/manifest.ts";
28
34
  import { shellWords } from "./text/shell.ts";
29
35
 
30
36
  /** A configuration module's name, each form with the spelling a root reports it by. */
@@ -40,14 +46,6 @@ const MODULE_FORMS: readonly { readonly name: RegExp; readonly form: string }[]
40
46
  /** A JSON configuration file's name. */
41
47
  const DOCUMENT_NAME = /^(?:[\w-]+(?:\.[\w-]+)?\.config\.json|\.[\w-]+rc(?:\.json)?)$/u;
42
48
 
43
- /** The manifest members a dependency is declared in. */
44
- const DEPENDENCY_MEMBERS = [
45
- "dependencies",
46
- "devDependencies",
47
- "peerDependencies",
48
- "optionalDependencies",
49
- ] as const;
50
-
51
49
  /** The prefixes a string names a file with, relative to the file that writes it. */
52
50
  const RELATIVE_PREFIXES = ["./", "../"] as const;
53
51
 
@@ -474,7 +472,7 @@ export function declaredIn(host: Host, dir: string): readonly string[] {
474
472
  return [];
475
473
  }
476
474
  const names = new Set<string>();
477
- for (const member of DEPENDENCY_MEMBERS) {
475
+ for (const member of DEPENDENCY_SECTIONS) {
478
476
  const section = value[member];
479
477
  if (isRecord(section)) {
480
478
  Object.keys(section).forEach((name) => names.add(name));
@@ -19,7 +19,7 @@ import {
19
19
  import { SymbolFlags, type NodeHandle, type Symbol as TSSymbol } from "@typescript/native/sync";
20
20
  import type { AliasChains } from "./alias-chain.ts";
21
21
  import { resolvedTargets } from "./calls.ts";
22
- import type { Config, DeclarationEntry } from "./config.ts";
22
+ import type { DeclarationEntry, ResolvedConfig } from "./config.ts";
23
23
  import { declaredComponent, type Inventory } from "./inventory.ts";
24
24
  import { must, Unanswerable } from "./query.ts";
25
25
  import { nameComponent } from "./ref.ts";
@@ -252,21 +252,21 @@ export function resolveEntries<Brand>(
252
252
  }
253
253
  const modules = modulesNamed(
254
254
  project,
255
- new Set(entries.flatMap((entry) => (entry.shape === "module" ? [entry.module] : []))),
255
+ new Set(entries.flatMap((entry) => ("module" in entry ? [entry.module] : []))),
256
256
  );
257
257
  return entries.map((entry) => {
258
- if (entry.shape === "symbol") {
258
+ if ("symbol" in entry) {
259
259
  return { entry, handles: new Set<string>(), ids: new Set(byRef.get(entry.symbol) ?? []) };
260
260
  }
261
261
  const { components, static: isStatic } = componentsOf(
262
- entry.shape === "module" ? entry.name : entry.global,
262
+ "module" in entry ? entry.name : entry.global,
263
263
  );
264
264
  const [first = "", ...rest] = components;
265
265
  let start: TSSymbol | undefined;
266
266
  if (isStatic && rest.length === 0) {
267
267
  // Only a member is static, and a path of one component names no member.
268
268
  start = undefined;
269
- } else if (entry.shape === "module") {
269
+ } else if ("module" in entry) {
270
270
  const module = modules.get(entry.module);
271
271
  start = module === undefined ? undefined : memberOf(project, module, first, false);
272
272
  } else if (nameComponent(first) === first) {
@@ -329,14 +329,10 @@ export function entriesAt<Brand>(
329
329
  * program the display name the inventory gives it.
330
330
  */
331
331
  export function spelledEntry(entry: DeclarationEntry, held: Inventory): string {
332
- switch (entry.shape) {
333
- case "symbol":
334
- return held.symbols.find((symbol) => symbol.ref === entry.symbol)?.name ?? entry.symbol;
335
- case "module":
336
- return entry.name;
337
- case "global":
338
- return entry.global;
332
+ if ("symbol" in entry) {
333
+ return held.symbols.find((symbol) => symbol.ref === entry.symbol)?.name ?? entry.symbol;
339
334
  }
335
+ return "module" in entry ? entry.name : entry.global;
340
336
  }
341
337
 
342
338
  /** One entry of a configuration key that names a declaration, and the key's dotted path. */
@@ -353,14 +349,17 @@ const LIFECYCLE_KEY = "ts.lifecycle_contracts";
353
349
  * the injection registrations, each lifecycle contract's components and then its bases,
354
350
  * and the serializers.
355
351
  */
356
- export function configuredDeclarations(config: Config): readonly ConfiguredDeclaration[] {
352
+ export function configuredDeclarations(config: ResolvedConfig): readonly ConfiguredDeclaration[] {
357
353
  return [
358
- ...config.ts.injectionRegistrations.map((entry) => ({
354
+ ...config.ts.injection_registrations.map((entry) => ({
359
355
  key: "ts.injection_registrations",
360
356
  entry,
361
357
  })),
362
- ...config.ts.lifecycleContracts.flatMap((contract) =>
363
- [...contract.components, ...contract.bases].map((entry) => ({ key: LIFECYCLE_KEY, entry })),
358
+ ...config.ts.lifecycle_contracts.flatMap((contract) =>
359
+ [...(contract.components ?? []), ...(contract.bases ?? [])].map((entry) => ({
360
+ key: LIFECYCLE_KEY,
361
+ entry,
362
+ })),
364
363
  ),
365
364
  ...config.ts.serializers.map((entry) => ({ key: "ts.serializers", entry })),
366
365
  ];
@@ -396,12 +395,8 @@ export function declarationsNamed<Brand>(
396
395
  * sign and its name, and a global entry's path after a number sign.
397
396
  */
398
397
  export function configuredRef(entry: DeclarationEntry): string {
399
- switch (entry.shape) {
400
- case "symbol":
401
- return entry.symbol;
402
- case "module":
403
- return `${entry.module}#${entry.name}`;
404
- case "global":
405
- return `#${entry.global}`;
398
+ if ("symbol" in entry) {
399
+ return entry.symbol;
406
400
  }
401
+ return "module" in entry ? `${entry.module}#${entry.name}` : `#${entry.global}`;
407
402
  }
package/src/consumers.ts CHANGED
@@ -1,60 +1,9 @@
1
- /**
2
- * The consumers a scope declares, loaded beside the target: each a directory on the
3
- * local filesystem whose compiler configurations open as projects of the run's one
4
- * snapshot, and whose references to the target's declarations count against them.
5
- */
6
-
7
- import type { Config } from "./config.ts";
8
- import { consumerProjects } from "./discover.ts";
1
+ import type { PartialConfig } from "./config.ts";
9
2
  import type { Host } from "./host.ts";
10
- import { inventory, packageScope } from "./inventory.ts";
3
+ import { inventory } from "./inventory.ts";
11
4
  import { relativePath } from "./paths.ts";
12
5
  import { references, type ConsumerSide, type Reference } from "./references.ts";
13
- import type { Module, Scope } from "./scope.ts";
14
- import { narrowedTo, type Engine, type ProjectView } from "./session.ts";
15
-
16
- /** One consumer the run loaded. */
17
- export interface LoadedConsumer {
18
- /** The name the consumer publishes itself under, which every finding names it by. */
19
- readonly id: string;
20
- /** The consumer's directory, absolute. */
21
- readonly path: string;
22
- }
23
-
24
- /** One declared consumer and the compiler configurations it opens as. */
25
- interface ConsumerLoad {
26
- readonly consumer: LoadedConsumer;
27
- /** The configuration files, absolute, in discovery order, none a target project's. */
28
- readonly configFiles: readonly string[];
29
- }
30
-
31
- /** The name one module publishes itself under: the scope's, else its manifest's. */
32
- export function moduleIdentity(host: Host, module: Module): string {
33
- return module.id === "" ? packageScope(host, module.path)("index.ts").package : module.id;
34
- }
35
-
36
- /**
37
- * Every consumer the scope declares, in its order, with the projects it opens as. A
38
- * configuration that is also one of the target's projects, or an earlier consumer's, is
39
- * that project's alone. A consumer whose directory is absent, is no directory or holds
40
- * no configuration ends the run naming it, before any project opens.
41
- */
42
- export function consumerLoads(
43
- engine: Engine,
44
- host: Host,
45
- scope: Scope,
46
- targetConfigFiles: readonly string[],
47
- ): readonly ConsumerLoad[] {
48
- const opened = new Set(targetConfigFiles);
49
- return scope.consumers.map((module) => {
50
- const configFiles = consumerProjects(engine, host, module.path).filter((configFile) => {
51
- const fresh = !opened.has(configFile);
52
- opened.add(configFile);
53
- return fresh;
54
- });
55
- return { consumer: { id: moduleIdentity(host, module), path: module.path }, configFiles };
56
- });
57
- }
6
+ import { narrowedTo, type ProjectView } from "./session.ts";
58
7
 
59
8
  /**
60
9
  * Every reference one consumer project's own files make to a declaration of the target.
@@ -68,7 +17,7 @@ export function consumerReferences<Brand>(
68
17
  host: Host,
69
18
  targetRoot: string,
70
19
  consumer: ConsumerSide,
71
- config: Config,
20
+ config: PartialConfig,
72
21
  ): readonly Reference[] {
73
22
  const held = inventory(
74
23
  narrowedTo(project, (file) => relativePath(targetRoot, file.fileName) !== undefined),
@@ -76,10 +25,10 @@ export function consumerReferences<Brand>(
76
25
  targetRoot,
77
26
  );
78
27
  const found = references(project, held, targetRoot, {
79
- testFiles: config.ts.testFiles,
28
+ testFiles: config.ts.test_files,
80
29
  consumer,
81
30
  }).references;
82
- if (config.analysis.consumerTests !== "production") {
31
+ if (config.analysis.consumer_tests !== "production") {
83
32
  return found;
84
33
  }
85
34
  return found.map((reference) => (reference.test ? { ...reference, test: false } : reference));