@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,437 @@
|
|
|
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
|
+
import { isArrayBindingPattern, isArrayLiteralExpression, isArrowFunction, isAsExpression, isCallExpression, isConstructorDeclaration, isFunctionDeclaration, isFunctionExpression, isGetAccessorDeclaration, isIdentifier, isImportDeclaration, isMetaProperty, isMethodDeclaration, isNamedImports, isNamespaceImport, isNewExpression, isNoSubstitutionTemplateLiteral, isObjectBindingPattern, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isSetAccessorDeclaration, isStringLiteral, isVariableDeclaration, isVariableStatement, NodeFlags, } from "@typescript/native/ast";
|
|
8
|
+
import { filesNamedBy } from "./configuration-files.js";
|
|
9
|
+
import { globExpression } from "./glob.js";
|
|
10
|
+
import { scriptTokens } from "./manifest.js";
|
|
11
|
+
import { dirnamePath, joinPath, relativePath, resolvePath } from "./paths.js";
|
|
12
|
+
/**
|
|
13
|
+
* The bundlers whose build call names its entries: esbuild resolves `entryPoints` against
|
|
14
|
+
* `absWorkingDir` (https://esbuild.github.io/api/#working-directory), webpack `entry`
|
|
15
|
+
* against `context` (https://webpack.js.org/configuration/entry-context/), and Rollup
|
|
16
|
+
* `input` against the working directory, each the manifest's directory when its script runs.
|
|
17
|
+
*/
|
|
18
|
+
const BUNDLERS = [
|
|
19
|
+
{
|
|
20
|
+
module: "esbuild",
|
|
21
|
+
calls: ["build", "buildSync", "context"],
|
|
22
|
+
option: "entryPoints",
|
|
23
|
+
base: "absWorkingDir",
|
|
24
|
+
paths: true,
|
|
25
|
+
},
|
|
26
|
+
{ module: "webpack", calls: ["default"], option: "entry", base: "context", paths: false },
|
|
27
|
+
{ module: "rollup", calls: ["rollup", "watch"], option: "input", base: "", paths: true },
|
|
28
|
+
];
|
|
29
|
+
const MODULE_EXTENSION = /\.(?:js|mjs|cjs|ts|mts|cts)$/u;
|
|
30
|
+
const MANIFEST = "package.json";
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
/** The expression a wrapper that changes no value holds. */
|
|
35
|
+
function unwrapped(node) {
|
|
36
|
+
let at = node;
|
|
37
|
+
while (isParenthesizedExpression(at) || isAsExpression(at) || isSatisfiesExpression(at)) {
|
|
38
|
+
at = at.expression;
|
|
39
|
+
}
|
|
40
|
+
return at;
|
|
41
|
+
}
|
|
42
|
+
function literalOf(node) {
|
|
43
|
+
const at = unwrapped(node);
|
|
44
|
+
return isStringLiteral(at) || isNoSubstitutionTemplateLiteral(at) ? at.text : undefined;
|
|
45
|
+
}
|
|
46
|
+
/** Whether one call is `require(<module>)`. */
|
|
47
|
+
function requires(node, module) {
|
|
48
|
+
const at = unwrapped(node);
|
|
49
|
+
return (isCallExpression(at) &&
|
|
50
|
+
isIdentifier(at.expression) &&
|
|
51
|
+
at.expression.text === "require" &&
|
|
52
|
+
at.arguments.length === 1 &&
|
|
53
|
+
at.arguments[0] !== undefined &&
|
|
54
|
+
literalOf(at.arguments[0]) === module);
|
|
55
|
+
}
|
|
56
|
+
function bindingsOf(file, api) {
|
|
57
|
+
const functions = new Set();
|
|
58
|
+
const modules = new Set();
|
|
59
|
+
const building = (name) => api.calls.includes(name);
|
|
60
|
+
for (const statement of file.statements) {
|
|
61
|
+
if (isImportDeclaration(statement)) {
|
|
62
|
+
if (literalOf(statement.moduleSpecifier) !== api.module) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const clause = statement.importClause;
|
|
66
|
+
if (clause?.name !== undefined) {
|
|
67
|
+
(building("default") ? functions : modules).add(clause.name.text);
|
|
68
|
+
}
|
|
69
|
+
const named = clause?.namedBindings;
|
|
70
|
+
if (named !== undefined && isNamespaceImport(named)) {
|
|
71
|
+
modules.add(named.name.text);
|
|
72
|
+
}
|
|
73
|
+
else if (named !== undefined && isNamedImports(named)) {
|
|
74
|
+
for (const element of named.elements) {
|
|
75
|
+
if (building((element.propertyName ?? element.name).text)) {
|
|
76
|
+
functions.add(element.name.text);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (isVariableStatement(statement)) {
|
|
82
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
83
|
+
const { name, initializer } = declaration;
|
|
84
|
+
if (initializer === undefined || !requires(initializer, api.module)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (isIdentifier(name)) {
|
|
88
|
+
(building("default") ? functions : modules).add(name.text);
|
|
89
|
+
}
|
|
90
|
+
else if (isObjectBindingPattern(name)) {
|
|
91
|
+
for (const element of name.elements) {
|
|
92
|
+
const local = element.name;
|
|
93
|
+
const key = element.propertyName ?? local;
|
|
94
|
+
if (key !== undefined &&
|
|
95
|
+
local !== undefined &&
|
|
96
|
+
isIdentifier(key) &&
|
|
97
|
+
isIdentifier(local) &&
|
|
98
|
+
building(key.text)) {
|
|
99
|
+
functions.add(local.text);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { functions, modules };
|
|
107
|
+
}
|
|
108
|
+
/** Whether one call's callee is a building function of a bundler the file binds, `shadowed` naming none. */
|
|
109
|
+
function builds(callee, api, bindings, shadowed) {
|
|
110
|
+
const at = unwrapped(callee);
|
|
111
|
+
if (isIdentifier(at)) {
|
|
112
|
+
return bindings.functions.has(at.text) && !shadowed.has(at.text);
|
|
113
|
+
}
|
|
114
|
+
if (!isPropertyAccessExpression(at) ||
|
|
115
|
+
!isIdentifier(at.name) ||
|
|
116
|
+
!api.calls.includes(at.name.text)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const holder = unwrapped(at.expression);
|
|
120
|
+
return ((isIdentifier(holder) && bindings.modules.has(holder.text) && !shadowed.has(holder.text)) ||
|
|
121
|
+
requires(holder, api.module));
|
|
122
|
+
}
|
|
123
|
+
/** The top-level `const` initializers one file declares, by name. */
|
|
124
|
+
function constants(file) {
|
|
125
|
+
const found = new Map();
|
|
126
|
+
for (const statement of file.statements) {
|
|
127
|
+
if (isVariableStatement(statement) &&
|
|
128
|
+
(statement.declarationList.flags & NodeFlags.Const) !== 0) {
|
|
129
|
+
for (const { name, initializer } of statement.declarationList.declarations) {
|
|
130
|
+
if (isIdentifier(name) && initializer !== undefined) {
|
|
131
|
+
found.set(name.text, initializer);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return found;
|
|
137
|
+
}
|
|
138
|
+
/** The value one object literal writes for one member as `name: value`. */
|
|
139
|
+
function member(object, name) {
|
|
140
|
+
if (!isObjectLiteralExpression(object)) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
for (const property of object.properties) {
|
|
144
|
+
if (isPropertyAssignment(property) && literalOrName(property.name) === name) {
|
|
145
|
+
return property.initializer;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
function literalOrName(node) {
|
|
151
|
+
return isIdentifier(node) ? node.text : literalOf(node);
|
|
152
|
+
}
|
|
153
|
+
/** Whether one expression is the script's own directory: `__dirname` or `import.meta.dirname`. */
|
|
154
|
+
function isOwnDirectory(node) {
|
|
155
|
+
const at = unwrapped(node);
|
|
156
|
+
if (isIdentifier(at)) {
|
|
157
|
+
return at.text === "__dirname";
|
|
158
|
+
}
|
|
159
|
+
return (isPropertyAccessExpression(at) &&
|
|
160
|
+
isMetaProperty(at.expression) &&
|
|
161
|
+
isIdentifier(at.name) &&
|
|
162
|
+
at.name.text === "dirname");
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The path one entry value writes, read against `dir`: a literal, or a `resolve` or
|
|
166
|
+
* `join` call, of `path` or bound from it, whose first argument is the script's own
|
|
167
|
+
* directory and whose others are literals.
|
|
168
|
+
*/
|
|
169
|
+
function pathOf(node, dir, scriptDir) {
|
|
170
|
+
const at = unwrapped(node);
|
|
171
|
+
const text = literalOf(at);
|
|
172
|
+
if (text !== undefined) {
|
|
173
|
+
const request = !text.startsWith("./") && !text.startsWith("../") && !text.startsWith("/");
|
|
174
|
+
return { path: resolvePath(dir, text), text, request };
|
|
175
|
+
}
|
|
176
|
+
if (!isCallExpression(at)) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
const callee = unwrapped(at.expression);
|
|
180
|
+
const name = isPropertyAccessExpression(callee) ? callee.name : callee;
|
|
181
|
+
if (!isIdentifier(name) || (name.text !== "resolve" && name.text !== "join")) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
const [first, ...rest] = at.arguments;
|
|
185
|
+
const parts = rest.map(literalOf);
|
|
186
|
+
if (first === undefined || !isOwnDirectory(first) || parts.some((part) => part === undefined)) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const joined = parts.join("/");
|
|
190
|
+
return { path: resolvePath(scriptDir, joined), text: joined, request: false };
|
|
191
|
+
}
|
|
192
|
+
/** The entry values one entries option writes: a value, an array of them, an object of them. */
|
|
193
|
+
function entryValues(node) {
|
|
194
|
+
const at = unwrapped(node);
|
|
195
|
+
if (isArrayLiteralExpression(at)) {
|
|
196
|
+
return at.elements.flatMap(entryValues);
|
|
197
|
+
}
|
|
198
|
+
if (isObjectLiteralExpression(at)) {
|
|
199
|
+
const imported = member(at, "import") ?? member(at, "in");
|
|
200
|
+
if (imported !== undefined) {
|
|
201
|
+
return entryValues(imported);
|
|
202
|
+
}
|
|
203
|
+
return at.properties.flatMap((property) => isPropertyAssignment(property) ? entryValues(property.initializer) : []);
|
|
204
|
+
}
|
|
205
|
+
return [at];
|
|
206
|
+
}
|
|
207
|
+
/** The own files one entry string names, read as `api` reads it. */
|
|
208
|
+
function entriesNamed(files, api, entry) {
|
|
209
|
+
if (!api.paths && entry.request) {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
if (api.paths && /[*?[{]/u.test(entry.text)) {
|
|
213
|
+
const expression = globExpression(entry.path);
|
|
214
|
+
return [...files.byName.values()].filter((file) => expression.test(file.fileName));
|
|
215
|
+
}
|
|
216
|
+
const dir = dirnamePath(entry.path);
|
|
217
|
+
return filesNamedBy(files, dir, entry.path.slice(dir.length + 1));
|
|
218
|
+
}
|
|
219
|
+
/** Whether one node is a function, whose body runs only where something calls it. */
|
|
220
|
+
function isFunction(node) {
|
|
221
|
+
return (isFunctionDeclaration(node) ||
|
|
222
|
+
isFunctionExpression(node) ||
|
|
223
|
+
isArrowFunction(node) ||
|
|
224
|
+
isMethodDeclaration(node) ||
|
|
225
|
+
isConstructorDeclaration(node) ||
|
|
226
|
+
isGetAccessorDeclaration(node) ||
|
|
227
|
+
isSetAccessorDeclaration(node));
|
|
228
|
+
}
|
|
229
|
+
/** The names one binding name binds: an identifier, or each name a pattern holds. */
|
|
230
|
+
function boundNames(name, into) {
|
|
231
|
+
if (isIdentifier(name)) {
|
|
232
|
+
into.add(name.text);
|
|
233
|
+
}
|
|
234
|
+
else if (isObjectBindingPattern(name) || isArrayBindingPattern(name)) {
|
|
235
|
+
name.forEachChild((element) => {
|
|
236
|
+
const bound = element.name;
|
|
237
|
+
if (bound !== undefined) {
|
|
238
|
+
boundNames(bound, into);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** The names one function binds of its own: its parameters and the declarations its body holds outside nested functions. */
|
|
244
|
+
function ownBindings(fn) {
|
|
245
|
+
const found = new Set();
|
|
246
|
+
const visit = (node) => {
|
|
247
|
+
if (node !== fn && isFunction(node)) {
|
|
248
|
+
if (isFunctionDeclaration(node) && node.name !== undefined) {
|
|
249
|
+
found.add(node.name.text);
|
|
250
|
+
}
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (isVariableDeclaration(node)) {
|
|
254
|
+
boundNames(node.name, found);
|
|
255
|
+
}
|
|
256
|
+
node.forEachChild(visit);
|
|
257
|
+
};
|
|
258
|
+
for (const parameter of fn
|
|
259
|
+
.parameters ?? []) {
|
|
260
|
+
boundNames(parameter.name, found);
|
|
261
|
+
}
|
|
262
|
+
fn.forEachChild(visit);
|
|
263
|
+
return found;
|
|
264
|
+
}
|
|
265
|
+
/** The functions one file declares under a name: a function declaration, or a variable bound to a function. */
|
|
266
|
+
function namedFunctions(file) {
|
|
267
|
+
const found = new Map();
|
|
268
|
+
const add = (name, fn) => {
|
|
269
|
+
found.set(name, [...(found.get(name) ?? []), fn]);
|
|
270
|
+
};
|
|
271
|
+
const visit = (node) => {
|
|
272
|
+
if (isFunctionDeclaration(node) && node.name !== undefined) {
|
|
273
|
+
add(node.name.text, node);
|
|
274
|
+
}
|
|
275
|
+
else if (isVariableDeclaration(node) &&
|
|
276
|
+
isIdentifier(node.name) &&
|
|
277
|
+
node.initializer !== undefined &&
|
|
278
|
+
isFunction(unwrapped(node.initializer))) {
|
|
279
|
+
add(node.name.text, unwrapped(node.initializer));
|
|
280
|
+
}
|
|
281
|
+
node.forEachChild(visit);
|
|
282
|
+
};
|
|
283
|
+
file.forEachChild(visit);
|
|
284
|
+
return found;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The calls one build script runs: those of its top level, and those of each function
|
|
288
|
+
* a call it runs calls or passes on, as a callee, an argument or a function called where
|
|
289
|
+
* it is written. `shadowed` is the names a function running them binds of its own, which
|
|
290
|
+
* hide the file's bindings of the same names.
|
|
291
|
+
*/
|
|
292
|
+
function runCalls(file, each) {
|
|
293
|
+
const named = namedFunctions(file);
|
|
294
|
+
const ran = new Set();
|
|
295
|
+
const run = (fn, outer) => {
|
|
296
|
+
if (ran.has(fn)) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
ran.add(fn);
|
|
300
|
+
const shadowed = new Set([...outer, ...ownBindings(fn)]);
|
|
301
|
+
fn.forEachChild((child) => {
|
|
302
|
+
visit(child, shadowed);
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
const runs = (node, shadowed) => {
|
|
306
|
+
const at = unwrapped(node);
|
|
307
|
+
if (isFunction(at)) {
|
|
308
|
+
run(at, shadowed);
|
|
309
|
+
}
|
|
310
|
+
else if (isIdentifier(at) && !shadowed.has(at.text)) {
|
|
311
|
+
for (const fn of named.get(at.text) ?? []) {
|
|
312
|
+
run(fn, new Set());
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const visit = (node, shadowed) => {
|
|
317
|
+
if (isFunction(node)) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (isCallExpression(node) || isNewExpression(node)) {
|
|
321
|
+
if (isCallExpression(node)) {
|
|
322
|
+
each(node, shadowed);
|
|
323
|
+
}
|
|
324
|
+
runs(node.expression, shadowed);
|
|
325
|
+
for (const argument of node.arguments ?? []) {
|
|
326
|
+
runs(argument, shadowed);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
node.forEachChild((child) => {
|
|
330
|
+
visit(child, shadowed);
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
file.forEachChild((child) => {
|
|
334
|
+
visit(child, new Set());
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/** The entries every bundler call one build script runs names, read against `dir`. */
|
|
338
|
+
function scriptEntries(file, dir, files) {
|
|
339
|
+
const found = [];
|
|
340
|
+
const declared = constants(file);
|
|
341
|
+
const scriptDir = dirnamePath(file.fileName);
|
|
342
|
+
const bound = BUNDLERS.map((api) => ({ api, bindings: bindingsOf(file, api) }));
|
|
343
|
+
runCalls(file, (call, shadowed) => {
|
|
344
|
+
for (const { api, bindings } of bound) {
|
|
345
|
+
if (!builds(call.expression, api, bindings, shadowed)) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const [argument] = call.arguments;
|
|
349
|
+
let options = argument === undefined ? undefined : unwrapped(argument);
|
|
350
|
+
if (options !== undefined && isIdentifier(options)) {
|
|
351
|
+
options = shadowed.has(options.text) ? undefined : declared.get(options.text);
|
|
352
|
+
options = options === undefined ? undefined : unwrapped(options);
|
|
353
|
+
}
|
|
354
|
+
const entries = options === undefined ? undefined : member(options, api.option);
|
|
355
|
+
const base = options === undefined || api.base === "" ? undefined : member(options, api.base);
|
|
356
|
+
const against = base === undefined ? { path: dir } : pathOf(base, dir, scriptDir);
|
|
357
|
+
if (entries === undefined || against === undefined) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
for (const value of entryValues(entries)) {
|
|
361
|
+
const named = pathOf(value, against.path, scriptDir);
|
|
362
|
+
if (named === undefined) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
for (const entry of entriesNamed(files, api, named)) {
|
|
366
|
+
found.push({ file: entry, source: named.text });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
return found;
|
|
372
|
+
}
|
|
373
|
+
/** The modules one manifest's scripts run, by absolute path, each below the target root. */
|
|
374
|
+
function scriptModules(host, root, dir) {
|
|
375
|
+
let manifest;
|
|
376
|
+
try {
|
|
377
|
+
manifest = JSON.parse(host.readFile(joinPath(dir, MANIFEST)));
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
const scripts = isRecord(manifest) ? manifest["scripts"] : undefined;
|
|
383
|
+
if (!isRecord(scripts)) {
|
|
384
|
+
return [];
|
|
385
|
+
}
|
|
386
|
+
const found = new Set();
|
|
387
|
+
for (const command of Object.values(scripts)) {
|
|
388
|
+
if (typeof command !== "string") {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
for (const token of scriptTokens(command)) {
|
|
392
|
+
const path = resolvePath(dir, token);
|
|
393
|
+
if (MODULE_EXTENSION.test(path) &&
|
|
394
|
+
relativePath(root, path) !== undefined &&
|
|
395
|
+
!path.split("/").includes("node_modules") &&
|
|
396
|
+
host.kindOf(path) === "file") {
|
|
397
|
+
found.add(path);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return [...found].sort();
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Every own file of one project a build script names as a bundler's entry: a module a
|
|
405
|
+
* script of a manifest at or above an own file runs, below the target root, read from
|
|
406
|
+
* the program where it holds the module and parsed alone otherwise, where a parser is given.
|
|
407
|
+
*/
|
|
408
|
+
export function buildScriptEntries(host, targetRoot, files, parse) {
|
|
409
|
+
const root = resolvePath(host.workingDirectory(), targetRoot);
|
|
410
|
+
const dirs = new Set([root]);
|
|
411
|
+
for (const file of files.byName.values()) {
|
|
412
|
+
for (let dir = dirnamePath(file.fileName); relativePath(root, dir) !== undefined && !dirs.has(dir); dir = dirnamePath(dir)) {
|
|
413
|
+
dirs.add(dir);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const found = [];
|
|
417
|
+
for (const dir of [...dirs].sort()) {
|
|
418
|
+
if (host.kindOf(joinPath(dir, MANIFEST)) !== "file") {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
for (const path of scriptModules(host, root, dir)) {
|
|
422
|
+
let script = files.byName.get(path);
|
|
423
|
+
if (script === undefined && parse !== undefined) {
|
|
424
|
+
try {
|
|
425
|
+
script = parse(path, host.readFile(path));
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (script !== undefined) {
|
|
432
|
+
found.push(...scriptEntries(script, dir, files));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return found;
|
|
437
|
+
}
|
|
@@ -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
|
};
|
|
@@ -10,8 +10,8 @@ const SCRIPT = "{js,jsx,ts,tsx}";
|
|
|
10
10
|
const MODULE = "{js,mjs,ts,mts}";
|
|
11
11
|
const ANY_MODULE = "{js,mjs,cjs,ts,mts,cts}";
|
|
12
12
|
const VITE_CONFIG = `vite.config.${ANY_MODULE}`;
|
|
13
|
-
/** The legacy configuration files of ESLint
|
|
14
|
-
const ESLINTRC = [".eslintrc", ".eslintrc.json", ".eslintrc.{js,cjs}"];
|
|
13
|
+
/** The legacy configuration files of ESLint: JSON, YAML or a CommonJS module. */
|
|
14
|
+
const ESLINTRC = [".eslintrc", ".eslintrc.json", ".eslintrc.{yml,yaml}", ".eslintrc.{js,cjs}"];
|
|
15
15
|
const SVELTEKIT_ROUTE_FILES = "+{page,layout,server,page.server,layout.server,error}";
|
|
16
16
|
/** SvelteKit's entries other than its parameter matchers. */
|
|
17
17
|
const SVELTEKIT_ENTRIES = [
|
|
@@ -61,6 +61,50 @@ const ANGULAR_PACKAGE_KEYS = [
|
|
|
61
61
|
"styles",
|
|
62
62
|
"scripts",
|
|
63
63
|
].map((key) => ({ key, files: ["angular.json"] }));
|
|
64
|
+
/**
|
|
65
|
+
* The row of a code generator that writes its output below one directory its
|
|
66
|
+
* configuration's `property` sets, `fallback` where no configuration file sets it, so
|
|
67
|
+
* every file there is a generated file.
|
|
68
|
+
*/
|
|
69
|
+
function outputDirectoryRow(row) {
|
|
70
|
+
return {
|
|
71
|
+
name: row.name,
|
|
72
|
+
package: row.package,
|
|
73
|
+
range: row.range,
|
|
74
|
+
entries: [],
|
|
75
|
+
generated: ["<output>"],
|
|
76
|
+
moves: [
|
|
77
|
+
{
|
|
78
|
+
id: "output",
|
|
79
|
+
defaults: [row.fallback],
|
|
80
|
+
readings: [{ property: row.property, files: row.files }],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The test runners and the assertion, mock and runner libraries whose import is test
|
|
87
|
+
* evidence beside each runner a row reads test files for. Each applies whether or not a
|
|
88
|
+
* manifest declares it, so none is a row.
|
|
89
|
+
*/
|
|
90
|
+
export const TEST_LIBRARIES = [
|
|
91
|
+
"@jest/globals",
|
|
92
|
+
"@playwright/test",
|
|
93
|
+
"ava",
|
|
94
|
+
"chai",
|
|
95
|
+
"expect",
|
|
96
|
+
"jasmine",
|
|
97
|
+
"jest",
|
|
98
|
+
"mocha",
|
|
99
|
+
"msw",
|
|
100
|
+
"nock",
|
|
101
|
+
"node:test",
|
|
102
|
+
"sinon",
|
|
103
|
+
"tap",
|
|
104
|
+
"uvu",
|
|
105
|
+
];
|
|
106
|
+
/** The scopes every package of which is a test library. */
|
|
107
|
+
export const TEST_LIBRARY_SCOPES = ["@testing-library/"];
|
|
64
108
|
/** Every row, ordered by name and then by range. */
|
|
65
109
|
export const CONVENTION_ROWS = [
|
|
66
110
|
{
|
|
@@ -126,6 +170,7 @@ export const CONVENTION_ROWS = [
|
|
|
126
170
|
range: ">=4.0.0 <10.0.0",
|
|
127
171
|
entries: [],
|
|
128
172
|
moves: [],
|
|
173
|
+
packageKeys: [{ key: "parser", files: ESLINTRC }],
|
|
129
174
|
prefixedNames: [
|
|
130
175
|
{ property: "plugins", files: ESLINTRC, prefix: "eslint-plugin" },
|
|
131
176
|
{ property: "extends", files: ESLINTRC, prefix: "eslint-plugin", marker: "plugin:" },
|
|
@@ -241,6 +286,14 @@ export const CONVENTION_ROWS = [
|
|
|
241
286
|
{ key: "oclif.hooks", directory: false },
|
|
242
287
|
],
|
|
243
288
|
},
|
|
289
|
+
outputDirectoryRow({
|
|
290
|
+
name: "panda",
|
|
291
|
+
package: "@pandacss/dev",
|
|
292
|
+
range: ">=0.1.0 <2.0.0",
|
|
293
|
+
files: [`panda.config.${ANY_MODULE}`],
|
|
294
|
+
property: "outdir",
|
|
295
|
+
fallback: "styled-system",
|
|
296
|
+
}),
|
|
244
297
|
{
|
|
245
298
|
name: "parcel",
|
|
246
299
|
package: "parcel",
|
|
@@ -308,6 +361,13 @@ export const CONVENTION_ROWS = [
|
|
|
308
361
|
},
|
|
309
362
|
],
|
|
310
363
|
},
|
|
364
|
+
{
|
|
365
|
+
name: "react-scripts",
|
|
366
|
+
package: "react-scripts",
|
|
367
|
+
range: ">=1.0.0 <6.0.0",
|
|
368
|
+
entries: [`src/index.${SCRIPT}`, "src/setupProxy.js", `src/setupTests.${SCRIPT}`],
|
|
369
|
+
moves: [],
|
|
370
|
+
},
|
|
311
371
|
{
|
|
312
372
|
name: "remix",
|
|
313
373
|
package: "@remix-run/dev",
|
package/dist/src/conventions.js
CHANGED
|
@@ -12,7 +12,14 @@ import { documentStrings } from "./configuration-files.js";
|
|
|
12
12
|
import { globExpression } from "./glob.js";
|
|
13
13
|
import { dirnamePath, joinPath, normalizePath, relativePath, resolvePath } from "./paths.js";
|
|
14
14
|
import { satisfies } from "./version-range.js";
|
|
15
|
+
import { yamlDocument } from "./yaml-document.js";
|
|
15
16
|
const JSON_EXTENSION = ".json";
|
|
17
|
+
/**
|
|
18
|
+
* A configuration file its tool reads as a YAML document, read as the JSON document it
|
|
19
|
+
* denotes. Its nodes' offsets are that JSON text's, so no move may read one: a failure's
|
|
20
|
+
* line would name the wrong line.
|
|
21
|
+
*/
|
|
22
|
+
const YAML_NAME = /\.ya?ml$/u;
|
|
16
23
|
/** A configuration file with no extension that its tool reads as a JSON document. */
|
|
17
24
|
const JSON_RC = /^\.[\w-]+rc$/u;
|
|
18
25
|
/** The sections an installed package is required by, so its absence fails the run. */
|
|
@@ -614,6 +621,14 @@ function readingFiles(host, parse, dir, files) {
|
|
|
614
621
|
catch {
|
|
615
622
|
continue;
|
|
616
623
|
}
|
|
624
|
+
if (YAML_NAME.test(name)) {
|
|
625
|
+
const value = yamlDocument(text);
|
|
626
|
+
if (value !== undefined) {
|
|
627
|
+
const json = JSON.stringify(value);
|
|
628
|
+
found.push({ name, text: json, file: parse(`${path}${JSON_EXTENSION}`, json) });
|
|
629
|
+
}
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
617
632
|
found.push({
|
|
618
633
|
name,
|
|
619
634
|
text,
|
package/dist/src/dependencies.js
CHANGED
|
@@ -664,6 +664,91 @@ function scriptTokensOf(manifest) {
|
|
|
664
664
|
}
|
|
665
665
|
return found;
|
|
666
666
|
}
|
|
667
|
+
/**
|
|
668
|
+
* The runtime flags whose value is a module loaded before the entry, as `--flag value` or
|
|
669
|
+
* `--flag=value`: https://nodejs.org/api/cli.html#--importmodule,
|
|
670
|
+
* https://nodejs.org/api/cli.html#--experimental-loadermodule,
|
|
671
|
+
* https://nodejs.org/api/cli.html#-r---require-module
|
|
672
|
+
*/
|
|
673
|
+
const PRELOAD_FLAGS = new Set([
|
|
674
|
+
"--experimental-loader",
|
|
675
|
+
"--import",
|
|
676
|
+
"--loader",
|
|
677
|
+
"--require",
|
|
678
|
+
"-r",
|
|
679
|
+
]);
|
|
680
|
+
/**
|
|
681
|
+
* The programs that pass a preload flag to the runtime they start: Node itself, and the
|
|
682
|
+
* runners that forward Node's flags or read the same `--require`:
|
|
683
|
+
* https://mochajs.org/#-require-module-r-module, https://tsx.is/node-enhancement,
|
|
684
|
+
* https://typestrong.org/ts-node/docs/options#require,
|
|
685
|
+
* https://github.com/remy/nodemon#running-non-node-scripts
|
|
686
|
+
*/
|
|
687
|
+
const PRELOADING_PROGRAMS = new Set([
|
|
688
|
+
"mocha",
|
|
689
|
+
"node",
|
|
690
|
+
"nodemon",
|
|
691
|
+
"ts-node",
|
|
692
|
+
"tsx",
|
|
693
|
+
]);
|
|
694
|
+
/** The programs that run the command after them, and an environment assignment before it. */
|
|
695
|
+
const LAUNCHERS = new Set(["cross-env", "env", "npx"]);
|
|
696
|
+
const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/u;
|
|
697
|
+
/** The commands one script string runs, split at the shell's list and pipeline operators. */
|
|
698
|
+
const COMMAND_SEPARATORS = /&&|\|\||;|\||&/u;
|
|
699
|
+
/**
|
|
700
|
+
* The packages one manifest's scripts preload by a runtime flag's bare module specifier,
|
|
701
|
+
* a flag counting only in a command whose program passes it to the runtime, and for Node
|
|
702
|
+
* only before the script it runs, whose own arguments come after it.
|
|
703
|
+
*/
|
|
704
|
+
function scriptPreloadsOf(manifest) {
|
|
705
|
+
const scripts = manifest["scripts"];
|
|
706
|
+
const found = new Set();
|
|
707
|
+
if (!isRecord(scripts)) {
|
|
708
|
+
return found;
|
|
709
|
+
}
|
|
710
|
+
for (const script of Object.values(scripts)) {
|
|
711
|
+
if (typeof script !== "string") {
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
for (const command of script.split(COMMAND_SEPARATORS)) {
|
|
715
|
+
const tokens = scriptTokens(command);
|
|
716
|
+
let at = 0;
|
|
717
|
+
while (at < tokens.length &&
|
|
718
|
+
(ASSIGNMENT.test(tokens[at] ?? "") || LAUNCHERS.has(tokens[at] ?? ""))) {
|
|
719
|
+
at += 1;
|
|
720
|
+
}
|
|
721
|
+
const path = tokens[at] ?? "";
|
|
722
|
+
const program = path.slice(path.lastIndexOf("/") + 1);
|
|
723
|
+
if (!PRELOADING_PROGRAMS.has(program)) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
for (at += 1; at < tokens.length; at += 1) {
|
|
727
|
+
const token = tokens[at] ?? "";
|
|
728
|
+
if (!token.startsWith("-")) {
|
|
729
|
+
if (program === "node") {
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
const equals = token.indexOf("=");
|
|
735
|
+
const flag = equals < 0 ? token : token.slice(0, equals);
|
|
736
|
+
if (!PRELOAD_FLAGS.has(flag)) {
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
if (equals < 0) {
|
|
740
|
+
at += 1;
|
|
741
|
+
}
|
|
742
|
+
const value = equals < 0 ? tokens[at] : token.slice(equals + 1);
|
|
743
|
+
const name = value === undefined ? undefined : packageOfSpecifier(value);
|
|
744
|
+
if (name !== undefined) {
|
|
745
|
+
found.add(name);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return found;
|
|
751
|
+
}
|
|
667
752
|
/** Whether a path below the target root lies in the directory `dir` below it, `""` being the root. */
|
|
668
753
|
function isInside(path, dir) {
|
|
669
754
|
return dir === "" || path.startsWith(`${dir}/`);
|
|
@@ -745,12 +830,16 @@ export function dependenciesOf(host, targetRoot, perProject, candidates, members
|
|
|
745
830
|
continue;
|
|
746
831
|
}
|
|
747
832
|
const tokens = scriptTokensOf(read.value);
|
|
833
|
+
const preloads = scriptPreloadsOf(read.value);
|
|
748
834
|
for (const dependency of declaredIn(read.text, read.value, path, scopeOf(path))) {
|
|
749
835
|
const found = installedOf(host, dir, dependency.name);
|
|
750
836
|
if (found === undefined && uninstalledHere.has(dir)) {
|
|
751
837
|
continue;
|
|
752
838
|
}
|
|
753
839
|
declared.push(dependency);
|
|
840
|
+
if (preloads.has(dependency.name)) {
|
|
841
|
+
ran.add(declarationKey(dependency));
|
|
842
|
+
}
|
|
754
843
|
if (found === undefined) {
|
|
755
844
|
continue;
|
|
756
845
|
}
|