diff --git a/lib/broccoli/broccoli-typescript.js b/lib/broccoli/broccoli-typescript.js index 3f85e67b9a86..0b47e0df5db5 100644 --- a/lib/broccoli/broccoli-typescript.js +++ b/lib/broccoli/broccoli-typescript.js @@ -40,14 +40,11 @@ class BroccoliTypeScriptCompiler extends Plugin { build() { if (!this._tsServiceHost) { this._createServiceHost(); - this._doFullBuild(); - } else { - this._doIncrementalBuild(); } + this._doIncrementalBuild(); } _doIncrementalBuild() { - var pathsWithErrors = []; var errorMessages = []; var entries = this.listEntries(); const inputPath = this.inputPaths[0]; @@ -93,10 +90,13 @@ class BroccoliTypeScriptCompiler extends Plugin { pathsToEmit.forEach(tsFilePath => { var output = this._tsService.getEmitOutput(tsFilePath); if (output.emitSkipped) { - var errorFound = this._collectErrors(tsFilePath); - if (errorFound) { - pathsWithErrors.push(tsFilePath); - errorMessages.push(errorFound); + const allDiagnostics = this._tsService.getCompilerOptionsDiagnostics() + .concat(this._tsService.getSyntacticDiagnostics(tsFilePath)) + .concat(this._tsService.getSemanticDiagnostics(tsFilePath)); + + const errors = this._collectErrors(allDiagnostics); + if (errors) { + errorMessages.push(errors); } } else { output.outputFiles.forEach(o => { @@ -106,13 +106,10 @@ class BroccoliTypeScriptCompiler extends Plugin { }); } - if (pathsWithErrors.length) { - this.previousRunFailed = true; + if (errorMessages.length) { var error = new Error('Typescript found the following errors:\n' + errorMessages.join('\n')); error['showStack'] = false; throw error; - } else if (this.previousRunFailed) { - this._doFullBuild(); } } @@ -128,65 +125,24 @@ class BroccoliTypeScriptCompiler extends Plugin { this._tsService = ts.createLanguageService(this._tsServiceHost, ts.createDocumentRegistry()); } - _collectErrors(tsFilePath) { - var allDiagnostics = this._tsService.getCompilerOptionsDiagnostics() - .concat(this._tsService.getSyntacticDiagnostics(tsFilePath)) - .concat(this._tsService.getSemanticDiagnostics(tsFilePath)); - var errors = []; - allDiagnostics.forEach(diagnostic => { - var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + _collectErrors(allDiagnostics) { + const errors = allDiagnostics.map(diagnostic => { + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); if (diagnostic.file) { - var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; - errors.push(' ' + diagnostic.file.fileName + ' (' + (line + 1) + ',' + (character + 1) + '): ' + message); + const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const line = position.line; + const character = position.character; + return ` ${diagnostic.file.fileName} (${line + 1}, ${character + 1}): ${message}`; } else { - errors.push(' Error: ' + message); + return ` Error: ${message}`; } }); + if (errors.length) { return errors.join('\n'); } } - _doFullBuild() { - var program = this._tsService.getProgram(); - - // Add file registry. - var allFiles = program.getSourceFiles(); - - // Find the entry, update the registry. - let allEntries = this.listEntries(); - allEntries.forEach(entry => this._addNewFileEntry(entry, false)); - - allFiles.forEach(sourceFile => { - const registry = this._fileRegistry[path.resolve(this.inputPaths[0], sourceFile.fileName)]; - const emitResult = program.emit(sourceFile, (absoluteFilePath, fileContent) => { - this._outputFile(absoluteFilePath, fileContent, registry); - }); - - if (emitResult.emitSkipped) { - var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); - var errorMessages = []; - allDiagnostics.forEach(function (diagnostic) { - var pos = ''; - if (diagnostic.file) { - var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; - pos = diagnostic.file.fileName + ' (' + (line + 1) + ', ' + (character + 1) + '): '; - } - var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - errorMessages.push(' ' + pos + message); - }); - if (errorMessages.length) { - this.previousRunFailed = true; - var error = new Error('Typescript found the following errors:\n' + errorMessages.join('\n')); - error['showStack'] = false; - throw error; - } else { - this.previousRunFailed = false; - } - } - }); - } - _outputFile(absoluteFilePath, fileContent, registry) { absoluteFilePath = path.resolve(this.cachePath, absoluteFilePath); // Replace the input path by the output.