10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Tips: TypeScriptのプロジェクトで使っていない`export`を見つけるのに`ts-prune`が便利だった

Posted at

これは何

TypeScriptのプロジェクトの開発を行っている時、どこからも参照されていないexportを見つけるのにts-pruneが便利だったので記事にしました。

ts-pruneとは

ts-pruneとは、ゼロコンフィグでどこからもimportされていないexportを列挙してくれるライブラリです。

とりあえず使ってみるなら以下のコマンドをプロジェクト直下で実行すれば動きます。

$ npx ts-prune

基本的にゼロコンフィグで動かせるのがとても手軽で便利です。

使い方

npx ts-pruneは各モジュール行単位で結果が出力されるので、grepを組み合わせ使うと色々な絞り込みができます。
よく用いているコマンドは以下の通りです

  • 特定のパスの中から探す場合
    • npx ts-prune | grep '/path/to/directory'
  • module内でのみ使っているファイルを探す場合
    • npx ts-prune | grep '(used in module)'
  • exportされたモジュールのプレフィックスで探す場合
    • npx ts-prune | grep ' - Prefix'
10
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?