Skip to content

Stop inspecting output strings to determine when builds complete #209

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
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/incremental-typescript-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,11 @@ module.exports = class IncrementalTypescriptCompiler {

this._watchProgram = compile(project, { outDir, watch: true }, {
watchedFileChanged: () => this.state.tscDidStart(),
buildComplete: () => this.state.tscDidEnd(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so much better!


reportWatchStatus: (diagnostic) => {
let text = diagnostic.messageText;
debugTsc(text);

if (text.indexOf('Compilation complete') !== -1) {
this.state.tscDidEnd();
}
},

reportDiagnostic: (diagnostic) => {
Expand Down
20 changes: 17 additions & 3 deletions lib/utilities/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down