Skip to content

Commit 3fdd66b

Browse files
committed
Report program's source files even when there are errors when building using --build mode
1 parent 0830292 commit 3fdd66b

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

src/compiler/tsbuild.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ namespace ts {
394394
const projectStatus = createFileMap<UpToDateStatus>(toPath);
395395
const missingRoots = createMap<true>();
396396
let globalDependencyGraph: DependencyGraph | undefined;
397-
const writeFileName = (s: string) => host.trace && host.trace(s);
397+
const writeFileName = host.trace ? (s: string) => host.trace!(s) : undefined;
398398
let readFileWithCache = (f: string) => host.readFile(f);
399399
let projectCompilerOptions = baseCompilerOptions;
400400
const compilerHost = createCompilerHostFromProgramHost(host, () => projectCompilerOptions);
@@ -1129,7 +1129,7 @@ namespace ts {
11291129
let declDiagnostics: Diagnostic[] | undefined;
11301130
const reportDeclarationDiagnostics = (d: Diagnostic) => (declDiagnostics || (declDiagnostics = [])).push(d);
11311131
const outputFiles: OutputFile[] = [];
1132-
emitFilesAndReportErrors(program, reportDeclarationDiagnostics, writeFileName, /*reportSummary*/ undefined, (name, text, writeByteOrderMark) => outputFiles.push({ name, text, writeByteOrderMark }));
1132+
emitFilesAndReportErrors(program, reportDeclarationDiagnostics, /*writeFileName*/ undefined, /*reportSummary*/ undefined, (name, text, writeByteOrderMark) => outputFiles.push({ name, text, writeByteOrderMark }));
11331133
// Don't emit .d.ts if there are decl file errors
11341134
if (declDiagnostics) {
11351135
program.restoreState();
@@ -1138,7 +1138,7 @@ namespace ts {
11381138

11391139
// Actual Emit
11401140
const emitterDiagnostics = createDiagnosticCollection();
1141-
const emittedOutputs = createFileMap<true>(toPath as ToPath);
1141+
const emittedOutputs = createFileMap<string>(toPath as ToPath);
11421142
outputFiles.forEach(({ name, text, writeByteOrderMark }) => {
11431143
let priorChangeTime: Date | undefined;
11441144
if (!anyDtsChanged && isDeclarationFile(name)) {
@@ -1152,7 +1152,7 @@ namespace ts {
11521152
}
11531153
}
11541154

1155-
emittedOutputs.setValue(name, true);
1155+
emittedOutputs.setValue(name, name);
11561156
writeFile(compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
11571157
if (priorChangeTime !== undefined) {
11581158
newestDeclarationFileContentChangedTime = newer(priorChangeTime, newestDeclarationFileContentChangedTime);
@@ -1165,6 +1165,11 @@ namespace ts {
11651165
return buildErrors(emitDiagnostics, BuildResultFlags.EmitErrors, "Emit");
11661166
}
11671167

1168+
if (writeFileName) {
1169+
emittedOutputs.forEach(name => listEmittedFile(configFile, name));
1170+
listFiles(program, writeFileName);
1171+
}
1172+
11681173
// Update time stamps for rest of the outputs
11691174
newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker(configFile, newestDeclarationFileContentChangedTime, Diagnostics.Updating_unchanged_output_timestamps_of_project_0, emittedOutputs);
11701175

@@ -1182,13 +1187,21 @@ namespace ts {
11821187
function buildErrors(diagnostics: ReadonlyArray<Diagnostic>, errorFlags: BuildResultFlags, errorType: string) {
11831188
resultFlags |= errorFlags;
11841189
reportAndStoreErrors(proj, diagnostics);
1190+
// List files if any other build error using program (emit errors already report files)
1191+
if (writeFileName) listFiles(program, writeFileName);
11851192
projectStatus.setValue(proj, { type: UpToDateStatusType.Unbuildable, reason: `${errorType} errors` });
11861193
afterProgramCreate(proj, program);
11871194
projectCompilerOptions = baseCompilerOptions;
11881195
return resultFlags;
11891196
}
11901197
}
11911198

1199+
function listEmittedFile(proj: ParsedCommandLine, file: string) {
1200+
if (writeFileName && proj.options.listEmittedFiles) {
1201+
writeFileName(`TSFILE: ${file}`);
1202+
}
1203+
}
1204+
11921205
function afterProgramCreate(proj: ResolvedConfigFileName, program: T) {
11931206
if (host.afterProgramEmitAndDiagnostics) {
11941207
host.afterProgramEmitAndDiagnostics(program);
@@ -1229,9 +1242,9 @@ namespace ts {
12291242
// Actual Emit
12301243
Debug.assert(!!outputFiles.length);
12311244
const emitterDiagnostics = createDiagnosticCollection();
1232-
const emittedOutputs = createFileMap<true>(toPath as ToPath);
1245+
const emittedOutputs = createFileMap<string>(toPath as ToPath);
12331246
outputFiles.forEach(({ name, text, writeByteOrderMark }) => {
1234-
emittedOutputs.setValue(name, true);
1247+
emittedOutputs.setValue(name, name);
12351248
writeFile(compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
12361249
});
12371250
const emitDiagnostics = emitterDiagnostics.getDiagnostics();
@@ -1242,6 +1255,10 @@ namespace ts {
12421255
return BuildResultFlags.DeclarationOutputUnchanged | BuildResultFlags.EmitErrors;
12431256
}
12441257

1258+
if (writeFileName) {
1259+
emittedOutputs.forEach(name => listEmittedFile(config, name));
1260+
}
1261+
12451262
// Update timestamps for dts
12461263
const newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker(config, minimumDate, Diagnostics.Updating_unchanged_output_timestamps_of_project_0, emittedOutputs);
12471264

@@ -1270,7 +1287,7 @@ namespace ts {
12701287
projectStatus.setValue(proj.options.configFilePath as ResolvedConfigFilePath, status);
12711288
}
12721289

1273-
function updateOutputTimestampsWorker(proj: ParsedCommandLine, priorNewestUpdateTime: Date, verboseMessage: DiagnosticMessage, skipOutputs?: FileMap<true>) {
1290+
function updateOutputTimestampsWorker(proj: ParsedCommandLine, priorNewestUpdateTime: Date, verboseMessage: DiagnosticMessage, skipOutputs?: FileMap<string>) {
12741291
const outputs = getAllProjectOutputs(proj, !host.useCaseSensitiveFileNames());
12751292
if (!skipOutputs || outputs.length !== skipOutputs.getSize()) {
12761293
if (options.verbose) {
@@ -1287,9 +1304,7 @@ namespace ts {
12871304
}
12881305

12891306
host.setModifiedTime(file, now);
1290-
if (proj.options.listEmittedFiles) {
1291-
writeFileName(`TSFILE: ${file}`);
1292-
}
1307+
listEmittedFile(proj, file);
12931308
}
12941309
}
12951310

src/compiler/watch.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ namespace ts {
121121
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
122122
}
123123

124+
export function listFiles(program: ProgramToEmitFilesAndReportErrors, writeFileName: (s: string) => void) {
125+
if (program.getCompilerOptions().listFiles) {
126+
forEach(program.getSourceFiles(), file => {
127+
writeFileName(file.fileName);
128+
});
129+
}
130+
}
131+
124132
/**
125133
* Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options
126134
*/
@@ -152,12 +160,7 @@ namespace ts {
152160
const filepath = getNormalizedAbsolutePath(file, currentDir);
153161
writeFileName(`TSFILE: ${filepath}`);
154162
});
155-
156-
if (program.getCompilerOptions().listFiles) {
157-
forEach(program.getSourceFiles(), file => {
158-
writeFileName(file.fileName);
159-
});
160-
}
163+
listFiles(program, writeFileName);
161164
}
162165

163166
if (reportSummary) {

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,14 @@ export class cNew {}`);
427427
builder.buildAllProjects();
428428
assert.deepEqual(host.traces, [
429429
"TSFILE: /src/core/anotherModule.js",
430-
"TSFILE: /src/core/anotherModule.d.ts",
431430
"TSFILE: /src/core/anotherModule.d.ts.map",
431+
"TSFILE: /src/core/anotherModule.d.ts",
432432
"TSFILE: /src/core/index.js",
433-
"TSFILE: /src/core/index.d.ts",
434433
"TSFILE: /src/core/index.d.ts.map",
434+
"TSFILE: /src/core/index.d.ts",
435435
"TSFILE: /src/core/tsconfig.tsbuildinfo",
436-
"TSFILE: /src/logic/index.js",
437436
"TSFILE: /src/logic/index.js.map",
437+
"TSFILE: /src/logic/index.js",
438438
"TSFILE: /src/logic/index.d.ts",
439439
"TSFILE: /src/logic/tsconfig.tsbuildinfo",
440440
"TSFILE: /src/tests/index.js",

src/testRunner/unittests/tsbuild/transitiveReferences.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const b = new A();`);
6565
const expectedFileTraces = [
6666
...getLibs(),
6767
"/src/a.ts",
68+
...getLibs(),
69+
"/src/b.ts"
6870
];
6971
verifyBuild(fs => modifyFsBTsToNonRelativeImport(fs, "node"),
7072
allExpectedOutputs,

0 commit comments

Comments
 (0)