出國前看到的東西,LINE 在 GitHub 上發表了整理 TypeScript 程式碼的套件:「Show HN: ts-remove-unused – Remove unused code from your TypeScript project (github.com/line)」,專案在「line/ts-remove-unused」這邊:
Remove unused code from your TypeScript project
不過 Hacker News 上的反應其實頗差,其中一個原因是預設值不太友善,沒有好的 ignore path 設定,test case 這種從 entry point 不會接觸到的就會被誤判了:
It deleted 100s of files, most of which were Jest test files, and potentially all of which were a mistake. I restored them all with `git restore $(git ls-files -d)`.
另外改出來的東西是爛的:
I then ran `tsc` on the remaining _modified_ files and `Found 3920 errors in 511 files.`
另外有不少人抱怨預設不是 dry run mode,被砍了一堆東西:
You should switch the default to not delete any files and modify/remove the files only with some flag (--dry-run=false, --rm, --delete, etc). I just deleted all files accidentally in a monorepo :D Luckily I didn't had any uncommitted changes and could recover using git
反倒是有人提了另外一個已經在停止發展,但運作的很好的 project:
I've been using ts-prune[1] for years at this point. The project is in maintenance mode but works fine so I've kept using it. I've been looking into Knip[2] which is recommended by the authors of ts-prune though it's been slow mostly because there's little incentive with the current tool working fine.
[1]: https://github.com/nadeesha/ts-prune
[2]: https://github.com/webpro-nl/knip
這邊反而值得看看...