From 5363b2d7ad5f90b27720b065bd15dcb2a62b68a0 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 6 Apr 2016 13:25:29 -0700 Subject: [PATCH 1/6] Add option to list the emitted as part of the compiler output. This is useful for incremental build scenarios. --- src/compiler/commandLineParser.ts | 5 +++++ src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/emitter.ts | 12 ++++++++++++ src/compiler/program.ts | 3 ++- src/compiler/tsc.ts | 18 +++++++++++++++--- src/compiler/types.ts | 2 ++ 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 67a3e264efc..3ee27ae255d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -331,6 +331,11 @@ namespace ts { type: "boolean", description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output }, + { + name: "listEmittedFiles", + type: "boolean", + description: Diagnostics.List_emitted_files + }, { name: "lib", type: "list", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8fefa92b140..f230d366cdb 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2292,6 +2292,10 @@ "category": "Message", "code": 6011 }, + "List emitted files.": { + "category": "Message", + "code": 6012 + }, "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'": { "category": "Message", "code": 6015 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 469530bb6be..0852f76ef2a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -380,6 +380,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge const languageVersion = getEmitScriptTarget(compilerOptions); const modulekind = getEmitModuleKind(compilerOptions); const sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; + const emittedFilesList: string[] = compilerOptions.listEmittedFiles ? [] : undefined; const emitterDiagnostics = createDiagnosticCollection(); let emitSkipped = false; const newLine = host.getNewLine(); @@ -390,6 +391,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return { emitSkipped, diagnostics: emitterDiagnostics.getDiagnostics(), + emittedFiles: emittedFilesList, sourceMaps: sourceMapDataList }; @@ -8232,6 +8234,16 @@ const _super = (function (geti, seti) { if (declarationFilePath) { emitSkipped = writeDeclarationFile(declarationFilePath, sourceFiles, isBundledEmit, host, resolver, emitterDiagnostics) || emitSkipped; } + + if (!emitSkipped && emittedFilesList) { + emittedFilesList.push(jsFilePath); + if (sourceMapFilePath) { + emittedFilesList.push(sourceMapFilePath); + } + if (declarationFilePath) { + emittedFilesList.push(declarationFilePath); + } + } } } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 70c421f9d2b..056b2a4fc9a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1015,7 +1015,7 @@ namespace ts { let declarationDiagnostics: Diagnostic[] = []; if (options.noEmit) { - return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emitSkipped: true }; + return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: [], emitSkipped: true }; } // If the noEmitOnError flag is set, then check if we have any errors so far. If so, @@ -1035,6 +1035,7 @@ namespace ts { return { diagnostics: concatenate(diagnostics, declarationDiagnostics), sourceMaps: undefined, + emittedFiles: [], emitSkipped: true }; } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index f4d25a6bf1b..198b59af2dd 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -14,6 +14,17 @@ namespace ts { } } + function reportEmittedFiles(files: string[], host: CompilerHost): void { + if (!files || files.length == 0) { + return; + } + + for (const file of files) { + const message = `TSFILE: ${file}${sys.newLine}`; + sys.write(message); + } + } + /** * Checks to see if the locale is in the appropriate format, * and if it is, attempts to set the appropriate language. @@ -108,7 +119,6 @@ namespace ts { sys.write(output); } - const redForegroundEscapeSequence = "\u001b[91m"; const yellowForegroundEscapeSequence = "\u001b[93m"; const blueForegroundEscapeSequence = "\u001b[93m"; @@ -130,7 +140,7 @@ namespace ts { let output = ""; if (diagnostic.file) { - const { start, length, file } = diagnostic; + const {start, length, file} = diagnostic; const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); const lastLineInFile = getLineAndCharacterOfPosition(file, file.text.length).line; @@ -185,7 +195,7 @@ namespace ts { } output += sys.newLine; - output += `${ relativeFileName }(${ firstLine + 1 },${ firstLineChar + 1 }): `; + output += `${relativeFileName}(${firstLine + 1},${firstLineChar + 1}): `; } const categoryColor = categoryFormatMap[diagnostic.category]; @@ -597,6 +607,8 @@ namespace ts { reportDiagnostics(sortAndDeduplicateDiagnostics(diagnostics), compilerHost); + reportEmittedFiles(emitOutput.emittedFiles, compilerHost); + if (emitOutput.emitSkipped && diagnostics.length > 0) { // If the emitter didn't emit anything, then pass that value along. return ExitStatus.DiagnosticsPresent_OutputsSkipped; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3bc3d1ad6a1..f8dd5627148 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1709,6 +1709,7 @@ namespace ts { emitSkipped: boolean; /** Contains declaration emit diagnostics */ diagnostics: Diagnostic[]; + emittedFiles: string[]; // Array of files the compiler wrote to disk /* @internal */ sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps } @@ -2458,6 +2459,7 @@ namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + listEmittedFiles?: boolean; lib?: string[]; /* @internal */ stripInternal?: boolean; From 340051f4f5d48d0233bb0fc5160e1ca497cb6431 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 6 Apr 2016 13:34:18 -0700 Subject: [PATCH 2/6] Whitespace fix --- src/compiler/tsc.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 198b59af2dd..2324a089b25 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -140,7 +140,7 @@ namespace ts { let output = ""; if (diagnostic.file) { - const {start, length, file} = diagnostic; + const { start, length, file } = diagnostic; const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); const lastLineInFile = getLineAndCharacterOfPosition(file, file.text.length).line; @@ -195,7 +195,7 @@ namespace ts { } output += sys.newLine; - output += `${relativeFileName}(${firstLine + 1},${firstLineChar + 1}): `; + output += `${ relativeFileName }(${ firstLine + 1 },${ firstLineChar + 1 }): `; } const categoryColor = categoryFormatMap[diagnostic.category]; From 88a8992ce3c7338d1c3f61bb4e0a3202da581380 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 7 Apr 2016 15:29:11 -0700 Subject: [PATCH 3/6] CR Feedback --- src/compiler/program.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 056b2a4fc9a..f993eadd3e6 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1015,7 +1015,7 @@ namespace ts { let declarationDiagnostics: Diagnostic[] = []; if (options.noEmit) { - return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: [], emitSkipped: true }; + return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: undefined, emitSkipped: true }; } // If the noEmitOnError flag is set, then check if we have any errors so far. If so, @@ -1035,7 +1035,7 @@ namespace ts { return { diagnostics: concatenate(diagnostics, declarationDiagnostics), sourceMaps: undefined, - emittedFiles: [], + emittedFiles: undefined, emitSkipped: true }; } From 40b22b2fcacde012b4093317249e2367519fd3ae Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 7 Apr 2016 15:31:02 -0700 Subject: [PATCH 4/6] Ensure the listed files have absolute paths. --- src/compiler/tsc.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2324a089b25..9734ba6689b 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -20,8 +20,9 @@ namespace ts { } for (const file of files) { - const message = `TSFILE: ${file}${sys.newLine}`; - sys.write(message); + const filepath = getNormalizedAbsolutePath(file, sys.getCurrentDirectory()); + + sys.write(`TSFILE: ${filepath}${sys.newLine}`); } } From 8d08be8a62c557f6d66ee4af2585c9a6498099a9 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 7 Apr 2016 16:06:29 -0700 Subject: [PATCH 5/6] use temp variable for current dir. prevents calls to the host for every file. --- src/compiler/tsc.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 9734ba6689b..c2199cf7345 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -19,8 +19,10 @@ namespace ts { return; } + const currentDir = sys.getCurrentDirectory(); + for (const file of files) { - const filepath = getNormalizedAbsolutePath(file, sys.getCurrentDirectory()); + const filepath = getNormalizedAbsolutePath(file, currentDir); sys.write(`TSFILE: ${filepath}${sys.newLine}`); } From 097adc6b3a5150d42fc33646ee84552036b9455e Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 7 Apr 2016 16:47:52 -0700 Subject: [PATCH 6/6] Remove message from 'help' --- src/compiler/commandLineParser.ts | 3 +-- src/compiler/diagnosticMessages.json | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3ee27ae255d..76432ae78d9 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -333,8 +333,7 @@ namespace ts { }, { name: "listEmittedFiles", - type: "boolean", - description: Diagnostics.List_emitted_files + type: "boolean" }, { name: "lib", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f230d366cdb..8fefa92b140 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2292,10 +2292,6 @@ "category": "Message", "code": 6011 }, - "List emitted files.": { - "category": "Message", - "code": 6012 - }, "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'": { "category": "Message", "code": 6015