@cplieger/deadset-ts 8.0.0-dev.2 → 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 +27 -5
- package/dist/src/augmentations.js +62 -0
- package/dist/src/build-scripts.js +437 -0
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/convention-rows.js +39 -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 +62 -26
- 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 +4 -1
- package/dist/src/graph.js +5 -3
- package/dist/src/intra-function-parts.js +45 -17
- package/dist/src/kinds.js +7 -7
- package/dist/src/manifest.js +18 -0
- package/dist/src/matrix.js +38 -4
- 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/sweep.js +7 -9
- package/dist/src/test-globals.js +234 -0
- 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 +45 -7
- package/src/augmentations.ts +76 -1
- package/src/build-scripts.ts +564 -0
- package/src/conformance-record.ts +1 -1
- package/src/convention-rows.ts +47 -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/findings/completion.ts +72 -28
- package/src/findings/intra-function.ts +4 -2
- package/src/findings/reads-and-writes.ts +7 -6
- package/src/findings/unused-declarations.ts +6 -1
- package/src/graph.ts +5 -3
- package/src/intra-function-parts.ts +55 -16
- package/src/kinds.ts +7 -7
- package/src/manifest.ts +21 -3
- package/src/matrix.ts +51 -4
- 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/sweep.ts +21 -9
- package/src/test-globals.ts +275 -0
- 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
package/dist/src/analysis.js
CHANGED
|
@@ -43,7 +43,10 @@ import { references, testFileRulesOf } from "./references.js";
|
|
|
43
43
|
import { roots, unmatchedEverywhere, } from "./roots.js";
|
|
44
44
|
import { serializationContract } from "./serialization-contract.js";
|
|
45
45
|
import { outsideTestReferences, testFilesAt } from "./outside-tests.js";
|
|
46
|
+
import { mergedGlobalInterfaces } from "./augmentations.js";
|
|
47
|
+
import { unseenLoadsOf } from "./unseen-loads.js";
|
|
46
48
|
import { joinedTestFiles, withJoinedTests } from "./test-joins.js";
|
|
49
|
+
import { GLOBALS_RUNNER, namesTestGlobals, withTestGlobals } from "./test-globals.js";
|
|
47
50
|
import { supportReferences, testSupportFiles } from "./test-support.js";
|
|
48
51
|
import { diagnosticsOf, ownedAs, runSession, } from "./session.js";
|
|
49
52
|
import { accessorsOf, storesOf } from "./stores.js";
|
|
@@ -195,7 +198,7 @@ function readProjects(engine, host, scope, config, stage) {
|
|
|
195
198
|
const joins = discovered.derived
|
|
196
199
|
? joinedTestFiles(engine, host, absoluteRoot, discovered.configFiles, testPatterns)
|
|
197
200
|
: new Map();
|
|
198
|
-
const programs = withBaseUrlPaths(engine, host, [...discovered.configFiles, ...consumerOf.keys()], workspace?.programs ?? new Map());
|
|
201
|
+
const programs = withTestGlobals(engine, host, parse, discovered.configFiles, withBaseUrlPaths(engine, host, [...discovered.configFiles, ...consumerOf.keys()], workspace?.programs ?? new Map()));
|
|
199
202
|
const session = runSession(engine, [...discovered.configFiles, ...consumerOf.keys()], (opened) => {
|
|
200
203
|
const consumer = consumerOf.get(opened.configFile);
|
|
201
204
|
const setup = consumer === undefined ? workspace?.unbuildable(opened.configFile) : undefined;
|
|
@@ -499,6 +502,9 @@ function readRun(engine, host, scope, config, mode, detectors, extra) {
|
|
|
499
502
|
: { generated: projectRead.generated }),
|
|
500
503
|
}, detectors, disabled);
|
|
501
504
|
const components = project.ownSourceFiles().filter(isComponentFile);
|
|
505
|
+
const injected = project.program
|
|
506
|
+
.getSourceFileNames()
|
|
507
|
+
.some((name) => name.endsWith(`/node_modules/${GLOBALS_RUNNER}/globals.d.ts`));
|
|
502
508
|
const pathOf = (file) => relativePath(targetRoot, file.fileName) ?? file.fileName;
|
|
503
509
|
return {
|
|
504
510
|
projectRead,
|
|
@@ -506,11 +512,22 @@ function readRun(engine, host, scope, config, mode, detectors, extra) {
|
|
|
506
512
|
testFiles: resolved.testFilePaths,
|
|
507
513
|
evidence,
|
|
508
514
|
componentFiles: components.map(pathOf),
|
|
515
|
+
augmented: mergedGlobalInterfaces(project, projectRead.held, sourceFilesOf(project, targetRoot)).map((id) => ({ id, kind: "global-augmentation", source: "" })),
|
|
509
516
|
imports: new Map(project.ownSourceFiles().flatMap((file) => {
|
|
510
517
|
const path = relativePath(targetRoot, file.fileName);
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
518
|
+
if (path === undefined) {
|
|
519
|
+
return [];
|
|
520
|
+
}
|
|
521
|
+
const specifiers = file.imports.filter(isStringLiteralLikeNode).map((one) => one.text);
|
|
522
|
+
// A file calling the globals a program declares is written for their runner.
|
|
523
|
+
return [
|
|
524
|
+
[
|
|
525
|
+
path,
|
|
526
|
+
injected && namesTestGlobals(project, file)
|
|
527
|
+
? [...specifiers, GLOBALS_RUNNER]
|
|
528
|
+
: specifiers,
|
|
529
|
+
],
|
|
530
|
+
];
|
|
514
531
|
})),
|
|
515
532
|
componentWarnings: components.flatMap((file) => readComponent(file.originalText, extensionOf(file.fileName)).warnings.map((warning) => ({
|
|
516
533
|
path: pathOf(file),
|
|
@@ -549,7 +566,9 @@ function readRun(engine, host, scope, config, mode, detectors, extra) {
|
|
|
549
566
|
configuration: projectRead.configuration,
|
|
550
567
|
symbols: projectRead.held.symbols,
|
|
551
568
|
references: [...made, ...evidenceReferences(projectRead.held.symbols, detected.inTestFiles)],
|
|
552
|
-
|
|
569
|
+
// The augmentations are rooted after test support is read: an outside declaration
|
|
570
|
+
// naming one calls nothing of its file.
|
|
571
|
+
roots: [...projectRead.rooted.liveUnderReachability, ...one.augmented],
|
|
553
572
|
testFiles: [...one.testFiles, ...supportFiles],
|
|
554
573
|
...(supportFiles.length === 0 ? {} : { supportFiles }),
|
|
555
574
|
...(testUsedFiles.length === 0 ? {} : { testUsedFiles }),
|
|
@@ -761,6 +780,7 @@ export function readEmitterRun(engine, host, scope, config, mode, detectors) {
|
|
|
761
780
|
directives: inlineDirectives(project, read.held, targetRoot).filter((directive) => !read.referenceOnly.includes(directive.site.path)),
|
|
762
781
|
declarationsNamed: declarationsNamed(project, read.held, configuredDeclarations(config)),
|
|
763
782
|
parts: projectParts(project, read.held, references, targetRoot),
|
|
783
|
+
unseenLoads: unseenLoadsOf(project, read.configuration, targetRoot, testFiles),
|
|
764
784
|
}));
|
|
765
785
|
// Whether a declaration carries the marker decides its code, so one whose marker went
|
|
766
786
|
// unread is reported by nothing.
|
|
@@ -836,6 +856,7 @@ export function emitterInputOver(host, scope, config, read, input, selfCheck) {
|
|
|
836
856
|
heldByInclusion: new Set(projects.flatMap((one) => one.extra.heldByInclusion)),
|
|
837
857
|
generated: new Set(projects.flatMap((one) => one.extra.generated)),
|
|
838
858
|
inOperands: new Set(projects.flatMap((one) => one.extra.inOperands)),
|
|
859
|
+
unseenLoads: projects.flatMap((one) => one.extra.unseenLoads),
|
|
839
860
|
},
|
|
840
861
|
boundary: {
|
|
841
862
|
consumers: {
|
|
@@ -886,6 +907,7 @@ function readAnalysis(engine, host, scope, config, provenance, mode, detectors)
|
|
|
886
907
|
librariesUnfound: read.librariesUnfound,
|
|
887
908
|
conventionsApplied: read.conventionsApplied,
|
|
888
909
|
unmappedEntries: unmappedEverywhere(read.projects),
|
|
910
|
+
unseenLoads: read.projects.flatMap((one) => one.extra.unseenLoads),
|
|
889
911
|
},
|
|
890
912
|
configured: read.projects.map((one) => one.configured),
|
|
891
913
|
symbols,
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* name, which the language or a library types values by where the target never names it,
|
|
7
7
|
* as `import.meta` or `process.env`, so a use of its member is a use of it.
|
|
8
8
|
*/
|
|
9
|
+
import { isInterfaceDeclaration, isModuleBlock, isModuleDeclaration, } from "@typescript/native/ast";
|
|
10
|
+
import { nodeKey } from "./inventory.js";
|
|
9
11
|
import { referenceKey } from "./matrix.js";
|
|
10
12
|
/** Whether one declaration is a `declare global` block: a module-level namespace named `global`. */
|
|
11
13
|
function isGlobalBlock(symbol, held, files) {
|
|
@@ -54,6 +56,66 @@ export function ambientGlobalInterfaces(held, interfaces, scripts) {
|
|
|
54
56
|
? []
|
|
55
57
|
: interfaces.filter((id) => held.ambient.has(id) && holders(id).global);
|
|
56
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Each ambient global interface of the project's own files that merges into an interface
|
|
61
|
+
* declared outside them, with every interface, namespace and block between it and the
|
|
62
|
+
* global scope: the outside declaration names it wherever a value is typed by it. Where
|
|
63
|
+
* every outside declaration is a package's, not the compiler's library, and declares no
|
|
64
|
+
* member, each member it declares as well: such an interface is a slot the package reads
|
|
65
|
+
* by type, as `keyof` does, in declarations the analysis does not walk.
|
|
66
|
+
*/
|
|
67
|
+
export function mergedGlobalInterfaces(project, held, files) {
|
|
68
|
+
const scripts = new Set();
|
|
69
|
+
const names = new Map();
|
|
70
|
+
for (const file of files.byName.values()) {
|
|
71
|
+
const fileId = held.declarations.get(nodeKey(file, file));
|
|
72
|
+
if (fileId !== undefined && file.externalModuleIndicator === undefined) {
|
|
73
|
+
scripts.add(fileId);
|
|
74
|
+
}
|
|
75
|
+
const visit = (node) => {
|
|
76
|
+
if (isInterfaceDeclaration(node)) {
|
|
77
|
+
const id = held.declarations.get(nodeKey(file, node));
|
|
78
|
+
if (id !== undefined) {
|
|
79
|
+
names.set(id, node.name);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (isModuleDeclaration(node) || isModuleBlock(node)) {
|
|
83
|
+
node.forEachChild(visit);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
file.forEachChild(visit);
|
|
87
|
+
}
|
|
88
|
+
const global = new Set(ambientGlobalInterfaces(held, [...names.keys()], scripts));
|
|
89
|
+
const asked = [...names].filter(([id]) => global.has(id));
|
|
90
|
+
if (asked.length === 0) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const answers = project.symbolsAt(asked.map(([, name]) => project.handle(name)));
|
|
94
|
+
const holders = holdersOf(held, scripts);
|
|
95
|
+
const empty = (handle) => {
|
|
96
|
+
if (project.program.getSourceFileMetadata(handle.path)?.isDefaultLibrary === true) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const node = project.declarationAt(handle)?.node;
|
|
100
|
+
return node !== undefined && isInterfaceDeclaration(node) && node.members.length === 0;
|
|
101
|
+
};
|
|
102
|
+
return [
|
|
103
|
+
...new Set(asked.flatMap(([id], at) => {
|
|
104
|
+
const symbol = answers[at];
|
|
105
|
+
if (typeof symbol !== "object") {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const outside = symbol.declarations.filter((handle) => !files.byName.has(handle.path));
|
|
109
|
+
if (outside.length === 0) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const members = outside.every(empty)
|
|
113
|
+
? held.symbols.filter((one) => one.parent === id).map((one) => one.id)
|
|
114
|
+
: [];
|
|
115
|
+
return [id, ...(holders?.(id).ids ?? []), ...members];
|
|
116
|
+
})),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
57
119
|
/**
|
|
58
120
|
* For each reference to a declaration an augmentation block, or the global scope of a
|
|
59
121
|
* file in `scripts` (the files that are no module), holds, a read at the same place of
|
|
@@ -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,27 @@ 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
|
+
}
|
|
64
85
|
/**
|
|
65
86
|
* The test runners and the assertion, mock and runner libraries whose import is test
|
|
66
87
|
* evidence beside each runner a row reads test files for. Each applies whether or not a
|
|
@@ -149,6 +170,7 @@ export const CONVENTION_ROWS = [
|
|
|
149
170
|
range: ">=4.0.0 <10.0.0",
|
|
150
171
|
entries: [],
|
|
151
172
|
moves: [],
|
|
173
|
+
packageKeys: [{ key: "parser", files: ESLINTRC }],
|
|
152
174
|
prefixedNames: [
|
|
153
175
|
{ property: "plugins", files: ESLINTRC, prefix: "eslint-plugin" },
|
|
154
176
|
{ property: "extends", files: ESLINTRC, prefix: "eslint-plugin", marker: "plugin:" },
|
|
@@ -264,6 +286,14 @@ export const CONVENTION_ROWS = [
|
|
|
264
286
|
{ key: "oclif.hooks", directory: false },
|
|
265
287
|
],
|
|
266
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
|
+
}),
|
|
267
297
|
{
|
|
268
298
|
name: "parcel",
|
|
269
299
|
package: "parcel",
|
|
@@ -331,6 +361,13 @@ export const CONVENTION_ROWS = [
|
|
|
331
361
|
},
|
|
332
362
|
],
|
|
333
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
|
+
},
|
|
334
371
|
{
|
|
335
372
|
name: "remix",
|
|
336
373
|
package: "@remix-run/dev",
|