pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
749 stars 49 forks source link

Ignore unused exports from the entry point of library (package.json) #105

Open mrseanryan opened 4 years ago

mrseanryan commented 4 years ago

Ignore unused exports from the entry point of library (package.json).

This could be useful for source code of libraries.

So if package.json says:

  "main": "lib/app.js",

Then use tsconfig.json to infer that src/app.ts is the entry point. Then ignore unused exports from that file.

note: there is a workaround, using the ignorePaths=app.ts option - but that is not as nice to use.

maneetgoyal commented 4 years ago

Hi @mrseanryan, following up from #132

It's a nice enhancement. Hoping that the inference logic is quite robust. Some cases to think about are:

  1. Here's a TS library which has "main" in package.json as dist/index.js but no src/index.ts.
  2. In another TS project, I have "main": "dist/esm/index.js" because we are generating multiple types of distributions.

I'm sure you'd have some criteria to effectively handle multiple scenarios, but just pointing out some cases which I personally would benefit more from.


Further, it would be great if the users can provide a glob/regex to specify which files to analyze. It (along with the already existing ignoreFiles option) would offer a great amount of control. The README seems to have some formatting issue related to the ignoreFiles option though.

mrseanryan commented 4 years ago

Thank you @maneetgoyal for the library link. That library seems to be all .html or .tsx files no regular .ts files? To be honest, this kind of project is not something I've been thinking about (moistly working with ts and tsx files. So this example is interesting.

I will fix the README format.

For the glob/regex - have logged issue #136