@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.
- package/dist/bin/node-host.js +21 -3
- package/dist/src/analysis.js +94 -299
- package/dist/src/config.js +6 -83
- package/dist/src/configuration-files.js +2 -9
- package/dist/src/configured-declarations.js +15 -20
- package/dist/src/consumers.js +3 -30
- package/dist/src/contract/config.generated.js +544 -0
- package/dist/src/contract/contract.generated.js +20 -10
- package/dist/src/contract/report.generated.js +3 -2
- package/dist/src/conventions.js +3 -8
- package/dist/src/edges.js +36 -112
- package/dist/src/exempt-classes.js +0 -2
- package/dist/src/exempt.js +1 -1
- package/dist/src/failure.js +36 -0
- package/dist/src/findings/completion.js +5 -4
- package/dist/src/findings/emitters.js +1 -1
- package/dist/src/findings/intra-function.js +1 -1
- package/dist/src/findings/non-code-artifacts.js +2 -2
- package/dist/src/findings/unused-declarations.js +1 -1
- package/dist/src/findings/visibility-narrowing.js +2 -2
- package/dist/src/findings-pass.js +1 -1
- package/dist/src/framework-lifecycle.js +7 -7
- package/dist/src/fs/document.js +52 -0
- package/dist/src/fs/manifest.js +7 -0
- package/dist/src/injection-container.js +1 -1
- package/dist/src/json-document.js +194 -67
- package/dist/src/kinds.js +0 -7
- package/dist/src/load/classify.js +236 -0
- package/dist/src/load/diagnostics.js +79 -0
- package/dist/src/load/discover.js +230 -0
- package/dist/src/{emit-map.js → load/emit-map.js} +1 -1
- package/dist/src/load/expected-module.js +136 -0
- package/dist/src/load/load.js +22 -0
- package/dist/src/load/module-lookup.js +37 -0
- package/dist/src/load/plan.js +155 -0
- package/dist/src/{test-globals.js → load/test-globals.js} +51 -56
- package/dist/src/load/test-joins.js +82 -0
- package/dist/src/{workspace-manifests.js → load/workspace-manifests.js} +3 -3
- package/dist/src/{workspace-programs.js → load/workspace-programs.js} +37 -40
- package/dist/src/{workspace-resolution.js → load/workspace-resolution.js} +21 -59
- package/dist/src/{workspace-run.js → load/workspace-run.js} +4 -3
- package/dist/src/{workspace.js → load/workspace.js} +21 -17
- package/dist/src/outside-tests.js +1 -1
- package/dist/src/print.js +10 -79
- package/dist/src/report-schema.js +3 -224
- package/dist/src/resolve.js +245 -715
- package/dist/src/run.js +59 -72
- package/dist/src/schema.js +320 -344
- package/dist/src/scope.js +37 -113
- package/dist/src/serialization-contract.js +1 -1
- package/dist/src/session.js +22 -28
- package/dist/src/source-files.js +1 -1
- package/dist/src/suppress-file.js +15 -17
- package/dist/src/suppress.js +3 -3
- package/dist/src/template-field.js +4 -4
- package/dist/src/type-errors.js +11 -216
- package/dist/src/usage.js +10 -0
- package/dist/src/verbs/analyze.js +100 -122
- package/dist/src/verbs/describe.js +5 -12
- package/dist/src/verbs/explain.js +3 -3
- package/dist/src/verbs/print-projects.js +2 -2
- package/dist/src/verbs/version.js +12 -2
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/analysis.ts +95 -460
- package/src/config.ts +31 -298
- package/src/configuration-files.ts +8 -10
- package/src/configured-declarations.ts +18 -23
- package/src/consumers.ts +6 -57
- package/src/contract/config.generated.ts +798 -0
- package/src/contract/contract.generated.ts +20 -10
- package/src/contract/report.generated.ts +3 -2
- package/src/conventions.ts +6 -12
- package/src/edges.ts +39 -124
- package/src/exempt-classes.ts +0 -5
- package/src/exempt.ts +4 -4
- package/src/failure.ts +63 -0
- package/src/findings/completion.ts +5 -6
- package/src/findings/emitter.ts +2 -2
- package/src/findings/emitters.ts +1 -1
- package/src/findings/intra-function.ts +1 -1
- package/src/findings/non-code-artifacts.ts +4 -4
- package/src/findings/unused-declarations.ts +1 -1
- package/src/findings/visibility-narrowing.ts +2 -2
- package/src/findings-pass.ts +3 -3
- package/src/framework-lifecycle.ts +7 -7
- package/src/fs/document.ts +70 -0
- package/src/fs/manifest.ts +8 -0
- package/src/host.ts +12 -5
- package/src/injection-container.ts +1 -1
- package/src/json-document.ts +236 -76
- package/src/kinds.ts +0 -8
- package/src/load/classify.ts +352 -0
- package/src/load/diagnostics.ts +141 -0
- package/src/load/discover.ts +378 -0
- package/src/{emit-map.ts → load/emit-map.ts} +1 -1
- package/src/load/expected-module.ts +188 -0
- package/src/load/load.ts +61 -0
- package/src/load/module-lookup.ts +50 -0
- package/src/load/plan.ts +258 -0
- package/src/{test-globals.ts → load/test-globals.ts} +59 -65
- package/src/load/test-joins.ts +98 -0
- package/src/{workspace-manifests.ts → load/workspace-manifests.ts} +4 -4
- package/src/{workspace-programs.ts → load/workspace-programs.ts} +59 -53
- package/src/{workspace-resolution.ts → load/workspace-resolution.ts} +31 -78
- package/src/{workspace-run.ts → load/workspace-run.ts} +14 -11
- package/src/{workspace.ts → load/workspace.ts} +28 -21
- package/src/outside-tests.ts +1 -1
- package/src/partial.ts +1 -1
- package/src/print.ts +11 -92
- package/src/report-schema.ts +3 -299
- package/src/resolve.ts +281 -1105
- package/src/run.ts +68 -80
- package/src/schema.ts +391 -389
- package/src/scope.ts +45 -131
- package/src/serialization-contract.ts +1 -1
- package/src/session.ts +52 -53
- package/src/source-files.ts +1 -1
- package/src/suppress-file.ts +15 -20
- package/src/suppress.ts +3 -3
- package/src/template-field.ts +10 -7
- package/src/type-errors.ts +18 -288
- package/src/usage.ts +10 -0
- package/src/verbs/analyze.ts +139 -157
- package/src/verbs/describe.ts +4 -11
- package/src/verbs/explain.ts +3 -7
- package/src/verbs/print-projects.ts +2 -2
- package/src/verbs/verb.ts +2 -2
- package/src/verbs/version.ts +13 -2
- package/dist/src/base-url.js +0 -18
- package/dist/src/discover.js +0 -374
- package/dist/src/setup-failure.js +0 -19
- package/dist/src/test-joins.js +0 -101
- package/src/base-url.ts +0 -24
- package/src/discover.ts +0 -548
- package/src/setup-failure.ts +0 -37
- 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 {
|
|
3
|
-
import {
|
|
3
|
+
import { REPOSITORY_DOCUMENT } from "./config.js";
|
|
4
|
+
import { readTargetDocument } from "./fs/document.js";
|
|
4
5
|
import { joinPath, resolvePath } from "./paths.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
*
|
|
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
|
|
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
|
|
80
|
+
throw new UsageError(`unknown option ${JSON.stringify(spelled ?? arg)}`);
|
|
95
81
|
}
|
|
96
82
|
if (rest.length === 0) {
|
|
97
|
-
throw new
|
|
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
|
-
|
|
91
|
+
/** The document an option names. */
|
|
92
|
+
function documentAt(host, label) {
|
|
106
93
|
try {
|
|
107
|
-
|
|
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
|
-
|
|
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
|
|
118
|
-
*
|
|
119
|
-
|
|
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
|
|
125
|
-
const repository =
|
|
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 :
|
|
128
|
-
const
|
|
129
|
-
const
|
|
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
|
|
133
|
-
|
|
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
|
-
|
|
141
|
-
...(repository === undefined ? {} : { repository
|
|
142
|
-
...(central === undefined
|
|
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.
|
|
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.
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
220
|
-
|
|
221
|
-
err.write(`${
|
|
211
|
+
if (!(error instanceof FailureExit)) {
|
|
212
|
+
if (error instanceof Error && error.stack !== undefined) {
|
|
213
|
+
err.write(`${error.stack}\n`);
|
|
222
214
|
}
|
|
223
|
-
|
|
224
|
-
return EXIT_FAILURE;
|
|
215
|
+
return refuse(productFault(`meets an error none of its classes names: ${message(error)}`), err);
|
|
225
216
|
}
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
return EXIT_FAILURE;
|
|
220
|
+
for (const line of failureLines(error.failures)) {
|
|
221
|
+
err.write(`${line}\n`);
|
|
235
222
|
}
|
|
236
|
-
|
|
223
|
+
return EXIT_FAILURE;
|
|
237
224
|
}
|