-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfind-deadcode.ts
More file actions
49 lines (38 loc) · 1.12 KB
/
find-deadcode.ts
File metadata and controls
49 lines (38 loc) · 1.12 KB
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
import { join, relative, resolve } from "path";
import { exit } from "process";
import { analyzeTsConfig } from "ts-unused-exports";
import { Analysis } from "ts-unused-exports/lib/types";
function main() {
const repositoryRoot = resolve(join(__dirname, ".."));
let result: Analysis;
try {
result = analyzeTsConfig("tsconfig.json");
} catch (error) {
if (error instanceof Error) {
console.error("Failed to analyze tsconfig.json:", error.message);
} else {
console.error("Failed to analyze tsconfig.json:", error);
}
exit(1);
}
if (!result) {
console.error("No result from analyzeTsConfig");
exit(1);
}
let foundUnusedExports = false;
for (const [filepath, exportNameAndLocations] of Object.entries(
result.unusedExports,
)) {
const relativeFilepath = relative(repositoryRoot, filepath);
foundUnusedExports = true;
console.log(relativeFilepath);
for (const exportNameAndLocation of exportNameAndLocations) {
console.log(` ${exportNameAndLocation.exportName}`);
}
console.log();
}
if (foundUnusedExports) {
exit(1);
}
}
main();