@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/dist/src/run.js CHANGED
@@ -1,9 +1,12 @@
1
+ import { CONFIG_MAX_BYTES, SETTINGS } from "./contract/config.generated.js";
1
2
  import { EXIT_FAILURE, EXIT_USAGE } from "./contract/contract.generated.js";
2
- import { ConfigError, REPOSITORY_DOCUMENT } from "./config.js";
3
- import { DiscoveryError, renderDiagnostic } from "./discover.js";
3
+ import { REPOSITORY_DOCUMENT } from "./config.js";
4
+ import { readTargetDocument } from "./fs/document.js";
4
5
  import { joinPath, resolvePath } from "./paths.js";
5
- import { readScope, ScopeError, scopeForDir } from "./scope.js";
6
- import { SetupError, setupLine } from "./setup-failure.js";
6
+ import { renderDiagnostic } from "./load/diagnostics.js";
7
+ import { FailureExit, failureLines, productFault } from "./failure.js";
8
+ import { readScope, scopeForDir } from "./scope.js";
9
+ import { UsageError } from "./usage.js";
7
10
  import { openEngine } from "./session.js";
8
11
  import { printConfigVerb } from "./verbs/print-config.js";
9
12
  import { printProjectsVerb } from "./verbs/print-projects.js";
@@ -34,29 +37,12 @@ const USAGE = `usage: ${PRODUCT} <verb> [options]\nverbs: ${VERBS.map((verb) =>
34
37
  */
35
38
  const SOURCE_EDIT_TOKENS = ["fix", "edit", "delete", "rewrite"];
36
39
  /**
37
- * Maps an option name to the setting of the Contract's configuration schema it supplies,
38
- * so one entry registers the option, supplies the document resolution reads, and gives
39
- * the spelling the setting's provenance names. The name is this command's vocabulary and
40
- * is never derived from the path: a setting reaches the command line only by an entry,
41
- * and a path names a key the schema declares.
40
+ * Maps an option name to the setting of the Contract's configuration schema it supplies:
41
+ * the options contract/settings.json names for a setting this analyzer reads.
42
42
  */
43
- export const SETTING_OPTIONS = new Map([
44
- ["min-confidence", "analysis.min_confidence"],
45
- ["sort", "reporters.sort"],
46
- ["cascade", "reporters.cascade"],
47
- ["max-findings", "reporters.max_findings"],
48
- ["fail-on", "reporters.fail_on"],
49
- ]);
43
+ export const SETTING_OPTIONS = new Map(SETTINGS.flatMap((row) => (row.option === undefined ? [] : [[row.option, row.key]])));
50
44
  /** The options that take a value and are not settings. */
51
45
  const PLAIN_OPTIONS = new Set(["target", "config", "central", "scope"]);
52
- /**
53
- * The setting options whose value is an integer rather than a string. A value
54
- * written other than as digits is passed on as the string it is, so resolution
55
- * refuses it by its type rather than reading `1e2` as 100.
56
- */
57
- const INTEGER_OPTIONS = new Set(["max-findings"]);
58
- /** An integer as an option writes it: an optional minus sign and digits alone. */
59
- const INTEGER_TEXT = /^-?[0-9]+$/u;
60
46
  /** No option beyond the ones every verb takes. */
61
47
  const NO_OPTIONS = { plain: [], repeatable: [] };
62
48
  /**
@@ -83,7 +69,7 @@ function readOptions(args, own) {
83
69
  const repeated = new Map();
84
70
  for (const arg of args) {
85
71
  if (!arg.startsWith("-")) {
86
- throw new ConfigError("malformed", "", `unexpected argument ${JSON.stringify(arg)}`);
72
+ throw new UsageError(`unexpected argument ${JSON.stringify(arg)}`);
87
73
  }
88
74
  const [spelled, ...rest] = arg.split("=");
89
75
  const name = (spelled ?? "").replace(/^-+/u, "");
@@ -91,10 +77,10 @@ function readOptions(args, own) {
91
77
  !SETTING_OPTIONS.has(name) &&
92
78
  !own.plain.includes(name) &&
93
79
  !own.repeatable.includes(name)) {
94
- throw new ConfigError("malformed", "", `unknown option ${JSON.stringify(spelled ?? arg)}`);
80
+ throw new UsageError(`unknown option ${JSON.stringify(spelled ?? arg)}`);
95
81
  }
96
82
  if (rest.length === 0) {
97
- throw new ConfigError("malformed", "", `option ${JSON.stringify(spelled ?? arg)} takes a value`);
83
+ throw new UsageError(`option ${JSON.stringify(spelled ?? arg)} takes a value`);
98
84
  }
99
85
  const value = rest.join("=");
100
86
  named.set(name, value);
@@ -102,45 +88,49 @@ function readOptions(args, own) {
102
88
  }
103
89
  return { named, repeated };
104
90
  }
105
- function readFileOr(host, path, orUndefined) {
91
+ /** The document an option names. */
92
+ function documentAt(host, label) {
106
93
  try {
107
- return host.readFile(resolvePath(host.workingDirectory(), path));
94
+ const path = resolvePath(host.workingDirectory(), label);
95
+ // A file past the bound reads as one byte more than it, which resolution refuses.
96
+ return { text: host.readFile(path, CONFIG_MAX_BYTES + 1), label };
108
97
  }
109
98
  catch (error) {
110
- if (orUndefined) {
111
- return undefined;
112
- }
113
- throw new ConfigError("malformed", "", `${path}: ${message(error)}`);
99
+ throw new UsageError(`${label}: ${message(error)}`);
114
100
  }
115
101
  }
116
102
  /**
117
- * The configuration documents one invocation reads: the repository configuration
118
- * at the target root or the path an option named, the central configuration, and
119
- * the settings the options supply as one flag document.
103
+ * The repository configuration at the target root, none where it is absent. One that
104
+ * cannot be read is a configuration document that cannot be, refused with the usage code.
105
+ */
106
+ function repositoryAt(host, target) {
107
+ const label = joinPath(target, REPOSITORY_DOCUMENT);
108
+ const root = resolvePath(host.workingDirectory(), target);
109
+ const text = readTargetDocument(host, root, REPOSITORY_DOCUMENT, label, (named, reason) => new UsageError(`${named}: ${reason}`));
110
+ return text === undefined ? undefined : { text, label };
111
+ }
112
+ /**
113
+ * The configuration sources one invocation carries: the repository configuration at
114
+ * the target root or the path an option named, the central configuration, and the
115
+ * text each setting option was given.
120
116
  */
121
117
  function inputsOf(host, options) {
122
- const target = options.named.get("target") ?? ".";
123
118
  const named = options.named.get("config");
124
- const repositoryLabel = named ?? joinPath(target, REPOSITORY_DOCUMENT);
125
- const repository = readFileOr(host, repositoryLabel, named === undefined);
119
+ const target = options.named.get("target") ?? ".";
120
+ const repository = named === undefined ? repositoryAt(host, target) : documentAt(host, named);
126
121
  const centralLabel = options.named.get("central");
127
- const central = centralLabel === undefined ? undefined : readFileOr(host, centralLabel, false);
128
- const flat = {};
129
- const flagLabels = new Map();
130
- for (const [name, path] of SETTING_OPTIONS) {
122
+ const central = centralLabel === undefined ? undefined : documentAt(host, centralLabel);
123
+ const flags = new Map();
124
+ for (const [name, key] of SETTING_OPTIONS) {
131
125
  const value = options.named.get(name);
132
- if (value === undefined) {
133
- continue;
126
+ if (value !== undefined) {
127
+ flags.set(key, value);
134
128
  }
135
- flat[path] = INTEGER_OPTIONS.has(name) && INTEGER_TEXT.test(value) ? Number(value) : value;
136
- flagLabels.set(path, `--${name}`);
137
129
  }
138
- const flags = Object.keys(flat).length === 0 ? undefined : JSON.stringify(flat);
139
130
  return {
140
- ...(flags === undefined ? {} : { flags }),
141
- ...(repository === undefined ? {} : { repository, repositoryLabel }),
142
- ...(central === undefined || centralLabel === undefined ? {} : { central, centralLabel }),
143
- flagLabels,
131
+ flags,
132
+ ...(repository === undefined ? {} : { repository }),
133
+ ...(central === undefined ? {} : { central }),
144
134
  };
145
135
  }
146
136
  /** The scope one invocation analyzes: the document an option named, or the target. */
@@ -156,9 +146,7 @@ function scopeOf(host, options) {
156
146
  * the exit code: 0 for a completed verb, 1 for a finding that fails the run, 2 for a
157
147
  * usage error, a requested source edit or a refused configuration, 3 for a failure that
158
148
  * produced no answer. It writes nothing outside `out` and `err` and never exits the
159
- * process. `host` is the platform the run reads, the version it reports included, and
160
- * `openClient` opens the compiler client; a caller that watches what a run reads
161
- * supplies its own of either.
149
+ * process. A caller that watches what a run reads supplies its own `host` or `openClient`.
162
150
  */
163
151
  export function run(args, out, err, host, openClient = openEngine) {
164
152
  const editing = sourceEditOption(args);
@@ -198,7 +186,7 @@ function invoke(verb, own, args, streams, openClient) {
198
186
  openClient: (config) => {
199
187
  opened = openClient({
200
188
  collectTiming: false,
201
- components: { extensions: config.ts.componentExtensions, host: streams.host },
189
+ components: { extensions: config.ts.component_extensions, host: streams.host },
202
190
  });
203
191
  return opened;
204
192
  },
@@ -209,29 +197,28 @@ function invoke(verb, own, args, streams, openClient) {
209
197
  return refuse(error, streams.err);
210
198
  }
211
199
  }
212
- /** Turns one refusal into the exit code the Contract's table gives it. */
200
+ /**
201
+ * Turns one refusal into the exit code the Contract's table gives it. An error no class names
202
+ * is a fault of this analyzer, printed with its stack for the maintainers it asks the user to
203
+ * report it to.
204
+ */
213
205
  function refuse(error, err) {
214
- if (error instanceof ConfigError) {
206
+ if (error instanceof UsageError) {
215
207
  diagnose(err, error.message);
216
208
  err.write(USAGE);
217
209
  return EXIT_USAGE;
218
210
  }
219
- if (error instanceof DiscoveryError) {
220
- for (const diagnostic of error.diagnostics) {
221
- err.write(`${renderDiagnostic(diagnostic)}\n`);
211
+ if (!(error instanceof FailureExit)) {
212
+ if (error instanceof Error && error.stack !== undefined) {
213
+ err.write(`${error.stack}\n`);
222
214
  }
223
- diagnose(err, error.message);
224
- return EXIT_FAILURE;
215
+ return refuse(productFault(`meets an error none of its classes names: ${message(error)}`), err);
225
216
  }
226
- if (error instanceof SetupError) {
227
- for (const failure of error.failures) {
228
- err.write(`${setupLine(failure)}\n`);
229
- }
230
- return EXIT_FAILURE;
217
+ for (const diagnostic of error.diagnostics) {
218
+ err.write(`${renderDiagnostic(diagnostic)}\n`);
231
219
  }
232
- if (error instanceof ScopeError) {
233
- diagnose(err, error.message);
234
- return EXIT_FAILURE;
220
+ for (const line of failureLines(error.failures)) {
221
+ err.write(`${line}\n`);
235
222
  }
236
- throw error;
223
+ return EXIT_FAILURE;
237
224
  }