@cplieger/deadset-ts 8.0.0-dev.1 → 8.0.0-dev.3
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 +30 -6
- package/dist/src/augmentations.js +105 -12
- package/dist/src/build-scripts.js +437 -0
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/convention-rows.js +62 -2
- package/dist/src/conventions.js +15 -0
- package/dist/src/dependencies.js +89 -0
- package/dist/src/entry-points.js +9 -18
- package/dist/src/findings/completion.js +122 -49
- package/dist/src/findings/intra-function.js +4 -2
- package/dist/src/findings/reads-and-writes.js +7 -6
- package/dist/src/findings/unused-declarations.js +13 -5
- package/dist/src/findings/visibility-narrowing.js +8 -3
- package/dist/src/graph.js +5 -3
- package/dist/src/intra-function-parts.js +45 -17
- package/dist/src/kinds.js +8 -8
- package/dist/src/manifest.js +18 -0
- package/dist/src/matrix.js +76 -4
- package/dist/src/references.js +34 -3
- package/dist/src/report.js +23 -4
- package/dist/src/reporters/sarif.js +12 -8
- package/dist/src/roots.js +138 -11
- package/dist/src/serialization-contract.js +258 -8
- package/dist/src/suppress.js +1 -0
- package/dist/src/sweep.js +7 -9
- package/dist/src/test-globals.js +234 -0
- package/dist/src/test-support.js +8 -11
- package/dist/src/type-errors.js +11 -3
- package/dist/src/unseen-loads.js +107 -0
- package/dist/src/verbs/analyze.js +24 -2
- package/dist/src/yaml-document.js +355 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/analysis.ts +48 -8
- package/src/augmentations.ts +134 -16
- package/src/build-scripts.ts +564 -0
- package/src/conformance-record.ts +1 -1
- package/src/convention-rows.ts +72 -2
- package/src/conventions.ts +16 -0
- package/src/dependencies.ts +96 -0
- package/src/entry-points.ts +10 -25
- package/src/file-facts.ts +3 -0
- package/src/finding.ts +5 -0
- package/src/findings/completion.ts +153 -56
- package/src/findings/intra-function.ts +4 -2
- package/src/findings/reads-and-writes.ts +7 -6
- package/src/findings/unused-declarations.ts +17 -5
- package/src/findings/visibility-narrowing.ts +9 -3
- package/src/graph.ts +5 -3
- package/src/intra-function-parts.ts +55 -16
- package/src/kinds.ts +8 -8
- package/src/manifest.ts +21 -3
- package/src/matrix.ts +122 -4
- package/src/references.ts +38 -2
- package/src/report.ts +56 -16
- package/src/reporters/sarif.ts +16 -8
- package/src/roots.ts +162 -12
- package/src/serialization-contract.ts +309 -7
- package/src/suppress.ts +1 -0
- package/src/sweep.ts +21 -9
- package/src/test-globals.ts +275 -0
- package/src/test-support.ts +17 -13
- package/src/type-errors.ts +14 -3
- package/src/unseen-loads.ts +145 -0
- package/src/verbs/analyze.ts +28 -2
- package/src/yaml-document.ts +377 -0
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files a bundler's JavaScript API builds from, read from the build scripts a
|
|
3
|
+
* manifest's scripts run: the strings an options object passes as the bundler's entries.
|
|
4
|
+
* A script is read without running it, so a value that is not written out, a computed
|
|
5
|
+
* path or an options object built at run time among them, names nothing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isArrayBindingPattern,
|
|
10
|
+
isArrayLiteralExpression,
|
|
11
|
+
isArrowFunction,
|
|
12
|
+
isAsExpression,
|
|
13
|
+
isCallExpression,
|
|
14
|
+
isConstructorDeclaration,
|
|
15
|
+
isFunctionDeclaration,
|
|
16
|
+
isFunctionExpression,
|
|
17
|
+
isGetAccessorDeclaration,
|
|
18
|
+
isIdentifier,
|
|
19
|
+
isImportDeclaration,
|
|
20
|
+
isMetaProperty,
|
|
21
|
+
isMethodDeclaration,
|
|
22
|
+
isNamedImports,
|
|
23
|
+
isNamespaceImport,
|
|
24
|
+
isNewExpression,
|
|
25
|
+
isNoSubstitutionTemplateLiteral,
|
|
26
|
+
isObjectBindingPattern,
|
|
27
|
+
isObjectLiteralExpression,
|
|
28
|
+
isParenthesizedExpression,
|
|
29
|
+
isPropertyAccessExpression,
|
|
30
|
+
isPropertyAssignment,
|
|
31
|
+
isSatisfiesExpression,
|
|
32
|
+
isSetAccessorDeclaration,
|
|
33
|
+
isStringLiteral,
|
|
34
|
+
isVariableDeclaration,
|
|
35
|
+
isVariableStatement,
|
|
36
|
+
NodeFlags,
|
|
37
|
+
type CallExpression,
|
|
38
|
+
type Node,
|
|
39
|
+
type SourceFile,
|
|
40
|
+
} from "@typescript/native/ast";
|
|
41
|
+
import { filesNamedBy, type ParseFile } from "./configuration-files.ts";
|
|
42
|
+
import { globExpression } from "./glob.ts";
|
|
43
|
+
import type { Host } from "./host.ts";
|
|
44
|
+
import { scriptTokens } from "./manifest.ts";
|
|
45
|
+
import { dirnamePath, joinPath, relativePath, resolvePath } from "./paths.ts";
|
|
46
|
+
import type { SourceFiles } from "./source-files.ts";
|
|
47
|
+
|
|
48
|
+
/** One bundler API: the module, the functions it exports that build, and the option naming entries. */
|
|
49
|
+
interface BundlerAPI {
|
|
50
|
+
readonly module: string;
|
|
51
|
+
/** The exported names of the building functions; `default` is the module's own value called. */
|
|
52
|
+
readonly calls: readonly string[];
|
|
53
|
+
/** The option whose strings name the entries, read as `entries` states. */
|
|
54
|
+
readonly option: string;
|
|
55
|
+
/** The option that moves the directory the entries are read against. */
|
|
56
|
+
readonly base: string;
|
|
57
|
+
/** Whether an entry string is a path, glob characters matching, or a module request, only a relative one naming a file. */
|
|
58
|
+
readonly paths: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The bundlers whose build call names its entries: esbuild resolves `entryPoints` against
|
|
63
|
+
* `absWorkingDir` (https://esbuild.github.io/api/#working-directory), webpack `entry`
|
|
64
|
+
* against `context` (https://webpack.js.org/configuration/entry-context/), and Rollup
|
|
65
|
+
* `input` against the working directory, each the manifest's directory when its script runs.
|
|
66
|
+
*/
|
|
67
|
+
const BUNDLERS: readonly BundlerAPI[] = [
|
|
68
|
+
{
|
|
69
|
+
module: "esbuild",
|
|
70
|
+
calls: ["build", "buildSync", "context"],
|
|
71
|
+
option: "entryPoints",
|
|
72
|
+
base: "absWorkingDir",
|
|
73
|
+
paths: true,
|
|
74
|
+
},
|
|
75
|
+
{ module: "webpack", calls: ["default"], option: "entry", base: "context", paths: false },
|
|
76
|
+
{ module: "rollup", calls: ["rollup", "watch"], option: "input", base: "", paths: true },
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const MODULE_EXTENSION = /\.(?:js|mjs|cjs|ts|mts|cts)$/u;
|
|
80
|
+
|
|
81
|
+
const MANIFEST = "package.json";
|
|
82
|
+
|
|
83
|
+
/** One own file a build script's bundler call names as an entry. */
|
|
84
|
+
interface BuildEntry {
|
|
85
|
+
readonly file: SourceFile;
|
|
86
|
+
/** The string that named it. */
|
|
87
|
+
readonly source: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
91
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The expression a wrapper that changes no value holds. */
|
|
95
|
+
function unwrapped(node: Node): Node {
|
|
96
|
+
let at = node;
|
|
97
|
+
while (isParenthesizedExpression(at) || isAsExpression(at) || isSatisfiesExpression(at)) {
|
|
98
|
+
at = at.expression;
|
|
99
|
+
}
|
|
100
|
+
return at;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function literalOf(node: Node): string | undefined {
|
|
104
|
+
const at = unwrapped(node);
|
|
105
|
+
return isStringLiteral(at) || isNoSubstitutionTemplateLiteral(at) ? at.text : undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Whether one call is `require(<module>)`. */
|
|
109
|
+
function requires(node: Node, module: string): boolean {
|
|
110
|
+
const at = unwrapped(node);
|
|
111
|
+
return (
|
|
112
|
+
isCallExpression(at) &&
|
|
113
|
+
isIdentifier(at.expression) &&
|
|
114
|
+
at.expression.text === "require" &&
|
|
115
|
+
at.arguments.length === 1 &&
|
|
116
|
+
at.arguments[0] !== undefined &&
|
|
117
|
+
literalOf(at.arguments[0]) === module
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The local names one file binds to a bundler: each building function, and the module's own value. */
|
|
122
|
+
interface Bindings {
|
|
123
|
+
readonly functions: ReadonlySet<string>;
|
|
124
|
+
readonly modules: ReadonlySet<string>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function bindingsOf(file: SourceFile, api: BundlerAPI): Bindings {
|
|
128
|
+
const functions = new Set<string>();
|
|
129
|
+
const modules = new Set<string>();
|
|
130
|
+
const building = (name: string): boolean => api.calls.includes(name);
|
|
131
|
+
for (const statement of file.statements) {
|
|
132
|
+
if (isImportDeclaration(statement)) {
|
|
133
|
+
if (literalOf(statement.moduleSpecifier) !== api.module) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const clause = statement.importClause;
|
|
137
|
+
if (clause?.name !== undefined) {
|
|
138
|
+
(building("default") ? functions : modules).add(clause.name.text);
|
|
139
|
+
}
|
|
140
|
+
const named = clause?.namedBindings;
|
|
141
|
+
if (named !== undefined && isNamespaceImport(named)) {
|
|
142
|
+
modules.add(named.name.text);
|
|
143
|
+
} else if (named !== undefined && isNamedImports(named)) {
|
|
144
|
+
for (const element of named.elements) {
|
|
145
|
+
if (building((element.propertyName ?? element.name).text)) {
|
|
146
|
+
functions.add(element.name.text);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} else if (isVariableStatement(statement)) {
|
|
151
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
152
|
+
const { name, initializer } = declaration;
|
|
153
|
+
if (initializer === undefined || !requires(initializer, api.module)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (isIdentifier(name)) {
|
|
157
|
+
(building("default") ? functions : modules).add(name.text);
|
|
158
|
+
} else if (isObjectBindingPattern(name)) {
|
|
159
|
+
for (const element of name.elements) {
|
|
160
|
+
const local = element.name;
|
|
161
|
+
const key = element.propertyName ?? local;
|
|
162
|
+
if (
|
|
163
|
+
key !== undefined &&
|
|
164
|
+
local !== undefined &&
|
|
165
|
+
isIdentifier(key) &&
|
|
166
|
+
isIdentifier(local) &&
|
|
167
|
+
building(key.text)
|
|
168
|
+
) {
|
|
169
|
+
functions.add(local.text);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { functions, modules };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Whether one call's callee is a building function of a bundler the file binds, `shadowed` naming none. */
|
|
180
|
+
function builds(
|
|
181
|
+
callee: Node,
|
|
182
|
+
api: BundlerAPI,
|
|
183
|
+
bindings: Bindings,
|
|
184
|
+
shadowed: ReadonlySet<string>,
|
|
185
|
+
): boolean {
|
|
186
|
+
const at = unwrapped(callee);
|
|
187
|
+
if (isIdentifier(at)) {
|
|
188
|
+
return bindings.functions.has(at.text) && !shadowed.has(at.text);
|
|
189
|
+
}
|
|
190
|
+
if (
|
|
191
|
+
!isPropertyAccessExpression(at) ||
|
|
192
|
+
!isIdentifier(at.name) ||
|
|
193
|
+
!api.calls.includes(at.name.text)
|
|
194
|
+
) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
const holder = unwrapped(at.expression);
|
|
198
|
+
return (
|
|
199
|
+
(isIdentifier(holder) && bindings.modules.has(holder.text) && !shadowed.has(holder.text)) ||
|
|
200
|
+
requires(holder, api.module)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The top-level `const` initializers one file declares, by name. */
|
|
205
|
+
function constants(file: SourceFile): ReadonlyMap<string, Node> {
|
|
206
|
+
const found = new Map<string, Node>();
|
|
207
|
+
for (const statement of file.statements) {
|
|
208
|
+
if (
|
|
209
|
+
isVariableStatement(statement) &&
|
|
210
|
+
(statement.declarationList.flags & NodeFlags.Const) !== 0
|
|
211
|
+
) {
|
|
212
|
+
for (const { name, initializer } of statement.declarationList.declarations) {
|
|
213
|
+
if (isIdentifier(name) && initializer !== undefined) {
|
|
214
|
+
found.set(name.text, initializer);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return found;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The value one object literal writes for one member as `name: value`. */
|
|
223
|
+
function member(object: Node, name: string): Node | undefined {
|
|
224
|
+
if (!isObjectLiteralExpression(object)) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
for (const property of object.properties) {
|
|
228
|
+
if (isPropertyAssignment(property) && literalOrName(property.name) === name) {
|
|
229
|
+
return property.initializer;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function literalOrName(node: Node): string | undefined {
|
|
236
|
+
return isIdentifier(node) ? node.text : literalOf(node);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Whether one expression is the script's own directory: `__dirname` or `import.meta.dirname`. */
|
|
240
|
+
function isOwnDirectory(node: Node): boolean {
|
|
241
|
+
const at = unwrapped(node);
|
|
242
|
+
if (isIdentifier(at)) {
|
|
243
|
+
return at.text === "__dirname";
|
|
244
|
+
}
|
|
245
|
+
return (
|
|
246
|
+
isPropertyAccessExpression(at) &&
|
|
247
|
+
isMetaProperty(at.expression) &&
|
|
248
|
+
isIdentifier(at.name) &&
|
|
249
|
+
at.name.text === "dirname"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** One path an entry value writes. */
|
|
254
|
+
interface EntryPath {
|
|
255
|
+
readonly path: string;
|
|
256
|
+
/** What the script writes for it. */
|
|
257
|
+
readonly text: string;
|
|
258
|
+
/** Whether it is written as neither a relative nor an absolute path. */
|
|
259
|
+
readonly request: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The path one entry value writes, read against `dir`: a literal, or a `resolve` or
|
|
264
|
+
* `join` call, of `path` or bound from it, whose first argument is the script's own
|
|
265
|
+
* directory and whose others are literals.
|
|
266
|
+
*/
|
|
267
|
+
function pathOf(node: Node, dir: string, scriptDir: string): EntryPath | undefined {
|
|
268
|
+
const at = unwrapped(node);
|
|
269
|
+
const text = literalOf(at);
|
|
270
|
+
if (text !== undefined) {
|
|
271
|
+
const request = !text.startsWith("./") && !text.startsWith("../") && !text.startsWith("/");
|
|
272
|
+
return { path: resolvePath(dir, text), text, request };
|
|
273
|
+
}
|
|
274
|
+
if (!isCallExpression(at)) {
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
const callee = unwrapped(at.expression);
|
|
278
|
+
const name = isPropertyAccessExpression(callee) ? callee.name : callee;
|
|
279
|
+
if (!isIdentifier(name) || (name.text !== "resolve" && name.text !== "join")) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const [first, ...rest] = at.arguments;
|
|
283
|
+
const parts = rest.map(literalOf);
|
|
284
|
+
if (first === undefined || !isOwnDirectory(first) || parts.some((part) => part === undefined)) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
const joined = parts.join("/");
|
|
288
|
+
return { path: resolvePath(scriptDir, joined), text: joined, request: false };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The entry values one entries option writes: a value, an array of them, an object of them. */
|
|
292
|
+
function entryValues(node: Node): readonly Node[] {
|
|
293
|
+
const at = unwrapped(node);
|
|
294
|
+
if (isArrayLiteralExpression(at)) {
|
|
295
|
+
return at.elements.flatMap(entryValues);
|
|
296
|
+
}
|
|
297
|
+
if (isObjectLiteralExpression(at)) {
|
|
298
|
+
const imported = member(at, "import") ?? member(at, "in");
|
|
299
|
+
if (imported !== undefined) {
|
|
300
|
+
return entryValues(imported);
|
|
301
|
+
}
|
|
302
|
+
return at.properties.flatMap((property) =>
|
|
303
|
+
isPropertyAssignment(property) ? entryValues(property.initializer) : [],
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
return [at];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** The own files one entry string names, read as `api` reads it. */
|
|
310
|
+
function entriesNamed(
|
|
311
|
+
files: SourceFiles,
|
|
312
|
+
api: BundlerAPI,
|
|
313
|
+
entry: EntryPath,
|
|
314
|
+
): readonly SourceFile[] {
|
|
315
|
+
if (!api.paths && entry.request) {
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
if (api.paths && /[*?[{]/u.test(entry.text)) {
|
|
319
|
+
const expression = globExpression(entry.path);
|
|
320
|
+
return [...files.byName.values()].filter((file) => expression.test(file.fileName));
|
|
321
|
+
}
|
|
322
|
+
const dir = dirnamePath(entry.path);
|
|
323
|
+
return filesNamedBy(files, dir, entry.path.slice(dir.length + 1));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Whether one node is a function, whose body runs only where something calls it. */
|
|
327
|
+
function isFunction(node: Node): boolean {
|
|
328
|
+
return (
|
|
329
|
+
isFunctionDeclaration(node) ||
|
|
330
|
+
isFunctionExpression(node) ||
|
|
331
|
+
isArrowFunction(node) ||
|
|
332
|
+
isMethodDeclaration(node) ||
|
|
333
|
+
isConstructorDeclaration(node) ||
|
|
334
|
+
isGetAccessorDeclaration(node) ||
|
|
335
|
+
isSetAccessorDeclaration(node)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** The names one binding name binds: an identifier, or each name a pattern holds. */
|
|
340
|
+
function boundNames(name: Node, into: Set<string>): void {
|
|
341
|
+
if (isIdentifier(name)) {
|
|
342
|
+
into.add(name.text);
|
|
343
|
+
} else if (isObjectBindingPattern(name) || isArrayBindingPattern(name)) {
|
|
344
|
+
name.forEachChild((element) => {
|
|
345
|
+
const bound = (element as { readonly name?: Node }).name;
|
|
346
|
+
if (bound !== undefined) {
|
|
347
|
+
boundNames(bound, into);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** The names one function binds of its own: its parameters and the declarations its body holds outside nested functions. */
|
|
354
|
+
function ownBindings(fn: Node): ReadonlySet<string> {
|
|
355
|
+
const found = new Set<string>();
|
|
356
|
+
const visit = (node: Node): void => {
|
|
357
|
+
if (node !== fn && isFunction(node)) {
|
|
358
|
+
if (isFunctionDeclaration(node) && node.name !== undefined) {
|
|
359
|
+
found.add(node.name.text);
|
|
360
|
+
}
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (isVariableDeclaration(node)) {
|
|
364
|
+
boundNames(node.name, found);
|
|
365
|
+
}
|
|
366
|
+
node.forEachChild(visit);
|
|
367
|
+
};
|
|
368
|
+
for (const parameter of (fn as { readonly parameters?: readonly { readonly name: Node }[] })
|
|
369
|
+
.parameters ?? []) {
|
|
370
|
+
boundNames(parameter.name, found);
|
|
371
|
+
}
|
|
372
|
+
fn.forEachChild(visit);
|
|
373
|
+
return found;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** The functions one file declares under a name: a function declaration, or a variable bound to a function. */
|
|
377
|
+
function namedFunctions(file: SourceFile): ReadonlyMap<string, readonly Node[]> {
|
|
378
|
+
const found = new Map<string, Node[]>();
|
|
379
|
+
const add = (name: string, fn: Node): void => {
|
|
380
|
+
found.set(name, [...(found.get(name) ?? []), fn]);
|
|
381
|
+
};
|
|
382
|
+
const visit = (node: Node): void => {
|
|
383
|
+
if (isFunctionDeclaration(node) && node.name !== undefined) {
|
|
384
|
+
add(node.name.text, node);
|
|
385
|
+
} else if (
|
|
386
|
+
isVariableDeclaration(node) &&
|
|
387
|
+
isIdentifier(node.name) &&
|
|
388
|
+
node.initializer !== undefined &&
|
|
389
|
+
isFunction(unwrapped(node.initializer))
|
|
390
|
+
) {
|
|
391
|
+
add(node.name.text, unwrapped(node.initializer));
|
|
392
|
+
}
|
|
393
|
+
node.forEachChild(visit);
|
|
394
|
+
};
|
|
395
|
+
file.forEachChild(visit);
|
|
396
|
+
return found;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* The calls one build script runs: those of its top level, and those of each function
|
|
401
|
+
* a call it runs calls or passes on, as a callee, an argument or a function called where
|
|
402
|
+
* it is written. `shadowed` is the names a function running them binds of its own, which
|
|
403
|
+
* hide the file's bindings of the same names.
|
|
404
|
+
*/
|
|
405
|
+
function runCalls(
|
|
406
|
+
file: SourceFile,
|
|
407
|
+
each: (call: CallExpression, shadowed: ReadonlySet<string>) => void,
|
|
408
|
+
): void {
|
|
409
|
+
const named = namedFunctions(file);
|
|
410
|
+
const ran = new Set<Node>();
|
|
411
|
+
const run = (fn: Node, outer: ReadonlySet<string>): void => {
|
|
412
|
+
if (ran.has(fn)) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
ran.add(fn);
|
|
416
|
+
const shadowed = new Set([...outer, ...ownBindings(fn)]);
|
|
417
|
+
fn.forEachChild((child) => {
|
|
418
|
+
visit(child, shadowed);
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
const runs = (node: Node, shadowed: ReadonlySet<string>): void => {
|
|
422
|
+
const at = unwrapped(node);
|
|
423
|
+
if (isFunction(at)) {
|
|
424
|
+
run(at, shadowed);
|
|
425
|
+
} else if (isIdentifier(at) && !shadowed.has(at.text)) {
|
|
426
|
+
for (const fn of named.get(at.text) ?? []) {
|
|
427
|
+
run(fn, new Set());
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
const visit = (node: Node, shadowed: ReadonlySet<string>): void => {
|
|
432
|
+
if (isFunction(node)) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (isCallExpression(node) || isNewExpression(node)) {
|
|
436
|
+
if (isCallExpression(node)) {
|
|
437
|
+
each(node, shadowed);
|
|
438
|
+
}
|
|
439
|
+
runs(node.expression, shadowed);
|
|
440
|
+
for (const argument of node.arguments ?? []) {
|
|
441
|
+
runs(argument, shadowed);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
node.forEachChild((child) => {
|
|
445
|
+
visit(child, shadowed);
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
file.forEachChild((child) => {
|
|
449
|
+
visit(child, new Set());
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** The entries every bundler call one build script runs names, read against `dir`. */
|
|
454
|
+
function scriptEntries(file: SourceFile, dir: string, files: SourceFiles): readonly BuildEntry[] {
|
|
455
|
+
const found: BuildEntry[] = [];
|
|
456
|
+
const declared = constants(file);
|
|
457
|
+
const scriptDir = dirnamePath(file.fileName);
|
|
458
|
+
const bound = BUNDLERS.map((api) => ({ api, bindings: bindingsOf(file, api) }));
|
|
459
|
+
runCalls(file, (call, shadowed) => {
|
|
460
|
+
for (const { api, bindings } of bound) {
|
|
461
|
+
if (!builds(call.expression, api, bindings, shadowed)) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const [argument] = call.arguments;
|
|
465
|
+
let options = argument === undefined ? undefined : unwrapped(argument);
|
|
466
|
+
if (options !== undefined && isIdentifier(options)) {
|
|
467
|
+
options = shadowed.has(options.text) ? undefined : declared.get(options.text);
|
|
468
|
+
options = options === undefined ? undefined : unwrapped(options);
|
|
469
|
+
}
|
|
470
|
+
const entries = options === undefined ? undefined : member(options, api.option);
|
|
471
|
+
const base = options === undefined || api.base === "" ? undefined : member(options, api.base);
|
|
472
|
+
const against = base === undefined ? { path: dir } : pathOf(base, dir, scriptDir);
|
|
473
|
+
if (entries === undefined || against === undefined) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
for (const value of entryValues(entries)) {
|
|
477
|
+
const named = pathOf(value, against.path, scriptDir);
|
|
478
|
+
if (named === undefined) {
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
for (const entry of entriesNamed(files, api, named)) {
|
|
482
|
+
found.push({ file: entry, source: named.text });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
return found;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** The modules one manifest's scripts run, by absolute path, each below the target root. */
|
|
491
|
+
function scriptModules(host: Host, root: string, dir: string): readonly string[] {
|
|
492
|
+
let manifest: unknown;
|
|
493
|
+
try {
|
|
494
|
+
manifest = JSON.parse(host.readFile(joinPath(dir, MANIFEST)));
|
|
495
|
+
} catch {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
const scripts = isRecord(manifest) ? manifest["scripts"] : undefined;
|
|
499
|
+
if (!isRecord(scripts)) {
|
|
500
|
+
return [];
|
|
501
|
+
}
|
|
502
|
+
const found = new Set<string>();
|
|
503
|
+
for (const command of Object.values(scripts)) {
|
|
504
|
+
if (typeof command !== "string") {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
for (const token of scriptTokens(command)) {
|
|
508
|
+
const path = resolvePath(dir, token);
|
|
509
|
+
if (
|
|
510
|
+
MODULE_EXTENSION.test(path) &&
|
|
511
|
+
relativePath(root, path) !== undefined &&
|
|
512
|
+
!path.split("/").includes("node_modules") &&
|
|
513
|
+
host.kindOf(path) === "file"
|
|
514
|
+
) {
|
|
515
|
+
found.add(path);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return [...found].sort();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Every own file of one project a build script names as a bundler's entry: a module a
|
|
524
|
+
* script of a manifest at or above an own file runs, below the target root, read from
|
|
525
|
+
* the program where it holds the module and parsed alone otherwise, where a parser is given.
|
|
526
|
+
*/
|
|
527
|
+
export function buildScriptEntries(
|
|
528
|
+
host: Host,
|
|
529
|
+
targetRoot: string,
|
|
530
|
+
files: SourceFiles,
|
|
531
|
+
parse: ParseFile | undefined,
|
|
532
|
+
): readonly BuildEntry[] {
|
|
533
|
+
const root = resolvePath(host.workingDirectory(), targetRoot);
|
|
534
|
+
const dirs = new Set<string>([root]);
|
|
535
|
+
for (const file of files.byName.values()) {
|
|
536
|
+
for (
|
|
537
|
+
let dir = dirnamePath(file.fileName);
|
|
538
|
+
relativePath(root, dir) !== undefined && !dirs.has(dir);
|
|
539
|
+
dir = dirnamePath(dir)
|
|
540
|
+
) {
|
|
541
|
+
dirs.add(dir);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const found: BuildEntry[] = [];
|
|
545
|
+
for (const dir of [...dirs].sort()) {
|
|
546
|
+
if (host.kindOf(joinPath(dir, MANIFEST)) !== "file") {
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
for (const path of scriptModules(host, root, dir)) {
|
|
550
|
+
let script = files.byName.get(path);
|
|
551
|
+
if (script === undefined && parse !== undefined) {
|
|
552
|
+
try {
|
|
553
|
+
script = parse(path, host.readFile(path));
|
|
554
|
+
} catch {
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (script !== undefined) {
|
|
559
|
+
found.push(...scriptEntries(script, dir, files));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return found;
|
|
564
|
+
}
|
|
@@ -4,7 +4,7 @@ export const RECORD = {
|
|
|
4
4
|
conformance: {
|
|
5
5
|
corpusVersion: "6.0.0",
|
|
6
6
|
result: "pass",
|
|
7
|
-
digest: "sha256:
|
|
7
|
+
digest: "sha256:54d3de663b7867df0d50251bf79c3b3d1f023abd178fb477cf0bcd3a01ceb2e5",
|
|
8
8
|
},
|
|
9
9
|
gaps: [],
|
|
10
10
|
} as const;
|
package/src/convention-rows.ts
CHANGED
|
@@ -146,8 +146,8 @@ const SCRIPT = "{js,jsx,ts,tsx}";
|
|
|
146
146
|
const MODULE = "{js,mjs,ts,mts}";
|
|
147
147
|
const ANY_MODULE = "{js,mjs,cjs,ts,mts,cts}";
|
|
148
148
|
const VITE_CONFIG = `vite.config.${ANY_MODULE}`;
|
|
149
|
-
/** The legacy configuration files of ESLint
|
|
150
|
-
const ESLINTRC = [".eslintrc", ".eslintrc.json", ".eslintrc.{js,cjs}"];
|
|
149
|
+
/** The legacy configuration files of ESLint: JSON, YAML or a CommonJS module. */
|
|
150
|
+
const ESLINTRC = [".eslintrc", ".eslintrc.json", ".eslintrc.{yml,yaml}", ".eslintrc.{js,cjs}"];
|
|
151
151
|
|
|
152
152
|
const SVELTEKIT_ROUTE_FILES = "+{page,layout,server,page.server,layout.server,error}";
|
|
153
153
|
|
|
@@ -209,6 +209,60 @@ const ANGULAR_PACKAGE_KEYS: readonly PackageKey[] = [
|
|
|
209
209
|
"scripts",
|
|
210
210
|
].map((key) => ({ key, files: ["angular.json"] }));
|
|
211
211
|
|
|
212
|
+
/**
|
|
213
|
+
* The row of a code generator that writes its output below one directory its
|
|
214
|
+
* configuration's `property` sets, `fallback` where no configuration file sets it, so
|
|
215
|
+
* every file there is a generated file.
|
|
216
|
+
*/
|
|
217
|
+
function outputDirectoryRow(row: {
|
|
218
|
+
readonly name: string;
|
|
219
|
+
readonly package: string;
|
|
220
|
+
readonly range: string;
|
|
221
|
+
readonly files: readonly string[];
|
|
222
|
+
readonly property: string;
|
|
223
|
+
readonly fallback: string;
|
|
224
|
+
}): ConventionRow {
|
|
225
|
+
return {
|
|
226
|
+
name: row.name,
|
|
227
|
+
package: row.package,
|
|
228
|
+
range: row.range,
|
|
229
|
+
entries: [],
|
|
230
|
+
generated: ["<output>"],
|
|
231
|
+
moves: [
|
|
232
|
+
{
|
|
233
|
+
id: "output",
|
|
234
|
+
defaults: [row.fallback],
|
|
235
|
+
readings: [{ property: row.property, files: row.files }],
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The test runners and the assertion, mock and runner libraries whose import is test
|
|
243
|
+
* evidence beside each runner a row reads test files for. Each applies whether or not a
|
|
244
|
+
* manifest declares it, so none is a row.
|
|
245
|
+
*/
|
|
246
|
+
export const TEST_LIBRARIES: readonly string[] = [
|
|
247
|
+
"@jest/globals",
|
|
248
|
+
"@playwright/test",
|
|
249
|
+
"ava",
|
|
250
|
+
"chai",
|
|
251
|
+
"expect",
|
|
252
|
+
"jasmine",
|
|
253
|
+
"jest",
|
|
254
|
+
"mocha",
|
|
255
|
+
"msw",
|
|
256
|
+
"nock",
|
|
257
|
+
"node:test",
|
|
258
|
+
"sinon",
|
|
259
|
+
"tap",
|
|
260
|
+
"uvu",
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
/** The scopes every package of which is a test library. */
|
|
264
|
+
export const TEST_LIBRARY_SCOPES: readonly string[] = ["@testing-library/"];
|
|
265
|
+
|
|
212
266
|
/** Every row, ordered by name and then by range. */
|
|
213
267
|
export const CONVENTION_ROWS: readonly ConventionRow[] = [
|
|
214
268
|
{
|
|
@@ -274,6 +328,7 @@ export const CONVENTION_ROWS: readonly ConventionRow[] = [
|
|
|
274
328
|
range: ">=4.0.0 <10.0.0",
|
|
275
329
|
entries: [],
|
|
276
330
|
moves: [],
|
|
331
|
+
packageKeys: [{ key: "parser", files: ESLINTRC }],
|
|
277
332
|
prefixedNames: [
|
|
278
333
|
{ property: "plugins", files: ESLINTRC, prefix: "eslint-plugin" },
|
|
279
334
|
{ property: "extends", files: ESLINTRC, prefix: "eslint-plugin", marker: "plugin:" },
|
|
@@ -389,6 +444,14 @@ export const CONVENTION_ROWS: readonly ConventionRow[] = [
|
|
|
389
444
|
{ key: "oclif.hooks", directory: false },
|
|
390
445
|
],
|
|
391
446
|
},
|
|
447
|
+
outputDirectoryRow({
|
|
448
|
+
name: "panda",
|
|
449
|
+
package: "@pandacss/dev",
|
|
450
|
+
range: ">=0.1.0 <2.0.0",
|
|
451
|
+
files: [`panda.config.${ANY_MODULE}`],
|
|
452
|
+
property: "outdir",
|
|
453
|
+
fallback: "styled-system",
|
|
454
|
+
}),
|
|
392
455
|
{
|
|
393
456
|
name: "parcel",
|
|
394
457
|
package: "parcel",
|
|
@@ -456,6 +519,13 @@ export const CONVENTION_ROWS: readonly ConventionRow[] = [
|
|
|
456
519
|
},
|
|
457
520
|
],
|
|
458
521
|
},
|
|
522
|
+
{
|
|
523
|
+
name: "react-scripts",
|
|
524
|
+
package: "react-scripts",
|
|
525
|
+
range: ">=1.0.0 <6.0.0",
|
|
526
|
+
entries: [`src/index.${SCRIPT}`, "src/setupProxy.js", `src/setupTests.${SCRIPT}`],
|
|
527
|
+
moves: [],
|
|
528
|
+
},
|
|
459
529
|
{
|
|
460
530
|
name: "remix",
|
|
461
531
|
package: "@remix-run/dev",
|