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

Api for tsc --build and --incremental #31432

Merged
merged 44 commits into from
Jun 5, 2019
Merged

Api for tsc --build and --incremental #31432

merged 44 commits into from
Jun 5, 2019

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented May 16, 2019

This PR provides api for tooling to use build and incremental options:
TypeStrong/ts-loader#935 shows use of --build api

Solution Builder

Two functions createSolutionBuilder and createSolutionBuilderWithWatch provide a way to create SolutionBuilder for given root projects, and build options. The only difference in later is that it also watches the projects for changes to be able to build.

interface SolutionBuilder<T extends BuilderProgram> {
    build(project?: string, cancellationToken?: CancellationToken): ExitStatus;
    clean(project?: string): ExitStatus;
    buildReferences(project: string, cancellationToken?: CancellationToken): ExitStatus;
    cleanReferences(project?: string): ExitStatus;
    getNextInvalidatedProject(cancellationToken?: CancellationToken): InvalidatedProject<T> | undefined;
}

build and clean provide a compact way of building/cleaning all root projects provided or project mentioned (including their references).
getNextInvalidatedProject is the API for more granular level operations on each project. This function will give you a project that needs to be either built or needs to update output because prepend changed or just needs update timestamps. When done method of the returned project is called, it ensures all actions are taken place and its ready to move to next project so that next call to getNextInvalidatedProject will return you next project that's invalid or undefined if the build is complete.

Incremental Builder Program

createIncrementalProgram and createIncrementalCompilerHost are methods similar to createProgram and createCompilerHost to build the incremental builder program.
This also exposes readBuilderProgram provides a way to be able to create the EmitAndSemanticDiagnosticsBuilder from the .tsbuildinfo for the compiler options. Note that this is special program that is readonly version and it can only be used as oldProgram to create new builder program.

…aths

Turn projectPendingBuild to config file map
…r options

Also fix return type of readBuilderProgram
@sheetalkamat sheetalkamat marked this pull request as ready for review May 16, 2019 22:23
@manucorporat
Copy link

manucorporat commented May 16, 2019

@sheetalkamat could this API be used from a Language Service createLanguageService?

@sheetalkamat
Copy link
Member Author

@manucorporat Sorry I missed your question earlier. I am not sure what you mean by createLanguageService. This is the api for compiling the programs like tsc --b or tsc --incremental.

@sheetalkamat sheetalkamat merged commit 5c21fad into master Jun 5, 2019
@sheetalkamat sheetalkamat deleted the builderAPI branch June 5, 2019 19:31
@mihailik
Copy link
Contributor

It looks like these APIs either allow fine-granular acccess with getNextInvalidatedProject, or support watching.

In order to trigger the watching behaviour one needs to call solutionBuilder.build() which does not support custom transformers.

However, not all is lost. It is possible to sneak transformers in by using createProgram callback, inside which you can patch program.emit() method with your own code, calling the original emit(...) with extra transformers added.

Here is a simple example on Stack Overflow:

https://stackoverflow.com/questions/62026189/typescript-custom-transformers-with-ts-createwatchprogram/62027253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants