How Does It Work
The task is to compare all exports and imports of the package. Anything not imported but exported is an unused export.
Algorithm
- collect all package exports into exports Set
- traverse all files where package import may occur
- if the import is found, remove it from exports Set
- if the size of the exports Set became equal to 0, then exit with success
- if the exports Set size is not equal to 0, then exit with an error
How It Optimized
- file reading is divided into batches
- file is not immediately converted to AST. First the import of the package is searched for in the file. createReadStream is used
- there is an instant exit with success as soon as the size of exports Set is equal to zero
- swc is used to parse the AST
- fdir is used as project crawler