-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Program.isSourceFileDefaultLibrary to public API #25225
Comments
I had a similar requirement when I wanted to exclude all external files from linting.
This is my implementation that handles all of these cases: https://github.com/fimbullinter/wotan/blob/a3cfe28ef9162dacf451c839efa2f26be30d1ce1/packages/wotan/src/runner.ts#L196-L216 |
@ajafff In my case, I need to know only if a file is default lib file, but anyway thanks for the additional information! |
In that case you could simply compare to |
It seems that |
You might want to do the path comparison yourself: // may need some special handling to normalize slashes and file casing
path.dirname(sourceFile.fileName) === path.dirname(ts.getDefaultLibFilePath(program.getCompilerOptions())); |
I guess there is some misunderstanding - I need to filter all lib files (I thought it called "default lib files"). Of course, we can create one more solution (with checking the path of the file or something else), but compiler knows it already, so why I need to do its work? 🙂 |
But in this case, we'll filter
Why not? As far as I understand it checks that file is |
A PR would be appreciated. |
Search Terms
API, Program
Suggestion
Is there a chance to add
isSourceFileDefaultLibrary
toProgram
s API?For now, it is marked as
@internal
and this method is removed from declaration file https://github.com/Microsoft/TypeScript/blob/70975cd08f48497f3ae6538ff69bf50cac23706b/src/compiler/types.ts#L2777Use Cases
I working on https://github.com/timocov/dts-bundle-generator and there I need to know what files are default lib files. I need to know it to skip these files from preparing. It seems that is the right way to detect it, but it is not public.
If there is another way to check that some file is default lib file - please let me know.
Related to timocov/dts-bundle-generator#39.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: