@cplieger/deadset-ts 7.2.0-dev.4 → 8.0.0-dev.2
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/src/analysis.js +108 -10
- package/dist/src/augmentations.js +62 -18
- package/dist/src/automatic-types.js +189 -0
- package/dist/src/base-url.js +18 -0
- package/dist/src/components.js +7 -6
- package/dist/src/config.js +1 -0
- package/dist/src/configuration-files.js +50 -12
- package/dist/src/conformance-record.js +2 -2
- package/dist/src/convention-rows.js +98 -0
- package/dist/src/conventions.js +101 -5
- package/dist/src/decorator.js +21 -18
- package/dist/src/dependencies.js +183 -28
- package/dist/src/discover.js +132 -11
- package/dist/src/entry-point-gaps.js +7 -10
- package/dist/src/entry-points.js +112 -11
- package/dist/src/findings/completion.js +172 -40
- package/dist/src/findings/dependencies-and-module-machinery.js +71 -25
- package/dist/src/findings/emitters.js +1 -1
- package/dist/src/findings/intra-function.js +44 -13
- package/dist/src/findings/non-code-artifacts.js +66 -33
- package/dist/src/findings/unused-declarations.js +30 -5
- package/dist/src/findings/visibility-narrowing.js +29 -5
- package/dist/src/generated-file.js +11 -0
- package/dist/src/git-ignore.js +86 -0
- package/dist/src/graph.js +4 -1
- package/dist/src/import-bindings.js +97 -0
- package/dist/src/indexed-access.js +130 -28
- package/dist/src/interface-satisfaction.js +30 -12
- package/dist/src/intra-function-parts.js +297 -45
- package/dist/src/inventory.js +52 -8
- package/dist/src/kinds.js +13 -13
- package/dist/src/matrix.js +57 -10
- package/dist/src/mdx-entries.js +197 -0
- package/dist/src/module-declarations.js +9 -13
- package/dist/src/overrides.js +41 -10
- package/dist/src/print.js +1 -0
- package/dist/src/ref.js +10 -0
- package/dist/src/references.js +38 -4
- package/dist/src/report.js +4 -2
- package/dist/src/resolve.js +2 -0
- package/dist/src/roots.js +110 -38
- package/dist/src/schema.js +1 -0
- package/dist/src/serialization-contract.js +54 -8
- package/dist/src/session.js +7 -0
- package/dist/src/source-files.js +39 -14
- package/dist/src/suppress-file.js +10 -2
- package/dist/src/suppress-inline.js +18 -2
- package/dist/src/suppress.js +8 -5
- package/dist/src/sweep.js +27 -10
- package/dist/src/symbol-keys.js +103 -2
- package/dist/src/test-support.js +119 -18
- package/dist/src/type-errors.js +34 -7
- package/dist/src/type-parameter-reads.js +172 -0
- package/dist/src/verbs/analyze.js +16 -0
- package/dist/src/verbs/explain.js +4 -2
- package/dist/src/version.js +1 -1
- package/dist/src/workflow-steps.js +119 -22
- package/dist/src/workspace-programs.js +7 -3
- package/dist/src/workspace-resolution.js +53 -10
- package/jsr.json +1 -1
- package/package.json +2 -2
- package/src/analysis.ts +146 -11
- package/src/augmentations.ts +76 -22
- package/src/automatic-types.ts +246 -0
- package/src/base-url.ts +24 -0
- package/src/components.ts +7 -6
- package/src/config.ts +3 -0
- package/src/configuration-files.ts +66 -12
- package/src/conformance-record.ts +2 -2
- package/src/convention-rows.ts +128 -0
- package/src/conventions.ts +121 -7
- package/src/decorator.ts +28 -18
- package/src/dependencies.ts +247 -41
- package/src/discover.ts +156 -13
- package/src/entry-point-gaps.ts +8 -11
- package/src/entry-points.ts +133 -11
- package/src/finding.ts +15 -0
- package/src/findings/completion.ts +222 -46
- package/src/findings/dependencies-and-module-machinery.ts +90 -28
- package/src/findings/emitters.ts +1 -1
- package/src/findings/intra-function.ts +56 -14
- package/src/findings/non-code-artifacts.ts +81 -41
- package/src/findings/unused-declarations.ts +36 -5
- package/src/findings/visibility-narrowing.ts +40 -5
- package/src/generated-file.ts +16 -0
- package/src/git-ignore.ts +98 -0
- package/src/graph.ts +6 -0
- package/src/host.ts +5 -9
- package/src/import-bindings.ts +128 -0
- package/src/indexed-access.ts +152 -30
- package/src/interface-satisfaction.ts +33 -13
- package/src/intra-function-parts.ts +394 -59
- package/src/inventory.ts +71 -7
- package/src/kinds.ts +13 -13
- package/src/matrix.ts +104 -15
- package/src/mdx-entries.ts +241 -0
- package/src/module-declarations.ts +11 -13
- package/src/overrides.ts +51 -12
- package/src/print.ts +1 -0
- package/src/ref.ts +12 -0
- package/src/references.ts +48 -3
- package/src/report.ts +16 -3
- package/src/resolve.ts +3 -0
- package/src/roots.ts +163 -45
- package/src/schema.ts +1 -0
- package/src/serialization-contract.ts +55 -4
- package/src/session.ts +7 -0
- package/src/source-files.ts +66 -16
- package/src/suppress-file.ts +12 -1
- package/src/suppress-inline.ts +18 -1
- package/src/suppress.ts +10 -5
- package/src/sweep.ts +32 -11
- package/src/symbol-keys.ts +129 -2
- package/src/test-support.ts +155 -18
- package/src/type-errors.ts +38 -6
- package/src/type-parameter-reads.ts +227 -0
- package/src/verbs/analyze.ts +22 -0
- package/src/verbs/explain.ts +5 -2
- package/src/version.ts +1 -1
- package/src/workflow-steps.ts +127 -22
- package/src/workspace-programs.ts +7 -3
- package/src/workspace-resolution.ts +62 -10
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The members a read through a value typed by a type parameter reaches: `value.kind`,
|
|
3
|
+
* where `value` is of a type parameter `T` of a generic function, reads `kind` on each
|
|
4
|
+
* object type no class declares that a call of the function passes for `T`, because the
|
|
5
|
+
* call's value is what the read reads, whatever member of the constraint the name resolves
|
|
6
|
+
* to. A class's members a constraint requires are interface satisfaction's.
|
|
7
|
+
*/
|
|
8
|
+
import { isBinaryExpression, isCallExpression, isIdentifier, isNewExpression, isPropertyAccessExpression, isTypeParameterDeclaration, SyntaxKind, } from "@typescript/native/ast";
|
|
9
|
+
import { SymbolFlags } from "@typescript/native/sync";
|
|
10
|
+
import { nodeKey } from "./inventory.js";
|
|
11
|
+
import { renderPosition } from "./position.js";
|
|
12
|
+
import { isAnswered } from "./query.js";
|
|
13
|
+
/** How deep a parameter's type is matched against the type a call passes: `readonly T[]` is one level. */
|
|
14
|
+
const MATCH_DEPTH = 3;
|
|
15
|
+
/** The name a call reaches one generic by: its own, or that of what holds it. */
|
|
16
|
+
function nameOf(generic) {
|
|
17
|
+
const own = generic.name;
|
|
18
|
+
const holder = generic.parent?.name;
|
|
19
|
+
const name = own ?? holder;
|
|
20
|
+
return name !== undefined && isIdentifier(name) ? name.text : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Whether a property access is the target of a plain assignment, which writes the member. */
|
|
23
|
+
function assignedTo(access) {
|
|
24
|
+
const parent = access.parent;
|
|
25
|
+
return (isBinaryExpression(parent) &&
|
|
26
|
+
parent.operatorToken.kind === SyntaxKind.EqualsToken &&
|
|
27
|
+
parent.left === access);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The references the reads through type-parameter-typed values of one project's own files
|
|
31
|
+
* make to the members of the types its calls pass, each made by the declaration holding
|
|
32
|
+
* the read.
|
|
33
|
+
*/
|
|
34
|
+
export function typeParameterReads(project, held, chains, root, testFiles) {
|
|
35
|
+
const queries = project.queries;
|
|
36
|
+
const reads = [];
|
|
37
|
+
const calls = [];
|
|
38
|
+
for (const file of project.ownSourceFiles()) {
|
|
39
|
+
const fileId = held.declarations.get(nodeKey(file, file));
|
|
40
|
+
if (fileId === undefined) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const visit = (node, from, generic) => {
|
|
44
|
+
const holder = held.declarations.get(nodeKey(file, node)) ?? from;
|
|
45
|
+
const inside = generic ||
|
|
46
|
+
node.typeParameters !== undefined;
|
|
47
|
+
if (inside &&
|
|
48
|
+
isPropertyAccessExpression(node) &&
|
|
49
|
+
isIdentifier(node.name) &&
|
|
50
|
+
!assignedTo(node)) {
|
|
51
|
+
reads.push({ file, from: holder, access: node });
|
|
52
|
+
}
|
|
53
|
+
if (isCallExpression(node) || isNewExpression(node)) {
|
|
54
|
+
calls.push(node);
|
|
55
|
+
}
|
|
56
|
+
node.forEachChild((child) => {
|
|
57
|
+
visit(child, holder, inside);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
file.forEachChild((child) => {
|
|
61
|
+
visit(child, fileId, false);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (reads.length === 0) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
// The reads whose receiver the checker types as a type parameter, by the generic declaring it.
|
|
68
|
+
const receivers = queries.typesAt(reads.map((read) => read.access.expression));
|
|
69
|
+
const byGeneric = new Map();
|
|
70
|
+
reads.forEach((read, at) => {
|
|
71
|
+
const type = receivers[at];
|
|
72
|
+
if (type === undefined || !isAnswered(type) || !type.isTypeParameter()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const symbol = queries.symbolOfType(type);
|
|
76
|
+
const declaration = symbol === undefined || !isAnswered(symbol)
|
|
77
|
+
? undefined
|
|
78
|
+
: symbol.declarations
|
|
79
|
+
.map((handle) => project.declarationAt(handle)?.node)
|
|
80
|
+
.find((node) => node !== undefined && isTypeParameterDeclaration(node));
|
|
81
|
+
const generic = declaration?.parent;
|
|
82
|
+
if (generic !== undefined) {
|
|
83
|
+
byGeneric.set(generic, [...(byGeneric.get(generic) ?? []), { read, parameter: type }]);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (byGeneric.size === 0) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
/** The types `instantiated` holds where `declared` holds `parameter`, matched part for part. */
|
|
90
|
+
const passedFor = (parameter, declared, instantiated, depth) => {
|
|
91
|
+
if (declared.id === parameter.id) {
|
|
92
|
+
return [instantiated];
|
|
93
|
+
}
|
|
94
|
+
if (depth >= MATCH_DEPTH) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const a = queries.typeArguments(declared);
|
|
98
|
+
const b = queries.typeArguments(instantiated);
|
|
99
|
+
if (!isAnswered(a) || !isAnswered(b) || a.length !== b.length) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
return a.flatMap((one, at) => {
|
|
103
|
+
const other = b[at];
|
|
104
|
+
return other === undefined ? [] : passedFor(parameter, one, other, depth + 1);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
// Only a call spelling a generic's name is resolved: one request each.
|
|
108
|
+
const spelled = new Set([...byGeneric.keys()].flatMap((generic) => nameOf(generic) ?? []));
|
|
109
|
+
const found = new Map();
|
|
110
|
+
for (const call of calls) {
|
|
111
|
+
const callee = call.expression;
|
|
112
|
+
const written = isIdentifier(callee)
|
|
113
|
+
? callee.text
|
|
114
|
+
: isPropertyAccessExpression(callee) && isIdentifier(callee.name)
|
|
115
|
+
? callee.name.text
|
|
116
|
+
: undefined;
|
|
117
|
+
if (written === undefined || !spelled.has(written)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const resolved = queries.resolvedSignature(call);
|
|
121
|
+
if (resolved === undefined || !isAnswered(resolved) || resolved.declaration === undefined) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const generic = project.declarationAt(resolved.declaration)?.node;
|
|
125
|
+
const pending = generic === undefined ? undefined : byGeneric.get(generic);
|
|
126
|
+
const declared = pending === undefined ? undefined : queries.genericOf(resolved);
|
|
127
|
+
if (pending === undefined || declared === undefined || !isAnswered(declared)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const count = (generic?.parameters ?? []).length;
|
|
131
|
+
for (const { read, parameter } of pending) {
|
|
132
|
+
const passed = [];
|
|
133
|
+
for (let at = 0; at < count; at += 1) {
|
|
134
|
+
const own = queries.parameterType(declared, at);
|
|
135
|
+
const given = queries.typeAtPosition(resolved, at);
|
|
136
|
+
if (own !== undefined && isAnswered(own) && isAnswered(given)) {
|
|
137
|
+
passed.push(...passedFor(parameter, own, given, 0));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const name = read.access.name.text;
|
|
141
|
+
const position = renderPosition(read.file, root, read.access.name.getStart());
|
|
142
|
+
for (const type of passed) {
|
|
143
|
+
const parts = type.isUnionType() ? queries.constituents(type) : [type];
|
|
144
|
+
for (const part of isAnswered(parts) ? parts : []) {
|
|
145
|
+
const owner = queries.symbolOfType(part);
|
|
146
|
+
if (!isAnswered(owner) ||
|
|
147
|
+
owner === undefined ||
|
|
148
|
+
(owner.flags & SymbolFlags.Class) !== 0) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const properties = queries.propertiesOf(part);
|
|
152
|
+
for (const property of isAnswered(properties) ? properties : []) {
|
|
153
|
+
if (property.name !== name) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
for (const to of chains.declarationsOf(property)) {
|
|
157
|
+
found.set(`${read.from}\u0000${to}\u0000${String(read.access.name.pos)}`, {
|
|
158
|
+
from: read.from,
|
|
159
|
+
to,
|
|
160
|
+
position,
|
|
161
|
+
use: "read",
|
|
162
|
+
resolution: "batch",
|
|
163
|
+
test: testFiles.has(position.path),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return [...found.values()];
|
|
172
|
+
}
|
|
@@ -62,6 +62,21 @@ function runRelative(invoked, path) {
|
|
|
62
62
|
}
|
|
63
63
|
return below;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* One note per manifest entry the run reads back to no source file: what the entry names
|
|
67
|
+
* reaches nothing, so the findings its file would have rooted are reported.
|
|
68
|
+
*/
|
|
69
|
+
function unmappedNotes(entries, targetRoot) {
|
|
70
|
+
return entries.map((entry) => {
|
|
71
|
+
const named = relativePath(targetRoot, entry.path) ?? entry.path;
|
|
72
|
+
return {
|
|
73
|
+
kind: "unmapped-entry",
|
|
74
|
+
path: relativePath(targetRoot, entry.dir) ?? ".",
|
|
75
|
+
key: "ts.entry_files",
|
|
76
|
+
message: `the manifest's ${entry.member} names ${named}, which reads back to no source file of the target: name the file it is built from in ts.entry_files`,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
65
80
|
/** Each project the run dropped as a report names it, by its configuration file below the target. */
|
|
66
81
|
function notBuiltOf(dropped, targetRoot) {
|
|
67
82
|
return dropped.map((one) => {
|
|
@@ -207,6 +222,7 @@ export const analyzeVerb = ({ err, host, inputs, scope, openClient, option, repe
|
|
|
207
222
|
typeErrorSkips: run.typeErrorSkips,
|
|
208
223
|
unanswered: unansweredCounts(analysis),
|
|
209
224
|
conventionsApplied: run.conventionsApplied,
|
|
225
|
+
notes: unmappedNotes(run.unmappedEntries, resolvePath(invoked, targetRoot)),
|
|
210
226
|
});
|
|
211
227
|
report = capFindings(sortFindings(built, config.reporters.sort), config.reporters.maxFindings);
|
|
212
228
|
verdict = verdictOf(result, config);
|
|
@@ -257,11 +257,13 @@ function reported(found) {
|
|
|
257
257
|
/**
|
|
258
258
|
* Every finding of the run that names the declaration by its reference and reports at
|
|
259
259
|
* another position: a part of it, or a suppression record naming it. Each is published under
|
|
260
|
-
* the reference asked about,
|
|
260
|
+
* the reference asked about, or a parameter's under one it starts, so an explanation leaving
|
|
261
|
+
* it out would disagree with the report.
|
|
261
262
|
*/
|
|
262
263
|
function namedElsewhere(findings, subject) {
|
|
263
264
|
return findings
|
|
264
|
-
.filter((found) => found.symbol.ref === subject.ref &&
|
|
265
|
+
.filter((found) => (found.symbol.holder ?? found.symbol.ref) === subject.ref &&
|
|
266
|
+
positionKey(found.position) !== subject.id)
|
|
265
267
|
.map((found) => `also reported: ${found.code} ${found.kind}\t${positionKey(found.position)}\t${found.symbol.kind} ${found.symbol.name}\n`)
|
|
266
268
|
.join("");
|
|
267
269
|
}
|
package/dist/src/version.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The source files a CI workflow's `run:` steps
|
|
3
|
-
* A workflow file is read as text, line by line, with no
|
|
2
|
+
* The source files a CI workflow's `run:` steps and the repository's git hooks name by their
|
|
3
|
+
* path from the target root. A workflow or hook file is read as text, line by line, with no
|
|
4
|
+
* YAML parsed.
|
|
4
5
|
*/
|
|
5
6
|
import { scriptTokens } from "./manifest.js";
|
|
6
|
-
import { joinPath, resolvePath } from "./paths.js";
|
|
7
|
+
import { joinPath, relativePath, resolvePath } from "./paths.js";
|
|
7
8
|
const WORKFLOWS = ".github/workflows";
|
|
8
9
|
/** A line holding a run command: indentation and one sequence marker before `run:`. */
|
|
9
10
|
const RUN_LINE = /^(\s*(?:- )?)run:(.*)$/u;
|
|
11
|
+
/** The directories whose every file is a git hook script, run as the shell runs it. */
|
|
12
|
+
const HOOK_DIRS = [".husky", ".githooks"];
|
|
13
|
+
/** The hook manager files whose commands are written under a key, with that key. */
|
|
14
|
+
const HOOK_MANAGERS = [
|
|
15
|
+
[".pre-commit-config.yaml", /^(\s*(?:- )?)entry:(.*)$/u],
|
|
16
|
+
["lefthook.yml", RUN_LINE],
|
|
17
|
+
["lefthook.yaml", RUN_LINE],
|
|
18
|
+
[".lefthook.yml", RUN_LINE],
|
|
19
|
+
];
|
|
20
|
+
/** The names GNU make reads a makefile under, in the order it tries them. */
|
|
21
|
+
const MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
22
|
+
/** The operators that end one shell command of a recipe line. */
|
|
23
|
+
const COMMAND_SEPARATORS = /&&|\|\||;|\|/u;
|
|
10
24
|
const BLOCK_SCALAR = /^[|>][+-]?$/u;
|
|
11
25
|
const QUOTED = /^(["'])(.*)\1$/su;
|
|
12
26
|
/** A token holding one of these is computed or a pattern, so it names no file. */
|
|
13
27
|
const COMPUTED = /[${*?[]/u;
|
|
14
28
|
const INDENT = /^\s*/u;
|
|
15
|
-
|
|
29
|
+
/** The files directly in one directory whose name `accepts`, in name order. */
|
|
30
|
+
function filesIn(host, dir, accepts) {
|
|
16
31
|
let entries;
|
|
17
32
|
try {
|
|
18
33
|
entries = host.readDirectory(dir);
|
|
@@ -21,16 +36,24 @@ function workflowFiles(host, dir) {
|
|
|
21
36
|
return [];
|
|
22
37
|
}
|
|
23
38
|
return entries
|
|
24
|
-
.filter((entry) => !entry.directory &&
|
|
39
|
+
.filter((entry) => !entry.directory && accepts(entry.name))
|
|
25
40
|
.map((entry) => joinPath(dir, entry.name))
|
|
26
41
|
.sort();
|
|
27
42
|
}
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
function readText(host, path) {
|
|
44
|
+
try {
|
|
45
|
+
return host.readFile(path);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Every command line one workflow file's `run:` steps, or the steps under `key`, hold. */
|
|
52
|
+
export function runCommands(text, key = RUN_LINE) {
|
|
30
53
|
const lines = text.split(/\r?\n/u);
|
|
31
54
|
const found = [];
|
|
32
55
|
for (let at = 0; at < lines.length; at += 1) {
|
|
33
|
-
const match =
|
|
56
|
+
const match = key.exec(lines[at] ?? "");
|
|
34
57
|
if (match === null) {
|
|
35
58
|
continue;
|
|
36
59
|
}
|
|
@@ -50,28 +73,92 @@ export function runCommands(text) {
|
|
|
50
73
|
}
|
|
51
74
|
return found;
|
|
52
75
|
}
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Every token the recipe lines of the target root's makefile hold, each with the directory
|
|
78
|
+
* below the root it is read against: a recipe line is one that starts with a tab, joined
|
|
79
|
+
* with the lines a trailing `\` continues it onto, and make runs each in a shell of its
|
|
80
|
+
* own, so a `cd` moves the directory of the later commands of its line alone.
|
|
81
|
+
*/
|
|
82
|
+
function recipeTokens(host, root) {
|
|
83
|
+
const path = MAKEFILES.map((name) => joinPath(root, name)).find((candidate) => host.kindOf(candidate) === "file");
|
|
84
|
+
const text = path === undefined ? undefined : readText(host, path);
|
|
85
|
+
if (text === undefined) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
56
88
|
const found = [];
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
text = host.readFile(path);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
89
|
+
for (const line of text.replace(/\\\r?\n/gu, " ").split(/\r?\n/u)) {
|
|
90
|
+
if (!line.startsWith("\t")) {
|
|
63
91
|
continue;
|
|
64
92
|
}
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
let dir = root;
|
|
94
|
+
for (const command of withoutComment(line.slice(1).replace(/^[@+-]+/u, "")).split(COMMAND_SEPARATORS)) {
|
|
95
|
+
const tokens = scriptTokens(command);
|
|
96
|
+
const [first, target, ...rest] = tokens;
|
|
97
|
+
if (first === "cd" && target !== undefined && rest.length === 0 && !COMPUTED.test(target)) {
|
|
98
|
+
dir = resolvePath(dir, target);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
for (const token of tokens) {
|
|
102
|
+
found.push({ token, dir: relativePath(root, dir) ?? "" });
|
|
103
|
+
}
|
|
67
104
|
}
|
|
68
105
|
}
|
|
69
106
|
return found;
|
|
70
107
|
}
|
|
108
|
+
/** One shell line up to its comment: a `#` that starts a word outside quotes. */
|
|
109
|
+
function withoutComment(line) {
|
|
110
|
+
let quote = "";
|
|
111
|
+
for (let at = 0; at < line.length; at += 1) {
|
|
112
|
+
const char = line[at];
|
|
113
|
+
if (quote !== "") {
|
|
114
|
+
if (char === quote) {
|
|
115
|
+
quote = "";
|
|
116
|
+
}
|
|
117
|
+
else if (char === "\\" && quote === '"') {
|
|
118
|
+
at += 1;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (char === "'" || char === '"') {
|
|
122
|
+
quote = char;
|
|
123
|
+
}
|
|
124
|
+
else if (char === "\\") {
|
|
125
|
+
at += 1;
|
|
126
|
+
}
|
|
127
|
+
else if (char === "#" && (at === 0 || /\s/u.test(line[at - 1] ?? ""))) {
|
|
128
|
+
return line.slice(0, at);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return line;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Every token the target root's workflow steps, git hooks and makefile hold: the `run:`
|
|
135
|
+
* steps of the workflow files in `.github/workflows`, every line of each file in `.husky`
|
|
136
|
+
* and `.githooks`, the `entry:` commands of `.pre-commit-config.yaml`, the `run:` commands
|
|
137
|
+
* of a lefthook file and the makefile's recipe lines.
|
|
138
|
+
*/
|
|
139
|
+
export function workflowTokens(host, targetRoot) {
|
|
140
|
+
const root = resolvePath(host.workingDirectory(), targetRoot);
|
|
141
|
+
const commands = [];
|
|
142
|
+
for (const path of filesIn(host, joinPath(root, WORKFLOWS), (name) => /\.ya?ml$/u.test(name))) {
|
|
143
|
+
commands.push(...runCommands(readText(host, path) ?? ""));
|
|
144
|
+
}
|
|
145
|
+
for (const dir of HOOK_DIRS) {
|
|
146
|
+
for (const path of filesIn(host, joinPath(root, dir), () => true)) {
|
|
147
|
+
commands.push(...(readText(host, path) ?? "").split(/\r?\n/u).map(withoutComment));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const [name, key] of HOOK_MANAGERS) {
|
|
151
|
+
commands.push(...runCommands(readText(host, joinPath(root, name)) ?? "", key));
|
|
152
|
+
}
|
|
153
|
+
return [
|
|
154
|
+
...commands.flatMap((command) => scriptTokens(command)),
|
|
155
|
+
...recipeTokens(host, root).map(({ token }) => token),
|
|
156
|
+
];
|
|
157
|
+
}
|
|
71
158
|
/**
|
|
72
|
-
* The own files the
|
|
73
|
-
*
|
|
74
|
-
* without a leading `./`, whatever directory the step runs in.
|
|
159
|
+
* The own files the target root's workflow steps and git hooks name, as
|
|
160
|
+
* {@link workflowTokens} reads them: a token equal to a file's path below the target root,
|
|
161
|
+
* with or without a leading `./`, whatever directory the step runs in.
|
|
75
162
|
*/
|
|
76
163
|
export function workflowEntries(host, targetRoot, files) {
|
|
77
164
|
const found = [];
|
|
@@ -84,5 +171,15 @@ export function workflowEntries(host, targetRoot, files) {
|
|
|
84
171
|
found.push({ file, source: token });
|
|
85
172
|
}
|
|
86
173
|
}
|
|
174
|
+
const root = resolvePath(host.workingDirectory(), targetRoot);
|
|
175
|
+
for (const { token, dir } of recipeTokens(host, root)) {
|
|
176
|
+
const below = COMPUTED.test(token) || dir === ""
|
|
177
|
+
? undefined
|
|
178
|
+
: relativePath(root, resolvePath(joinPath(root, dir), token));
|
|
179
|
+
const file = below === undefined ? undefined : files.byPath.get(below);
|
|
180
|
+
if (file !== undefined) {
|
|
181
|
+
found.push({ file, source: token });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
87
184
|
return found;
|
|
88
185
|
}
|
|
@@ -7,18 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { ModuleKind, ModuleResolutionKind } from "@typescript/native/sync";
|
|
9
9
|
import { isStringLiteralLikeNode } from "@typescript/native/ast";
|
|
10
|
+
import { baseUrlPaths } from "./base-url.js";
|
|
10
11
|
import { dirnamePath, resolvePath } from "./paths.js";
|
|
11
12
|
/** The most questions one round trip carries. */
|
|
12
13
|
const BATCH = 2048;
|
|
13
14
|
/**
|
|
14
15
|
* The options a configuration's program is built with: its own, less the ones that
|
|
15
|
-
* lay out an emitted program's inputs and outputs
|
|
16
|
+
* lay out an emitted program's inputs and outputs, and with `paths` read against the
|
|
17
|
+
* effective `baseUrl` as {@link baseUrlPaths} states. The analysis emits nothing, and a
|
|
16
18
|
* member's source is outside the importer's root directory by construction, which
|
|
17
19
|
* the compiler refuses under such a layout.
|
|
18
20
|
*/
|
|
19
21
|
function analysisOptions(parsed) {
|
|
20
22
|
const { composite, rootDir: _rootDir, outDir: _outDir, declarationDir: _declarationDir, tsBuildInfoFile: _tsBuildInfoFile, ...kept } = parsed.options;
|
|
21
|
-
|
|
23
|
+
const paths = baseUrlPaths(parsed.options);
|
|
24
|
+
const options = paths === undefined ? kept : { ...kept, paths };
|
|
25
|
+
return composite === true ? { ...options, declaration: true } : options;
|
|
22
26
|
}
|
|
23
27
|
/** The conditions an `exports` lookup under one configuration and one resolution mode reads. */
|
|
24
28
|
function conditionsOf(parsed, mode) {
|
|
@@ -73,7 +77,7 @@ function configurationOf(engine, host, reading) {
|
|
|
73
77
|
const raw = options["pathsBasePath"];
|
|
74
78
|
const base = typeof raw === "string" ? raw : dirnamePath(reading.configFile);
|
|
75
79
|
const paths = {};
|
|
76
|
-
for (const [key, targets] of Object.entries(options.paths ?? {})) {
|
|
80
|
+
for (const [key, targets] of Object.entries(baseUrlPaths(options) ?? options.paths ?? {})) {
|
|
77
81
|
paths[key] = targets.map((target) => resolvePath(base, target));
|
|
78
82
|
}
|
|
79
83
|
for (const entry of reading.entries) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Which file an import of a workspace package's name is read from
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* the package
|
|
7
|
-
* import nothing answers for is unresolved.
|
|
2
|
+
* Which file an import of a workspace package's name is read from: the package
|
|
3
|
+
* `node_modules` links the importer to or, with no link, the one its manifest depends on.
|
|
4
|
+
* A source file the compiler reaches stands; any other file reads back to its source or to
|
|
5
|
+
* a manifest target that is source, an ignored file to the source its path mirrors, a file
|
|
6
|
+
* the package neither compiles nor writes is read as installed, and the rest is unresolved.
|
|
8
7
|
*/
|
|
9
8
|
import { emittedFrom } from "./emit-map.js";
|
|
9
|
+
import { gitIgnored } from "./git-ignore.js";
|
|
10
10
|
import { dirnamePath, isAbsolutePath, joinPath, relativePath, resolvePath } from "./paths.js";
|
|
11
11
|
import { satisfies } from "./version-range.js";
|
|
12
12
|
/** The manifest members that name an entry point for the subpath `.` without `exports`. */
|
|
@@ -163,6 +163,27 @@ export function workspaceResolver(host, workspace) {
|
|
|
163
163
|
links.set(key, found);
|
|
164
164
|
return found;
|
|
165
165
|
};
|
|
166
|
+
const root = workspace.members[0]?.dir;
|
|
167
|
+
const ignored = root === undefined ? () => false : gitIgnored(host, root);
|
|
168
|
+
const manifests = new Map();
|
|
169
|
+
/** The nearest manifest at or above one directory, up to the workspace's root. */
|
|
170
|
+
const nearestManifest = (dir) => {
|
|
171
|
+
if (manifests.has(dir)) {
|
|
172
|
+
return manifests.get(dir);
|
|
173
|
+
}
|
|
174
|
+
let found;
|
|
175
|
+
try {
|
|
176
|
+
const value = JSON.parse(host.readFile(joinPath(dir, "package.json")));
|
|
177
|
+
found = isRecord(value) ? { dir, manifest: value } : undefined;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
const up = dirnamePath(dir);
|
|
181
|
+
found =
|
|
182
|
+
up === dir || root === undefined || !inside(root, up) ? undefined : nearestManifest(up);
|
|
183
|
+
}
|
|
184
|
+
manifests.set(dir, found);
|
|
185
|
+
return found;
|
|
186
|
+
};
|
|
166
187
|
const linkOf = (candidates, fromDir) => {
|
|
167
188
|
const name = candidates[0]?.name ?? "";
|
|
168
189
|
const linked = linkedFrom(name, fromDir);
|
|
@@ -174,13 +195,15 @@ export function workspaceResolver(host, workspace) {
|
|
|
174
195
|
if (scope?.name === name) {
|
|
175
196
|
return { kind: "member", member: scope };
|
|
176
197
|
}
|
|
177
|
-
|
|
198
|
+
// A package below the root that no workspace lists depends on a member as a member does.
|
|
199
|
+
const owner = scope ?? nearestManifest(fromDir);
|
|
200
|
+
const manifest = owner?.manifest;
|
|
178
201
|
const declared = DEPENDENCY_MEMBERS.flatMap((field) => {
|
|
179
202
|
const held = manifest?.[field];
|
|
180
203
|
const specifier = isRecord(held) ? held[name] : undefined;
|
|
181
204
|
return typeof specifier === "string" ? [specifier] : [];
|
|
182
205
|
});
|
|
183
|
-
const matched = candidates.filter((member) => declared.some((specifier) => dependsOn(specifier, member,
|
|
206
|
+
const matched = candidates.filter((member) => declared.some((specifier) => dependsOn(specifier, member, owner?.dir ?? fromDir)));
|
|
184
207
|
const [one, two] = matched;
|
|
185
208
|
if (one === undefined) {
|
|
186
209
|
return { kind: "none" };
|
|
@@ -191,6 +214,21 @@ export function workspaceResolver(host, workspace) {
|
|
|
191
214
|
};
|
|
192
215
|
/** The files a member's configurations compile, which is what makes a file there source. */
|
|
193
216
|
const compiled = (member, path) => member.configurations.some((configuration) => configuration.fileNames.has(path));
|
|
217
|
+
/**
|
|
218
|
+
* The member's source an ignored output path mirrors: the path below one of its
|
|
219
|
+
* directories, the deepest first, read below the member's own directory as an output
|
|
220
|
+
* directory's tree mirrors its root directory's, which a build leaves in an ignored
|
|
221
|
+
* directory however its configuration writes it.
|
|
222
|
+
*/
|
|
223
|
+
const mirrored = (member, path) => {
|
|
224
|
+
for (let dir = dirnamePath(path); inside(member.dir, dir); dir = dirnamePath(dir)) {
|
|
225
|
+
const found = emittedFrom(path, { outDir: dir, sourceDirs: [member.dir] }).find((candidate) => SOURCE.test(candidate) && !ignored(candidate) && host.kindOf(candidate) === "file");
|
|
226
|
+
if (found !== undefined) {
|
|
227
|
+
return found;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
};
|
|
194
232
|
/**
|
|
195
233
|
* The member's source one of its paths is, or is compiled from: a TypeScript source
|
|
196
234
|
* file, the source an output path maps back to, or a file one of the member's
|
|
@@ -212,6 +250,9 @@ export function workspaceResolver(host, workspace) {
|
|
|
212
250
|
if (found !== undefined) {
|
|
213
251
|
return found;
|
|
214
252
|
}
|
|
253
|
+
if (ignored(path)) {
|
|
254
|
+
return mirrored(member, path);
|
|
255
|
+
}
|
|
215
256
|
return compiled(member, path) && host.kindOf(path) === "file" ? path : undefined;
|
|
216
257
|
};
|
|
217
258
|
/** The targets a member's manifest names for one subpath, the selected one first. */
|
|
@@ -270,9 +311,11 @@ export function workspaceResolver(host, workspace) {
|
|
|
270
311
|
}
|
|
271
312
|
const { member } = linked;
|
|
272
313
|
// A member no compiler configuration builds is read as the package manager
|
|
273
|
-
// installed it, wherever the compiler's resolution found it
|
|
314
|
+
// installed it, wherever the compiler's resolution found it, unless what it found is
|
|
315
|
+
// a file the tree ignores, which no install wrote.
|
|
274
316
|
if (answered !== undefined &&
|
|
275
|
-
(member.configurations.length === 0
|
|
317
|
+
((member.configurations.length === 0 && !ignored(answered.resolvedFileName)) ||
|
|
318
|
+
!inside(member.dir, answered.resolvedFileName))) {
|
|
276
319
|
return { kind: "default" };
|
|
277
320
|
}
|
|
278
321
|
if (answered !== undefined) {
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cplieger/deadset-ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-dev.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Deterministic dead-code analysis for TypeScript, class and type members included",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@types/node": "24.19.2",
|
|
44
44
|
"eslint": "10.12.0",
|
|
45
45
|
"fast-check": "4.10.2",
|
|
46
|
-
"prettier": "3.9.
|
|
46
|
+
"prettier": "3.9.10",
|
|
47
47
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
48
48
|
"typescript-eslint": "8.71.1",
|
|
49
49
|
"vitest": "5.0.4"
|