Skip to content

Commit f86866d

Browse files
committed
Extractor.processProject() returns false if there were errors or warnings; analyzeProject() is deprecated
1 parent deb0148 commit f86866d

6 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎apps/api-extractor/src/DebugRun.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const extractor: Extractor = new Extractor(
2626
}
2727
);
2828

29-
extractor.analyzeProject();
29+
if (!extractor.processProject()) {
30+
console.log('processProject() failed the build');
31+
} else {
32+
console.log('processProject() succeeded');
33+
}
3034

3135
console.log('DebugRun completed.');

‎apps/api-extractor/src/ExternalApiHelper.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export default class ExternalApiHelper {
6969
}
7070
});
7171

72-
extractor.analyzeProject();
72+
if (!extractor.processProject()) {
73+
throw new Error('API Extractor failed to process the input: ' + externalPackageFilePath);
74+
}
7375
}
7476
}

‎apps/api-extractor/src/cli/RunAction.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export class RunAction extends CommandLineAction {
8282
const extractor: Extractor = new Extractor(config, {
8383
localBuild: this._localParameter.value
8484
});
85-
extractor.analyzeProject();
85+
86+
if (!extractor.processProject()) {
87+
throw new Error('The build failed');
88+
}
8689
}
8790
}

‎apps/api-extractor/src/extractor/Extractor.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import ApiFileGenerator from '../generators/ApiFileGenerator';
2020
import { MonitoredLogger } from './MonitoredLogger';
2121

2222
/**
23-
* Options for {@link Extractor.analyzeProject}.
23+
* Options for {@link Extractor.processProject}.
2424
* @public
2525
*/
2626
export interface IAnalyzeProjectOptions {
@@ -161,13 +161,23 @@ export class Extractor {
161161
}
162162
}
163163

164+
/**
165+
* Invokes the API Extractor engine, using the configuration that was passed to the constructor.
166+
* @deprecated Use {@link Extractor.processProject} instead.
167+
*/
168+
public analyzeProject(options?: IAnalyzeProjectOptions): void {
169+
this.processProject(options);
170+
}
171+
164172
/**
165173
* Invokes the API Extractor engine, using the configuration that was passed to the constructor.
166174
* @param options - provides additional runtime state that is NOT part of the API Extractor
167175
* config file.
168-
* @returns true if there were no errors; false if the tool chain should fail the build
176+
* @returns true if there were no errors or warnings; false if the tool chain should fail the build
169177
*/
170-
public analyzeProject(options?: IAnalyzeProjectOptions): void {
178+
public processProject(options?: IAnalyzeProjectOptions): boolean {
179+
this._monitoredLogger.resetCounters();
180+
171181
if (!options) {
172182
options = { };
173183
}
@@ -259,6 +269,9 @@ export class Extractor {
259269
+ ` to ${expectedApiReviewShortPath} and committing it.`);
260270
}
261271
}
272+
273+
// If there were any errors or warnings, then fail the build
274+
return (this._monitoredLogger.errorCount + this._monitoredLogger.warningCount) === 0;
262275
}
263276

264277
private _getShortFilePath(absolutePath: string): string {

‎apps/api-extractor/src/extractor/MonitoredLogger.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ export class MonitoredLogger implements ILogger {
1010
/**
1111
* Number of calls to logError()
1212
*/
13-
public errorCount: number = 0;
13+
public errorCount: number;
1414

1515
/**
1616
* Number of calls to logWarning()
1717
*/
18-
public warningCount: number = 0;
18+
public warningCount: number;
1919

2020
/**
2121
* Number of calls to any logging method.
2222
*/
23-
public messageCount: number = 0;
23+
public messageCount: number;
2424

2525
private _innerLogger: ILogger;
2626

2727
constructor(logger: ILogger) {
2828
this._innerLogger = logger;
29+
this.resetCounters();
2930
}
3031

3132
public logVerbose(message: string): void {
@@ -49,4 +50,10 @@ export class MonitoredLogger implements ILogger {
4950
++this.errorCount;
5051
this._innerLogger.logVerbose(message);
5152
}
53+
54+
public resetCounters(): void {
55+
this.errorCount = 0;
56+
this.warningCount = 0;
57+
this.messageCount = 0;
58+
}
5259
}

‎common/reviews/api/api-extractor.api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ class ExternalApiHelper {
1313
// @public
1414
class Extractor {
1515
public constructor(config: IExtractorConfig, options?: IExtractorOptions);
16+
// @deprecated
1617
public analyzeProject(options?: IAnalyzeProjectOptions): void;
1718
public static jsonSchema: JsonSchema;
19+
public processProject(options?: IAnalyzeProjectOptions): boolean;
1820
}
1921

2022
// @public

0 commit comments

Comments
 (0)