A simple script to calculate unused files on a JavaScript codebase based on their module resolution paths.
In short, this script does the following:
- Chooses an entry point (defaults to
$PWD/src/App.js
) - Finds all
import
statements, and the files that they point to. - Repeats this process for each file found
- This list of imports is diffed with the list of all files in the directory (
$PWD/src
). Everything that is present in the second set is the list of unused files.
This script isn't published on npm
yet since we only need it for internal use.
Install the git-based dependency through yarn
and then add a script in the scripts
section in package.json
.
$ yarn add fleetpanda/unused-files#master
In your package.json
, add a script:
"scripts": {
"start": "react-native-start"
+ "unused-files": "unused-files"
}
Finally, run the script to see what files can be safely removed from the codebase:
$ yarn run unused-files
- Entry point is currently hardcoded to
$PWD/src/App.js
. - The directory to diff with is hardcoded to
$PWD/src
- All imports are done via the
import
syntax -require
s aren't supported. - All imports use relative file paths for local files.