Skip to content

Feature: Support incremental build #999

@mc0

Description

@mc0

Description

There has been some excellent work by @sheetalkamat and @andrewbranch on adding incremental/projectReferences API support to TypeScript [0] and ts-loader [1]. There are still some missing pieces of functionality for the incremental support in ts-loader even after a related PR was closed [2].

The primary issue is that if the base project that has Webpack in it is built with tsconfig.json containing the incremental or composite compiler options, the incremental program is never initialized and used. It's possible that this is blocked by needing support for passing in an oldProgram to TypeScript's languageService or rewriting ts-loader to stop using the languageService. I've dug into this quite a bit and thought it might be useful to pass on my thoughts.

With SolutionBuilder

I've been able to locally tweak ts-loader to run .build() on a solutionBuilder it creates/uses the tsBuildInfoFile as expected. Using solutionBuilder for ts-loader has downsides. Namely, if webpack has multiple entry values for a given project, the references will be built multiple times. Adding .build() in place of languageService would just make that problem worse.

// getEmitOutput...
            if (solutionBuilder) {
               const exitCode = solutionBuilder.build(instance.configFilePath);
               if (exitCode !== 0) {
                   throw new Error("Failed to build");
               }
               // presumably we could read the correct file and return it if we wanted
            } else {
              // ... use program.emit
            }

With LanguageService

Using LanguageService would require the ability to pass in an oldProgram (at minimum, it might need to allow a createProgram func). This seems like the most straightforward change for ts-loader but requires TypeScript changes. It is difficult to really know which API to choose at this point but it seems that the incremental support was not added to languageService.

Minimal Repo

Not a repo, but a gist: https://gist.github.com/mc0/e19f69b2b26f6b612423c17722250503

0: microsoft/TypeScript#31432
1: #935
2: #913

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions