@@ -17,6 +17,7 @@ import { ExtractorContext } from '../ExtractorContext';
1717import { ILogger } from './ILogger' ;
1818import ApiJsonGenerator from '../generators/ApiJsonGenerator' ;
1919import ApiFileGenerator from '../generators/ApiFileGenerator' ;
20+ import { MonitoredLogger } from './MonitoredLogger' ;
2021
2122/**
2223 * Options for {@link Extractor.analyzeProject}.
@@ -79,11 +80,11 @@ export class Extractor {
7980 logError : ( message : string ) => console . error ( colors . red ( message ) )
8081 } ;
8182
82- private _config : IExtractorConfig ;
83- private _program : ts . Program ;
84- private _localBuild : boolean ;
85- private _logger : ILogger ;
86- private _absoluteRootFolder : string ;
83+ private readonly _config : IExtractorConfig ;
84+ private readonly _program : ts . Program ;
85+ private readonly _localBuild : boolean ;
86+ private readonly _monitoredLogger : MonitoredLogger ;
87+ private readonly _absoluteRootFolder : string ;
8788
8889 private static _applyConfigDefaults ( config : IExtractorConfig ) : IExtractorConfig {
8990 // Use the provided config to override the defaults
@@ -93,17 +94,19 @@ export class Extractor {
9394 return normalized ;
9495 }
9596
96- public constructor ( config : IExtractorConfig , options ?: IExtractorOptions ) {
97+ public constructor ( config : IExtractorConfig , options ?: IExtractorOptions ) {
98+ let mergedLogger : ILogger ;
9799 if ( options && options . customLogger ) {
98- this . _logger = lodash . merge ( lodash . cloneDeep ( Extractor . _defaultLogger ) ,
100+ mergedLogger = lodash . merge ( lodash . cloneDeep ( Extractor . _defaultLogger ) ,
99101 options . customLogger ) ;
100102 } else {
101- this . _logger = Extractor . _defaultLogger ;
103+ mergedLogger = Extractor . _defaultLogger ;
102104 }
105+ this . _monitoredLogger = new MonitoredLogger ( mergedLogger ) ;
103106
104107 this . _config = Extractor . _applyConfigDefaults ( config ) ;
105108
106- this . _logger . logVerbose ( 'API Extractor Config: ' + JSON . stringify ( this . _config ) ) ;
109+ this . _monitoredLogger . logVerbose ( 'API Extractor Config: ' + JSON . stringify ( this . _config ) ) ;
107110
108111 if ( ! options ) {
109112 options = { } ;
@@ -160,6 +163,9 @@ export class Extractor {
160163
161164 /**
162165 * Invokes the API Extractor engine, using the configuration that was passed to the constructor.
166+ * @param options - provides additional runtime state that is NOT part of the API Extractor
167+ * config file.
168+ * @returns true if there were no errors; false if the tool chain should fail the build
163169 */
164170 public analyzeProject ( options ?: IAnalyzeProjectOptions ) : void {
165171 if ( ! options ) {
@@ -178,7 +184,7 @@ export class Extractor {
178184 const context : ExtractorContext = new ExtractorContext ( {
179185 program : this . _program ,
180186 entryPointFile : path . resolve ( this . _absoluteRootFolder , projectConfig . entryPointSourceFile ) ,
181- logger : this . _logger ,
187+ logger : this . _monitoredLogger ,
182188 policies : this . _config . policies
183189 } ) ;
184190
@@ -199,7 +205,7 @@ export class Extractor {
199205 const jsonGenerator : ApiJsonGenerator = new ApiJsonGenerator ( ) ;
200206 const apiJsonFilename : string = path . join ( outputFolder , packageBaseName + '.api.json' ) ;
201207
202- this . _logger . logVerbose ( 'Writing: ' + apiJsonFilename ) ;
208+ this . _monitoredLogger . logVerbose ( 'Writing: ' + apiJsonFilename ) ;
203209 jsonGenerator . writeJsonFile ( apiJsonFilename , context ) ;
204210 }
205211
@@ -228,27 +234,28 @@ export class Extractor {
228234 if ( ! ApiFileGenerator . areEquivalentApiFileContents ( actualApiReviewContent , expectedApiReviewContent ) ) {
229235 if ( ! this . _localBuild ) {
230236 // For production, issue a warning that will break the CI build.
231- this . _logger . logWarning ( 'You have changed the public API signature for this project.'
237+ this . _monitoredLogger . logWarning ( 'You have changed the public API signature for this project.'
232238 // @microsoft /gulp-core-build seems to run JSON.stringify() on the error messages for some reason,
233239 // so try to avoid escaped characters:
234240 + ` Please overwrite ${ expectedApiReviewShortPath } with a`
235241 + ` copy of ${ actualApiReviewShortPath } `
236242 + ' and then request an API review. See the Git repository README.md for more info.' ) ;
237243 } else {
238244 // For a local build, just copy the file automatically.
239- this . _logger . logWarning ( 'You have changed the public API signature for this project.'
245+ this . _monitoredLogger . logWarning ( 'You have changed the public API signature for this project.'
240246 + ` Updating ${ expectedApiReviewShortPath } ` ) ;
241247
242248 fsx . writeFileSync ( expectedApiReviewPath , actualApiReviewContent ) ;
243249 }
244250 } else {
245- this . _logger . logVerbose ( `The API signature is up to date: ${ actualApiReviewShortPath } ` ) ;
251+ this . _monitoredLogger . logVerbose ( `The API signature is up to date: ${ actualApiReviewShortPath } ` ) ;
246252 }
247253 } else {
248254 // NOTE: This warning seems like a nuisance, but it has caught genuine mistakes.
249255 // For example, when projects were moved into category folders, the relative path for
250256 // the API review files ended up in the wrong place.
251- this . _logger . logError ( `The API review file has not been set up. Do this by copying ${ actualApiReviewShortPath } `
257+ this . _monitoredLogger . logError ( `The API review file has not been set up.`
258+ + ` Do this by copying ${ actualApiReviewShortPath } `
252259 + ` to ${ expectedApiReviewShortPath } and committing it.` ) ;
253260 }
254261 }
0 commit comments