Skip to content

Commit 99d357d

Browse files
committed
Enable statistics reporting per program through temporary build api
1 parent ca7f78b commit 99d357d

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src/compiler/commandLineParser.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ namespace ts {
119119
category: Diagnostics.Advanced_Options,
120120
description: Diagnostics.Enable_tracing_of_the_name_resolution_process
121121
},
122+
{
123+
name: "diagnostics",
124+
type: "boolean",
125+
category: Diagnostics.Advanced_Options,
126+
description: Diagnostics.Show_diagnostic_information
127+
},
128+
{
129+
name: "extendedDiagnostics",
130+
type: "boolean",
131+
category: Diagnostics.Advanced_Options,
132+
description: Diagnostics.Show_verbose_diagnostic_information
133+
},
122134
];
123135

124136
/* @internal */
@@ -592,18 +604,6 @@ namespace ts {
592604
category: Diagnostics.Advanced_Options,
593605
description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h
594606
},
595-
{
596-
name: "diagnostics",
597-
type: "boolean",
598-
category: Diagnostics.Advanced_Options,
599-
description: Diagnostics.Show_diagnostic_information
600-
},
601-
{
602-
name: "extendedDiagnostics",
603-
type: "boolean",
604-
category: Diagnostics.Advanced_Options,
605-
description: Diagnostics.Show_verbose_diagnostic_information
606-
},
607607
{
608608
name: "resolveJsonModule",
609609
type: "boolean",

src/compiler/tsbuild.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace ts {
3232
pretty?: boolean;
3333

3434
traceResolution?: boolean;
35+
/* @internal */ diagnostics?: boolean;
36+
/* @internal */ extendedDiagnostics?: boolean;
3537
}
3638

3739
enum BuildResultFlags {
@@ -326,6 +328,11 @@ namespace ts {
326328

327329
reportDiagnostic: DiagnosticReporter; // Technically we want to move it out and allow steps of actions on Solution, but for now just merge stuff in build host here
328330
reportSolutionBuilderStatus: DiagnosticReporter;
331+
332+
// TODO: To do better with watch mode and normal build mode api that creates program and emits files
333+
// This currently helps enable --diagnostics and --extendedDiagnostics
334+
beforeCreateProgram?(options: CompilerOptions): void;
335+
afterProgramEmitAndDiagnostics?(program: Program): void;
329336
}
330337

331338
export interface SolutionBuilderHost extends SolutionBuilderHostBase {
@@ -997,7 +1004,6 @@ namespace ts {
9971004
}
9981005
}
9991006

1000-
10011007
function buildSingleProject(proj: ResolvedConfigFileName): BuildResultFlags {
10021008
if (options.dry) {
10031009
reportStatus(Diagnostics.A_non_dry_build_would_build_project_0, proj);
@@ -1030,6 +1036,9 @@ namespace ts {
10301036
options: configFile.options,
10311037
configFileParsingDiagnostics: configFile.errors
10321038
};
1039+
if (host.beforeCreateProgram) {
1040+
host.beforeCreateProgram(options);
1041+
}
10331042
const program = createProgram(programOptions);
10341043

10351044
// Don't emit anything in the presence of syntactic errors or options diagnostics
@@ -1089,12 +1098,18 @@ namespace ts {
10891098
};
10901099
diagnostics.removeKey(proj);
10911100
projectStatus.setValue(proj, status);
1101+
if (host.afterProgramEmitAndDiagnostics) {
1102+
host.afterProgramEmitAndDiagnostics(program);
1103+
}
10921104
return resultFlags;
10931105

10941106
function buildErrors(diagnostics: ReadonlyArray<Diagnostic>, errorFlags: BuildResultFlags, errorType: string) {
10951107
resultFlags |= errorFlags;
10961108
reportAndStoreErrors(proj, diagnostics);
10971109
projectStatus.setValue(proj, { type: UpToDateStatusType.Unbuildable, reason: `${errorType} errors` });
1110+
if (host.afterProgramEmitAndDiagnostics) {
1111+
host.afterProgramEmitAndDiagnostics(program);
1112+
}
10981113
return resultFlags;
10991114
}
11001115
}

src/tsc/tsc.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,14 @@ namespace ts {
199199
reportWatchModeWithoutSysSupport();
200200
}
201201

202-
// TODO: change this to host if watch => watchHost otherwiue without wathc
203-
const builder = createSolutionBuilder(buildOptions.watch ?
202+
// TODO: change this to host if watch => watchHost otherwiue without watch
203+
const buildHost = buildOptions.watch ?
204204
createSolutionBuilderWithWatchHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createWatchStatusReporter()) :
205-
createSolutionBuilderHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createReportErrorSummary(buildOptions)),
206-
projects, buildOptions);
205+
createSolutionBuilderHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createReportErrorSummary(buildOptions));
206+
buildHost.beforeCreateProgram = enableStatistics;
207+
buildHost.afterProgramEmitAndDiagnostics = reportStatistics;
208+
209+
const builder = createSolutionBuilder(buildHost, projects, buildOptions);
207210
if (buildOptions.clean) {
208211
return sys.exit(builder.cleanAllProjects());
209212
}

0 commit comments

Comments
 (0)