forked from mjbvz/vscode-strict-null-check-migration-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (55 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// @ts-check
const path = require("path");
const glob = require("glob");
const {
forUncheckedIndexEligbleFiles,
forEachFileInSrc,
} = require("./src/getStrictNullCheckEligibleFiles");
const { getImportsForFile } = require("./src/tsHelper");
const vscodeRoot = path.join(process.cwd(), process.argv[2]);
const srcRoot = path.join(vscodeRoot, "src");
let sort = true;
let filter;
let printDependedOnCount = true;
let includeTests = false;
if (false) {
// Generate test files listing
sort = false;
filter = (x) => x.endsWith(".test.ts");
printDependedOnCount = false;
includeTests = true;
}
forUncheckedIndexEligbleFiles(vscodeRoot, () => {}, { includeTests }).then(
async (eligibleFiles) => {
const eligibleSet = new Set(eligibleFiles);
const dependedOnCount = new Map(eligibleFiles.map((file) => [file, 0]));
for (const file of await forEachFileInSrc(srcRoot)) {
if (eligibleSet.has(file)) {
// Already added
continue;
}
for (const imp of getImportsForFile(file, srcRoot)) {
if (dependedOnCount.has(imp)) {
dependedOnCount.set(imp, dependedOnCount.get(imp) + 1);
}
}
}
let out = Array.from(dependedOnCount.entries());
if (filter) {
out = out.filter((x) => filter(x[0]));
}
if (sort) {
out = out.sort((a, b) => b[1] - a[1]);
}
for (const pair of out) {
console.log(
toFormattedFilePath(pair[0]) +
(printDependedOnCount ? ` — Depended on by **${pair[1]}** files` : "")
);
}
}
);
function toFormattedFilePath(file) {
// return `"./${path.relative(srcRoot, file)}",`;
return `- [ ] \`"./${path.relative(srcRoot, file)}"\``;
}