|
| 1 | +import { basename, join, relative, resolve } from "path"; |
| 2 | +import analyzeTsConfig from "ts-unused-exports"; |
| 3 | +import { containsPath, pathsEqual } from "../src/common/files"; |
| 4 | +import { exit } from "process"; |
| 5 | + |
| 6 | +function ignoreFile(file: string): boolean { |
| 7 | + return ( |
| 8 | + containsPath("gulpfile.ts", file) || |
| 9 | + containsPath(join("src", "stories"), file) || |
| 10 | + pathsEqual( |
| 11 | + join("test", "vscode-tests", "jest-runner-installed-extensions.ts"), |
| 12 | + file, |
| 13 | + ) || |
| 14 | + basename(file) === "jest.config.ts" || |
| 15 | + basename(file) === "index.tsx" || |
| 16 | + basename(file) === "index.ts" |
| 17 | + ); |
| 18 | +} |
| 19 | + |
| 20 | +function main() { |
| 21 | + const repositoryRoot = resolve(join(__dirname, "..")); |
| 22 | + |
| 23 | + const result = analyzeTsConfig("tsconfig.deadcode.json"); |
| 24 | + let foundUnusedExports = false; |
| 25 | + |
| 26 | + for (const [filepath, exportNameAndLocations] of Object.entries(result)) { |
| 27 | + const relativeFilepath = relative(repositoryRoot, filepath); |
| 28 | + |
| 29 | + if (ignoreFile(relativeFilepath)) { |
| 30 | + continue; |
| 31 | + } |
| 32 | + |
| 33 | + foundUnusedExports = true; |
| 34 | + |
| 35 | + console.log(relativeFilepath); |
| 36 | + for (const exportNameAndLocation of exportNameAndLocations) { |
| 37 | + console.log(` ${exportNameAndLocation.exportName}`); |
| 38 | + } |
| 39 | + console.log(); |
| 40 | + } |
| 41 | + |
| 42 | + if (foundUnusedExports) { |
| 43 | + exit(1); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +main(); |
0 commit comments