Skip to content
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

Investigate TypeScript builder program API #98

Closed
kasperisager opened this issue Jan 7, 2019 · 2 comments
Closed

Investigate TypeScript builder program API #98

kasperisager opened this issue Jan 7, 2019 · 2 comments

Comments

@kasperisager
Copy link
Contributor

kasperisager commented Jan 7, 2019

Our current use of the TypeScript language service API in which individual source files are diagnosed and emitted has at least the following drawbacks:

  • While diagnostics for source files that are not our own are actually collected, we never show these anywhere. Only recently have we introduced support for traversing source file dependencies (7c94bb0) such that we could improve upon this, but the next point will outline the problems with this as well.

  • While we can traverse source file dependencies by resolving imports, the TypeScript module resolver resolves imports from packages to their entry point defined in package.json, which is how things should work. What we're interested in, however, is which actual source files a given source file depends on and not necessarily which source files it imports.

In effect, directly running the TypeScript compiler can yield different results than when we compile the project using the language service API.

By using the builder program API introduced in TypeScript 2.7, we should be able to fix the drawbacks of our current approach. Specifically, the builder program API includes functionally for getting all dependencies of a file (https://github.com/Microsoft/TypeScript/blob/b7d7d5f7b39a5b9619c77590e5fe7f434ed68f1e/src/compiler/builder.ts#L651) in addition to providing incremental diagnostics for an entire program (https://github.com/Microsoft/TypeScript/blob/b7d7d5f7b39a5b9619c77590e5fe7f434ed68f1e/src/compiler/builder.ts#L660). How far these APIs will take us remains to be seen though.

@kasperisager kasperisager self-assigned this Jan 7, 2019
@kasperisager kasperisager added this to To do in ⚙️ Development via automation Jan 7, 2019
@kasperisager kasperisager moved this from To do to Ready in ⚙️ Development Jan 7, 2019
@kasperisager kasperisager moved this from Ready to In progress in ⚙️ Development Jan 7, 2019
@kasperisager
Copy link
Contributor Author

As the name does imply, getAllDependencies() (https://github.com/Microsoft/TypeScript/blob/b7d7d5f7b39a5b9619c77590e5fe7f434ed68f1e/src/compiler/builder.ts#L651) returns all dependencies of a given file, direct and transitive. I also haven't been able to make it behave as I would expect with regards to project references introduced in 2a3edb6; it resolves dependencies across packages to the implementation files, not declaration files. That is, if file foo.ts from package foo imports bar.ts from package bar, I would expect the dependency to resolve to bar.d.ts rather than bar.ts.

@kasperisager kasperisager moved this from In progress to Ready in ⚙️ Development Feb 20, 2019
@kasperisager
Copy link
Contributor Author

kasperisager commented Feb 20, 2019

I have some experimental code in place for this but will not pursue it further for now: https://github.com/Siteimprove/alfa/tree/builder-api

@kasperisager kasperisager removed their assignment Feb 20, 2019
@kasperisager kasperisager moved this from Ready to To do in ⚙️ Development Apr 1, 2019
⚙️ Development automation moved this from To do to Done Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
⚙️ Development
  
🏁 Done
Development

No branches or pull requests

1 participant