finse v1.5.8
finse
Find which files reference the target file
Features
- Friendly output
- Supports alias via
tsconfig.json
- Supports
esm
andcjs
- Detect the project root directory
- Unlimited file types
Install
$ npm i -g finse
$ finse -h # help
Usage
Suppose we have a project, its directory structure is like this:
finse
└─ test
└─ demo
├─ bar
├─ corge
└─ nacho.vue
└─ oop.ts
├─ foo
└─ sharp.js # sdf
└─ thud.tsx
And you want to find out which files reference oop.ts
,just run:
$ finse test/demo/bar/oop.ts
Maybe you will see the output similar to this:
The yellow background represents the file you want to match, the cyan background is the file that "uses" it
API
--root rootname
- Specify the project root directory
--expand
- Expand collapsed file tree
--link
- Display the absolute path of the file. That way other files can be accessed directly through the terminal
--ignore
- Ignore file does not exist errors
Motivation
It's hard to find which other files use the target file
Search in IDEA is not enough, it's difficult to give exact search keywords
How is works ?
- First, it will detect the project root directory if no directory is specified
- By default, the directory where
package.json
is located is selected as the root directory - Next, all reasonable files in the directory will be scanned
- Then match the contents of the file to see if there is an import statement
finse
will recognize the following imports
// static import
import xx from 'xxx'
if (Math.random() > 0.5) {
// dynamic import
import('xx.ts')
}
// require import
require('./xx/xx')
finse
works with regular expressions, But don't worry about "accidental recognition":
// Yes, legal import
import xx from 'xxx'
// No,Imports in comments are not recognized
// comment: import xx from 'xxx'
And supports identifying paths with alias:
<script setup>
import xx from '@/xx'
// or:
import xxx from '~/xx'
</script>
But have to make sure there is such a configuration in [t|j]sconfig.json
:
{
"compilerOptions": {
"paths": {
"~/*": ["test/demo/bar/*"],
"@/*": ["src/*"]
}
}
}
finse
it's mean find use
Acknowledgement
Thanks for the proposal for jsconfig.json
by Artsmp