From 0928244d274bea413f943c6c27d169423b098da7 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 30 Mar 2016 15:03:43 -0700 Subject: [PATCH] fix: on error builds an error was thrown because of duped files. --- lib/broccoli/broccoli-typescript.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/broccoli/broccoli-typescript.js b/lib/broccoli/broccoli-typescript.js index e0a5bcda13ff..794df7a48563 100644 --- a/lib/broccoli/broccoli-typescript.js +++ b/lib/broccoli/broccoli-typescript.js @@ -80,7 +80,6 @@ class BroccoliTypeScriptCompiler extends Plugin { fse.mkdirsSync(path.dirname(outputFilePath)); fs.linkSync(absoluteFilePath, outputFilePath); }); - return; } else { this._fileRegistry[tsFilePath].version = entry.mtime; pathsToEmit.push(tsFilePath); @@ -94,7 +93,7 @@ class BroccoliTypeScriptCompiler extends Plugin { pathsToEmit.forEach(tsFilePath => { var output = this._tsService.getEmitOutput(tsFilePath); if (output.emitSkipped) { - var errorFound = this.collectErrors(tsFilePath); + var errorFound = this._collectErrors(tsFilePath); if (errorFound) { pathsWithErrors.push(tsFilePath); errorMessages.push(errorFound); @@ -129,7 +128,7 @@ class BroccoliTypeScriptCompiler extends Plugin { this._tsService = ts.createLanguageService(this._tsServiceHost, ts.createDocumentRegistry()); } - collectErrors(tsFilePath) { + _collectErrors(tsFilePath) { var allDiagnostics = this._tsService.getCompilerOptionsDiagnostics() .concat(this._tsService.getSyntacticDiagnostics(tsFilePath)) .concat(this._tsService.getSemanticDiagnostics(tsFilePath)); @@ -156,7 +155,7 @@ class BroccoliTypeScriptCompiler extends Plugin { // Find the entry, update the registry. let allEntries = this.listEntries(); - allEntries.forEach(entry => this._addNewFileEntry(entry)); + allEntries.forEach(entry => this._addNewFileEntry(entry, false)); allFiles.forEach(sourceFile => { const registry = this._fileRegistry[path.resolve(this.inputPaths[0], sourceFile.fileName)]; @@ -166,7 +165,7 @@ class BroccoliTypeScriptCompiler extends Plugin { if (emitResult.emitSkipped) { var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); - var errorMessages_1 = []; + var errorMessages = []; allDiagnostics.forEach(function (diagnostic) { var pos = ''; if (diagnostic.file) { @@ -174,9 +173,9 @@ class BroccoliTypeScriptCompiler extends Plugin { pos = diagnostic.file.fileName + ' (' + (line + 1) + ', ' + (character + 1) + '): '; } var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - errorMessages_1.push(' ' + pos + message); + errorMessages.push(' ' + pos + message); }); - if (errorMessages_1.length) { + if (errorMessages.length) { this.previousRunFailed = true; var error = new Error('Typescript found the following errors:\n' + errorMessages_1.join('\n')); error['showStack'] = false; @@ -206,10 +205,14 @@ class BroccoliTypeScriptCompiler extends Plugin { fs.linkSync(absoluteFilePath, outputFilePath); } - _addNewFileEntry(entry) { + _addNewFileEntry(entry, checkDuplicates /* = true */) { + if (checkDuplicates === undefined) { + checkDuplicates = true; + } + const p = path.join(this.inputPaths[0], entry.relativePath); - if (this._fileRegistry[p]) { - throw new Error('Trying to add a new entry to an already existing one: ' + p); + if (checkDuplicates && this._fileRegistry[p]) { + throw `Trying to add a new entry to an already existing one: "${p}`; } this._fileRegistry[p] = {