-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add language service API to get the compile and runtime dependencies of a source file #3687
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
Conversation
I will look into the failures. I wasn't aware that the test harness implements ILanguageService. |
Here is how the current dependency info looks like: { So the fine name is the full path of the source file. This helps to related the dependency information back to the original source file. The compile and runtime dependencies are basically the external module reference strings. I looked into providing the full path to the resolved ts/d.ts file however this information isn't available for amd dependencies like /// But I am open to change the format to something that includes the full path to the resolved source file if it is available. |
let resolver = program.getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); | ||
|
||
let runtime: string[] = []; | ||
let compileTime: string[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initially i thought that compileTime is a subset of runtime, but then looking at the code, that did not turn out to be the case. i think we need better names here. maybe "compileTimeOnly", or "non-js dependencies.."
Sorry @dbaeumer for the delay. i have a general question, do you really need to know what reference is emitted and what is not? I understand that this is an accurate representation of the compiler behavior, but i wounder if this would allow for significant improvements compared to the complexity added in querying the information (i.e. needing the file to be fully type checked to get this information correctly, where as the other one can be done syntactically, just a simple tree walk). |
@mhegazy no problem. I was busy with VSCode anyway. I would really like to have the information whether the reference is compile time only or run time. The reason is that we want to use that for packaging. Currently we rely on some JS tools for packaging and these toosl change whether we compile to AMD or CommonJS. The nice thing about TS is that it is module system independent. So a tool that analyses runtime dependencies can be independent of the module system as well. This is even more helpful when SystemJS becomes adopted. It would mean we don't have to change our packaging story when we compile to ES6. I like the proposal to make the list more expressive. However to not make it to confusing with the names and easier maintainable in the future the list should contain object literal and not strings only. That way we can have only two top level properties for now. The literal would look like this: enum ImportKind { interface ImportInformation { Something like The import kind of amd dependencies would always be Code. We could also add an additional flag to the getDependencies function to indicate if the import kind should be computed. If not requested then a syntax walk would be sufficient. I wasn't aware of the work @vladima is doing with module resolution. I will definitely have a look at it (I think his work is still on a branch) and adopt the getDependencies feature. I will also add code to force the type check. Thanks for pointing this out to me. |
What are the next steps here? |
This has been superseded with the builder work. closing. |
This PR adds API to the language service to provide the compile and runtime dependencies of a TS file. This information is useful for a package that works independent of the module system and can be used for an incremental compiler that compiles upwards dependencies.