Skip to content

Simplify gulp to just use 'tsc -b' to build, update to gulp@4 #29619

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

Merged
merged 1 commit into from
Jan 28, 2019

Conversation

rbuckton
Copy link
Contributor

This completely rewrites our gulpfile to support gulp@4 and drops 'gulp-typescript' in favor of just calling tsc -b for the various projects.

NOTE: This requires you have an updated global install of gulp-cli:

npm install -g gulp-cli@4

Problems with Parallelism

The biggest issue with leveraging tsc -b is that parallel tasks would result in multiple running instances of tsc -b for top-level projects (such as tsc, run.js, etc.). Since these processes do not communicate with each other, its highly likely that each instance would attempt to build the same upstream project at the same time.

To avoid this, each call to tsc -b is queued for a period of time (currently 100ms) and then all projects to be built are passed to a single instance of tsc -b. This way, upstream projects are only built once. However, this has the downside of having all downstream projects in the same process, meaning the process consumes more memory and we cannot leverage parallel compilation.

We may in the future want to consider how to allow for better parallelism and coordination with tsc -b, even something as simple as an option to tsc -b that writes out a project-specific lock file before building a project. Other options might include leveraging unix sockets/named pipes for inter-process communication.

"Watch" mode

The other unsolved issue is how to best handle "watch mode". Gulp's watch function knows only about file system changes. Even if we pass multiple projects to tsc -b --watch, Gulp's watch could trigger on one output being written for a downstream project even while other downstream projects are still being built. Because there is no coordination, this would result in a test run starting prematurely. While we can have gulp watch the sources and run tsc -b without the --watch option, we then lose the incremental build-time benefits of tsc -b --watch. For now, our only option is to tinker with the delay passed to gulp.watch until we find one that is "good enough" for most purposes.

@rbuckton
Copy link
Contributor Author

@ahejlsberg: This also adds a gulp min task that builds only tsc and tsserver, as well as a gulp watch-min task that watches and rebuilds only tsc and tsserver.

For comparison, in a clean workspace after scripts/ has been built and diagnostics and libs have been generated:

  • tsc -b src/tsc src/tsserver takes about 32 seconds
  • gulp min takes about 35 seconds

gulp min has a small amount of overhead as it verifies scripts/ has been built and the diagnostics and libs haven't changed.

@rbuckton rbuckton merged commit e963107 into master Jan 28, 2019
@rbuckton rbuckton deleted the simpleGulp branch January 28, 2019 23:15
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.

2 participants