From 3fdd66bddf8174a443f11c4bad1cf19e76c08b34 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 2 Apr 2019 13:15:02 -0700 Subject: [PATCH] Report program's source files even when there are errors when building using --build mode --- src/compiler/tsbuild.ts | 35 +++++++++++++------ src/compiler/watch.ts | 15 ++++---- src/testRunner/unittests/tsbuild/sample.ts | 6 ++-- .../unittests/tsbuild/transitiveReferences.ts | 2 ++ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index 16e6e42272e..f60641fe0cf 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -394,7 +394,7 @@ namespace ts { const projectStatus = createFileMap(toPath); const missingRoots = createMap(); let globalDependencyGraph: DependencyGraph | undefined; - const writeFileName = (s: string) => host.trace && host.trace(s); + const writeFileName = host.trace ? (s: string) => host.trace!(s) : undefined; let readFileWithCache = (f: string) => host.readFile(f); let projectCompilerOptions = baseCompilerOptions; const compilerHost = createCompilerHostFromProgramHost(host, () => projectCompilerOptions); @@ -1129,7 +1129,7 @@ namespace ts { let declDiagnostics: Diagnostic[] | undefined; const reportDeclarationDiagnostics = (d: Diagnostic) => (declDiagnostics || (declDiagnostics = [])).push(d); const outputFiles: OutputFile[] = []; - emitFilesAndReportErrors(program, reportDeclarationDiagnostics, writeFileName, /*reportSummary*/ undefined, (name, text, writeByteOrderMark) => outputFiles.push({ name, text, writeByteOrderMark })); + emitFilesAndReportErrors(program, reportDeclarationDiagnostics, /*writeFileName*/ undefined, /*reportSummary*/ undefined, (name, text, writeByteOrderMark) => outputFiles.push({ name, text, writeByteOrderMark })); // Don't emit .d.ts if there are decl file errors if (declDiagnostics) { program.restoreState(); @@ -1138,7 +1138,7 @@ namespace ts { // Actual Emit const emitterDiagnostics = createDiagnosticCollection(); - const emittedOutputs = createFileMap(toPath as ToPath); + const emittedOutputs = createFileMap(toPath as ToPath); outputFiles.forEach(({ name, text, writeByteOrderMark }) => { let priorChangeTime: Date | undefined; if (!anyDtsChanged && isDeclarationFile(name)) { @@ -1152,7 +1152,7 @@ namespace ts { } } - emittedOutputs.setValue(name, true); + emittedOutputs.setValue(name, name); writeFile(compilerHost, emitterDiagnostics, name, text, writeByteOrderMark); if (priorChangeTime !== undefined) { newestDeclarationFileContentChangedTime = newer(priorChangeTime, newestDeclarationFileContentChangedTime); @@ -1165,6 +1165,11 @@ namespace ts { return buildErrors(emitDiagnostics, BuildResultFlags.EmitErrors, "Emit"); } + if (writeFileName) { + emittedOutputs.forEach(name => listEmittedFile(configFile, name)); + listFiles(program, writeFileName); + } + // Update time stamps for rest of the outputs newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker(configFile, newestDeclarationFileContentChangedTime, Diagnostics.Updating_unchanged_output_timestamps_of_project_0, emittedOutputs); @@ -1182,6 +1187,8 @@ namespace ts { function buildErrors(diagnostics: ReadonlyArray, errorFlags: BuildResultFlags, errorType: string) { resultFlags |= errorFlags; reportAndStoreErrors(proj, diagnostics); + // List files if any other build error using program (emit errors already report files) + if (writeFileName) listFiles(program, writeFileName); projectStatus.setValue(proj, { type: UpToDateStatusType.Unbuildable, reason: `${errorType} errors` }); afterProgramCreate(proj, program); projectCompilerOptions = baseCompilerOptions; @@ -1189,6 +1196,12 @@ namespace ts { } } + function listEmittedFile(proj: ParsedCommandLine, file: string) { + if (writeFileName && proj.options.listEmittedFiles) { + writeFileName(`TSFILE: ${file}`); + } + } + function afterProgramCreate(proj: ResolvedConfigFileName, program: T) { if (host.afterProgramEmitAndDiagnostics) { host.afterProgramEmitAndDiagnostics(program); @@ -1229,9 +1242,9 @@ namespace ts { // Actual Emit Debug.assert(!!outputFiles.length); const emitterDiagnostics = createDiagnosticCollection(); - const emittedOutputs = createFileMap(toPath as ToPath); + const emittedOutputs = createFileMap(toPath as ToPath); outputFiles.forEach(({ name, text, writeByteOrderMark }) => { - emittedOutputs.setValue(name, true); + emittedOutputs.setValue(name, name); writeFile(compilerHost, emitterDiagnostics, name, text, writeByteOrderMark); }); const emitDiagnostics = emitterDiagnostics.getDiagnostics(); @@ -1242,6 +1255,10 @@ namespace ts { return BuildResultFlags.DeclarationOutputUnchanged | BuildResultFlags.EmitErrors; } + if (writeFileName) { + emittedOutputs.forEach(name => listEmittedFile(config, name)); + } + // Update timestamps for dts const newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker(config, minimumDate, Diagnostics.Updating_unchanged_output_timestamps_of_project_0, emittedOutputs); @@ -1270,7 +1287,7 @@ namespace ts { projectStatus.setValue(proj.options.configFilePath as ResolvedConfigFilePath, status); } - function updateOutputTimestampsWorker(proj: ParsedCommandLine, priorNewestUpdateTime: Date, verboseMessage: DiagnosticMessage, skipOutputs?: FileMap) { + function updateOutputTimestampsWorker(proj: ParsedCommandLine, priorNewestUpdateTime: Date, verboseMessage: DiagnosticMessage, skipOutputs?: FileMap) { const outputs = getAllProjectOutputs(proj, !host.useCaseSensitiveFileNames()); if (!skipOutputs || outputs.length !== skipOutputs.getSize()) { if (options.verbose) { @@ -1287,9 +1304,7 @@ namespace ts { } host.setModifiedTime(file, now); - if (proj.options.listEmittedFiles) { - writeFileName(`TSFILE: ${file}`); - } + listEmittedFile(proj, file); } } diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 9b08c54222f..f9bf2a8468d 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -121,6 +121,14 @@ namespace ts { emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; } + export function listFiles(program: ProgramToEmitFilesAndReportErrors, writeFileName: (s: string) => void) { + if (program.getCompilerOptions().listFiles) { + forEach(program.getSourceFiles(), file => { + writeFileName(file.fileName); + }); + } + } + /** * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options */ @@ -152,12 +160,7 @@ namespace ts { const filepath = getNormalizedAbsolutePath(file, currentDir); writeFileName(`TSFILE: ${filepath}`); }); - - if (program.getCompilerOptions().listFiles) { - forEach(program.getSourceFiles(), file => { - writeFileName(file.fileName); - }); - } + listFiles(program, writeFileName); } if (reportSummary) { diff --git a/src/testRunner/unittests/tsbuild/sample.ts b/src/testRunner/unittests/tsbuild/sample.ts index 6d128b348cc..588eb256eda 100644 --- a/src/testRunner/unittests/tsbuild/sample.ts +++ b/src/testRunner/unittests/tsbuild/sample.ts @@ -427,14 +427,14 @@ export class cNew {}`); builder.buildAllProjects(); assert.deepEqual(host.traces, [ "TSFILE: /src/core/anotherModule.js", - "TSFILE: /src/core/anotherModule.d.ts", "TSFILE: /src/core/anotherModule.d.ts.map", + "TSFILE: /src/core/anotherModule.d.ts", "TSFILE: /src/core/index.js", - "TSFILE: /src/core/index.d.ts", "TSFILE: /src/core/index.d.ts.map", + "TSFILE: /src/core/index.d.ts", "TSFILE: /src/core/tsconfig.tsbuildinfo", - "TSFILE: /src/logic/index.js", "TSFILE: /src/logic/index.js.map", + "TSFILE: /src/logic/index.js", "TSFILE: /src/logic/index.d.ts", "TSFILE: /src/logic/tsconfig.tsbuildinfo", "TSFILE: /src/tests/index.js", diff --git a/src/testRunner/unittests/tsbuild/transitiveReferences.ts b/src/testRunner/unittests/tsbuild/transitiveReferences.ts index 201c89c7b5b..7944d1fda09 100644 --- a/src/testRunner/unittests/tsbuild/transitiveReferences.ts +++ b/src/testRunner/unittests/tsbuild/transitiveReferences.ts @@ -65,6 +65,8 @@ export const b = new A();`); const expectedFileTraces = [ ...getLibs(), "/src/a.ts", + ...getLibs(), + "/src/b.ts" ]; verifyBuild(fs => modifyFsBTsToNonRelativeImport(fs, "node"), allExpectedOutputs,