Skip to content

Commit 5c18513

Browse files
committed
Make SolutionBuilder as Public API
1 parent 3da4796 commit 5c18513

5 files changed

Lines changed: 145 additions & 68 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,7 @@ namespace ts {
10221022
}
10231023
}
10241024

1025-
/* @internal */
1026-
export interface OptionsBase {
1025+
interface OptionsBase {
10271026
[option: string]: CompilerOptionsValue | undefined;
10281027
}
10291028

src/compiler/tsbuild.ts

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,5 @@
1-
// Currently we do not want to expose API for build, we should work out the API, and then expose it just like we did for builder/watch
21
/*@internal*/
32
namespace ts {
4-
const minimumDate = new Date(-8640000000000000);
5-
const maximumDate = new Date(8640000000000000);
6-
7-
export interface BuildHost {
8-
verbose(diag: DiagnosticMessage, ...args: string[]): void;
9-
error(diag: DiagnosticMessage, ...args: string[]): void;
10-
errorDiagnostic(diag: Diagnostic): void;
11-
message(diag: DiagnosticMessage, ...args: string[]): void;
12-
}
13-
14-
export interface BuildOptions extends OptionsBase {
15-
dry?: boolean;
16-
force?: boolean;
17-
verbose?: boolean;
18-
19-
/*@internal*/ clean?: boolean;
20-
/*@internal*/ watch?: boolean;
21-
/*@internal*/ help?: boolean;
22-
23-
preserveWatchOutput?: boolean;
24-
listEmittedFiles?: boolean;
25-
listFiles?: boolean;
26-
pretty?: boolean;
27-
incremental?: boolean;
28-
29-
traceResolution?: boolean;
30-
/* @internal */ diagnostics?: boolean;
31-
/* @internal */ extendedDiagnostics?: boolean;
32-
}
33-
34-
enum BuildResultFlags {
35-
None = 0,
36-
37-
/**
38-
* No errors of any kind occurred during build
39-
*/
40-
Success = 1 << 0,
41-
/**
42-
* None of the .d.ts files emitted by this build were
43-
* different from the existing files on disk
44-
*/
45-
DeclarationOutputUnchanged = 1 << 1,
46-
47-
ConfigFileErrors = 1 << 2,
48-
SyntaxErrors = 1 << 3,
49-
TypeErrors = 1 << 4,
50-
DeclarationEmitErrors = 1 << 5,
51-
EmitErrors = 1 << 6,
52-
53-
AnyErrors = ConfigFileErrors | SyntaxErrors | TypeErrors | DeclarationEmitErrors | EmitErrors
54-
}
55-
563
export enum UpToDateStatusType {
574
Unbuildable,
585
UpToDate,
@@ -194,6 +141,63 @@ namespace ts {
194141
}
195142
}
196143

144+
export function resolveConfigFileProjectName(project: string): ResolvedConfigFileName {
145+
if (fileExtensionIs(project, Extension.Json)) {
146+
return project as ResolvedConfigFileName;
147+
}
148+
149+
return combinePaths(project, "tsconfig.json") as ResolvedConfigFileName;
150+
}
151+
}
152+
153+
namespace ts {
154+
const minimumDate = new Date(-8640000000000000);
155+
const maximumDate = new Date(8640000000000000);
156+
157+
export interface BuildOptions {
158+
dry?: boolean;
159+
force?: boolean;
160+
verbose?: boolean;
161+
162+
/*@internal*/ clean?: boolean;
163+
/*@internal*/ watch?: boolean;
164+
/*@internal*/ help?: boolean;
165+
166+
preserveWatchOutput?: boolean;
167+
listEmittedFiles?: boolean;
168+
listFiles?: boolean;
169+
pretty?: boolean;
170+
incremental?: boolean;
171+
172+
traceResolution?: boolean;
173+
/* @internal */ diagnostics?: boolean;
174+
/* @internal */ extendedDiagnostics?: boolean;
175+
176+
[option: string]: CompilerOptionsValue | undefined;
177+
}
178+
179+
enum BuildResultFlags {
180+
None = 0,
181+
182+
/**
183+
* No errors of any kind occurred during build
184+
*/
185+
Success = 1 << 0,
186+
/**
187+
* None of the .d.ts files emitted by this build were
188+
* different from the existing files on disk
189+
*/
190+
DeclarationOutputUnchanged = 1 << 1,
191+
192+
ConfigFileErrors = 1 << 2,
193+
SyntaxErrors = 1 << 3,
194+
TypeErrors = 1 << 4,
195+
DeclarationEmitErrors = 1 << 5,
196+
EmitErrors = 1 << 6,
197+
198+
AnyErrors = ConfigFileErrors | SyntaxErrors | TypeErrors | DeclarationEmitErrors | EmitErrors
199+
}
200+
197201
type ResolvedConfigFilePath = ResolvedConfigFileName & Path;
198202
interface FileMap<T, U extends Path = Path> extends Map<T> {
199203
get(key: U): T | undefined;
@@ -231,6 +235,8 @@ namespace ts {
231235
return fileExtensionIs(fileName, Extension.Dts);
232236
}
233237

238+
export type ReportEmitErrorSummary = (errorCount: number) => void;
239+
234240
export interface SolutionBuilderHostBase<T extends BuilderProgram> extends ProgramHost<T> {
235241
getModifiedTime(fileName: string): Date | undefined;
236242
setModifiedTime(fileName: string, date: Date): void;
@@ -1527,15 +1533,7 @@ namespace ts {
15271533
}
15281534
}
15291535

1530-
export function resolveConfigFileProjectName(project: string): ResolvedConfigFileName {
1531-
if (fileExtensionIs(project, Extension.Json)) {
1532-
return project as ResolvedConfigFileName;
1533-
}
1534-
1535-
return combinePaths(project, "tsconfig.json") as ResolvedConfigFileName;
1536-
}
1537-
1538-
export function formatUpToDateStatus<T>(configFileName: string, status: UpToDateStatus, relName: (fileName: string) => string, formatMessage: (message: DiagnosticMessage, ...args: string[]) => T) {
1536+
function formatUpToDateStatus<T>(configFileName: string, status: UpToDateStatus, relName: (fileName: string) => string, formatMessage: (message: DiagnosticMessage, ...args: string[]) => T) {
15391537
switch (status.type) {
15401538
case UpToDateStatusType.OutOfDateWithSelf:
15411539
return formatMessage(Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2,

src/compiler/watch.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ namespace ts {
8888
return result;
8989
}
9090

91-
export type ReportEmitErrorSummary = (errorCount: number) => void;
92-
9391
export function getErrorCountForSummary(diagnostics: ReadonlyArray<Diagnostic>) {
9492
return countWhere(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
9593
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,8 @@ declare namespace ts {
19051905
enum ExitStatus {
19061906
Success = 0,
19071907
DiagnosticsPresent_OutputsSkipped = 1,
1908-
DiagnosticsPresent_OutputsGenerated = 2
1908+
DiagnosticsPresent_OutputsGenerated = 2,
1909+
InvalidProject_OutputsSkipped = 3
19091910
}
19101911
interface EmitResult {
19111912
emitSkipped: boolean;
@@ -4555,6 +4556,46 @@ declare namespace ts {
45554556
*/
45564557
function createWatchProgram<T extends BuilderProgram>(host: WatchCompilerHostOfConfigFile<T>): WatchOfConfigFile<T>;
45574558
}
4559+
declare namespace ts {
4560+
interface BuildOptions {
4561+
dry?: boolean;
4562+
force?: boolean;
4563+
verbose?: boolean;
4564+
preserveWatchOutput?: boolean;
4565+
listEmittedFiles?: boolean;
4566+
listFiles?: boolean;
4567+
pretty?: boolean;
4568+
incremental?: boolean;
4569+
traceResolution?: boolean;
4570+
[option: string]: CompilerOptionsValue | undefined;
4571+
}
4572+
type ReportEmitErrorSummary = (errorCount: number) => void;
4573+
interface SolutionBuilderHostBase<T extends BuilderProgram> extends ProgramHost<T> {
4574+
getModifiedTime(fileName: string): Date | undefined;
4575+
setModifiedTime(fileName: string, date: Date): void;
4576+
deleteFile(fileName: string): void;
4577+
reportDiagnostic: DiagnosticReporter;
4578+
reportSolutionBuilderStatus: DiagnosticReporter;
4579+
afterProgramEmitAndDiagnostics?(program: T): void;
4580+
}
4581+
interface SolutionBuilderHost<T extends BuilderProgram> extends SolutionBuilderHostBase<T> {
4582+
reportErrorSummary?: ReportEmitErrorSummary;
4583+
}
4584+
interface SolutionBuilderWithWatchHost<T extends BuilderProgram> extends SolutionBuilderHostBase<T>, WatchHost {
4585+
}
4586+
interface SolutionBuilder {
4587+
build(project?: string, cancellationToken?: CancellationToken): ExitStatus;
4588+
clean(project?: string): ExitStatus;
4589+
}
4590+
/**
4591+
* Create a function that reports watch status by writing to the system and handles the formating of the diagnostic
4592+
*/
4593+
function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter;
4594+
function createSolutionBuilderHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost<T>;
4595+
function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost<T>;
4596+
function createSolutionBuilder<T extends BuilderProgram>(host: SolutionBuilderHost<T>, rootNames: ReadonlyArray<string>, defaultOptions: BuildOptions): SolutionBuilder;
4597+
function createSolutionBuilderWithWatch<T extends BuilderProgram>(host: SolutionBuilderWithWatchHost<T>, rootNames: ReadonlyArray<string>, defaultOptions: BuildOptions): SolutionBuilder;
4598+
}
45584599
declare namespace ts.server {
45594600
type ActionSet = "action::set";
45604601
type ActionInvalidate = "action::invalidate";

tests/baselines/reference/api/typescript.d.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,8 @@ declare namespace ts {
19051905
enum ExitStatus {
19061906
Success = 0,
19071907
DiagnosticsPresent_OutputsSkipped = 1,
1908-
DiagnosticsPresent_OutputsGenerated = 2
1908+
DiagnosticsPresent_OutputsGenerated = 2,
1909+
InvalidProject_OutputsSkipped = 3
19091910
}
19101911
interface EmitResult {
19111912
emitSkipped: boolean;
@@ -4555,6 +4556,46 @@ declare namespace ts {
45554556
*/
45564557
function createWatchProgram<T extends BuilderProgram>(host: WatchCompilerHostOfConfigFile<T>): WatchOfConfigFile<T>;
45574558
}
4559+
declare namespace ts {
4560+
interface BuildOptions {
4561+
dry?: boolean;
4562+
force?: boolean;
4563+
verbose?: boolean;
4564+
preserveWatchOutput?: boolean;
4565+
listEmittedFiles?: boolean;
4566+
listFiles?: boolean;
4567+
pretty?: boolean;
4568+
incremental?: boolean;
4569+
traceResolution?: boolean;
4570+
[option: string]: CompilerOptionsValue | undefined;
4571+
}
4572+
type ReportEmitErrorSummary = (errorCount: number) => void;
4573+
interface SolutionBuilderHostBase<T extends BuilderProgram> extends ProgramHost<T> {
4574+
getModifiedTime(fileName: string): Date | undefined;
4575+
setModifiedTime(fileName: string, date: Date): void;
4576+
deleteFile(fileName: string): void;
4577+
reportDiagnostic: DiagnosticReporter;
4578+
reportSolutionBuilderStatus: DiagnosticReporter;
4579+
afterProgramEmitAndDiagnostics?(program: T): void;
4580+
}
4581+
interface SolutionBuilderHost<T extends BuilderProgram> extends SolutionBuilderHostBase<T> {
4582+
reportErrorSummary?: ReportEmitErrorSummary;
4583+
}
4584+
interface SolutionBuilderWithWatchHost<T extends BuilderProgram> extends SolutionBuilderHostBase<T>, WatchHost {
4585+
}
4586+
interface SolutionBuilder {
4587+
build(project?: string, cancellationToken?: CancellationToken): ExitStatus;
4588+
clean(project?: string): ExitStatus;
4589+
}
4590+
/**
4591+
* Create a function that reports watch status by writing to the system and handles the formating of the diagnostic
4592+
*/
4593+
function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter;
4594+
function createSolutionBuilderHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost<T>;
4595+
function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost<T>;
4596+
function createSolutionBuilder<T extends BuilderProgram>(host: SolutionBuilderHost<T>, rootNames: ReadonlyArray<string>, defaultOptions: BuildOptions): SolutionBuilder;
4597+
function createSolutionBuilderWithWatch<T extends BuilderProgram>(host: SolutionBuilderWithWatchHost<T>, rootNames: ReadonlyArray<string>, defaultOptions: BuildOptions): SolutionBuilder;
4598+
}
45584599
declare namespace ts.server {
45594600
type ActionSet = "action::set";
45604601
type ActionInvalidate = "action::invalidate";

0 commit comments

Comments
 (0)