https://github.com/peterroe/finse
Find which files reference the target file
https://github.com/peterroe/finse
command-line finse
Last synced: 11 months ago
JSON representation
Find which files reference the target file
- Host: GitHub
- URL: https://github.com/peterroe/finse
- Owner: peterroe
- License: mit
- Created: 2022-10-23T09:13:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T11:34:50.000Z (over 2 years ago)
- Last Synced: 2025-05-29T05:18:17.380Z (about 1 year ago)
- Topics: command-line, finse
- Language: TypeScript
- Homepage:
- Size: 494 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## finse
Find which files reference the target file
### Features
* Friendly output
* Supports alias via `tsconfig.json`
* Supports `esm` and `cjs`
* Detect the project root directory
* Unlimited file types
### Install
```shell
$ npm i -g finse
$ finse -h # help
```
### Usage
Suppose we have a project, its directory structure is like this:
```txt
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:
```shell
$ 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
```js
// 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":
```js
// 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:
```html
import xx from '@/xx'
// or:
import xxx from '~/xx'
```
But have to make sure there is such a configuration in `[t|j]sconfig.json`:
```json
{
"compilerOptions": {
"paths": {
"~/*": ["test/demo/bar/*"],
"@/*": ["src/*"]
}
}
}
```
### finse
it's mean find use
### Acknowledgement
Thanks for the proposal for `jsconfig.json` by [Artsmp](https://github.com/Artsmp)