From 1f4803c6822d613d62574358d56d2381239ecea1 Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Mon, 14 May 2018 18:39:23 -0400 Subject: [PATCH] Stop inspecting output strings to determine when builds complete --- lib/incremental-typescript-compiler/index.js | 5 +---- lib/utilities/compile.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/incremental-typescript-compiler/index.js b/lib/incremental-typescript-compiler/index.js index f4fbfd609..a9dc7b63f 100644 --- a/lib/incremental-typescript-compiler/index.js +++ b/lib/incremental-typescript-compiler/index.js @@ -97,14 +97,11 @@ module.exports = class IncrementalTypescriptCompiler { this._watchProgram = compile(project, { outDir, watch: true }, { watchedFileChanged: () => this.state.tscDidStart(), + buildComplete: () => this.state.tscDidEnd(), reportWatchStatus: (diagnostic) => { let text = diagnostic.messageText; debugTsc(text); - - if (text.indexOf('Compilation complete') !== -1) { - this.state.tscDidEnd(); - } }, reportDiagnostic: (diagnostic) => { diff --git a/lib/utilities/compile.js b/lib/utilities/compile.js index 2030e4733..0d3eb6a4f 100644 --- a/lib/utilities/compile.js +++ b/lib/utilities/compile.js @@ -19,23 +19,37 @@ module.exports = function compile(project, tsOptions, callbacks) { }, tsOptions); let ts = project.require('typescript'); + let host = createWatchCompilerHost(ts, fullOptions, project, callbacks); + + return ts.createWatchProgram(host); +}; + +function createWatchCompilerHost(ts, options, project, callbacks) { let configPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json'); let createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram; let host = ts.createWatchCompilerHost( configPath, - fullOptions, + options, buildWatchHooks(project, ts.sys, callbacks), createProgram, diagnosticCallback(callbacks.reportDiagnostic), diagnosticCallback(callbacks.reportWatchStatus) ); + let afterCreate = host.afterProgramCreate; + host.afterProgramCreate = function() { + afterCreate.apply(this, arguments); + if (callbacks.buildComplete) { + callbacks.buildComplete(); + } + }; + if (debug.enabled) { host.trace = str => debug(str.trim()); } - return ts.createWatchProgram(host); -}; + return host; +} function diagnosticCallback(callback) { if (callback) {