Skip to content

Commit 181c72b

Browse files
committed
Rename ExtractorMessageLogLevel to ExtractorLogLevel and move it to its own source file
1 parent c349a4c commit 181c72b

6 files changed

Lines changed: 77 additions & 66 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
/**
5+
* Used with {@link IConfigMessageReportingRule.logLevel} and {@link IExtractorInvokeOptions.messageCallback}.
6+
*
7+
* @remarks
8+
* This is part of the {@link IConfigFile} structure.
9+
*
10+
* @public
11+
*/
12+
export const enum ExtractorLogLevel {
13+
/**
14+
* The message will be displayed as an error.
15+
*
16+
* @remarks
17+
* Errors typically cause the build to fail and return a nonzero exit code.
18+
*/
19+
Error = 'error',
20+
21+
/**
22+
* The message will be displayed as an warning.
23+
*
24+
* @remarks
25+
* Warnings typically cause a production build fail and return a nonzero exit code. For a non-production build
26+
* (e.g. using the `--local` option with `api-extractor run`), the warning is displayed but the build will not fail.
27+
*/
28+
Warning = 'warning',
29+
30+
/**
31+
* The message will be displayed as an informational message.
32+
*
33+
* @remarks
34+
* Informational messages may contain newlines to ensure nice formatting of the output,
35+
* however word-wrapping is the responsibility of the message handler.
36+
*/
37+
Info = 'info',
38+
39+
/**
40+
* The message will be displayed only when "verbose" output is requested, e.g. using the `--verbose`
41+
* command line option.
42+
*/
43+
Verbose = 'verbose',
44+
45+
/**
46+
* The message will be discarded entirely.
47+
*/
48+
None = 'none'
49+
}

apps/api-extractor/src/api/ExtractorMessage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as tsdoc from '@microsoft/tsdoc';
55
import * as path from 'path';
66
import { ExtractorMessageId } from './ExtractorMessageId';
77
import { Path, Text } from '@microsoft/node-core-library';
8+
import { ExtractorLogLevel } from './ExtractorLogLevel';
89

910
/**
1011
* Used by {@link ExtractorMessage.properties}.
@@ -114,7 +115,7 @@ export class ExtractorMessage {
114115
*
115116
* To discard a message entirely, assign `logLevel = none`.
116117
*/
117-
public logLevel: ExtractorMessageLogLevel;
118+
public logLevel: ExtractorLogLevel;
118119

119120
/**
120121
* The text description of this issue.

apps/api-extractor/src/api/IConfigFile.ts

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import { ExtractorLogLevel } from './ExtractorLogLevel';
5+
46
/**
57
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
68
*
@@ -198,53 +200,6 @@ export interface IConfigTsdocMetadata {
198200
tsdocMetadataFilePath?: string;
199201
}
200202

201-
/**
202-
* Used with {@link IConfigMessageReportingRule.logLevel}.
203-
*
204-
* @remarks
205-
* This is part of the {@link IConfigFile} structure.
206-
*
207-
* @public
208-
*/
209-
export const enum ExtractorMessageLogLevel {
210-
/**
211-
* The message will be displayed as an error.
212-
*
213-
* @remarks
214-
* Errors typically cause the build to fail and return a nonzero exit code.
215-
*/
216-
Error = 'error',
217-
218-
/**
219-
* The message will be displayed as an warning.
220-
*
221-
* @remarks
222-
* Warnings typically cause a production build fail and return a nonzero exit code. For a non-production build
223-
* (e.g. using the `--local` option with `api-extractor run`), the warning is displayed but the build will not fail.
224-
*/
225-
Warning = 'warning',
226-
227-
/**
228-
* The message will be displayed as an informational message.
229-
*
230-
* @remarks
231-
* Informational messages may contain newlines to ensure nice formatting of the output,
232-
* however word-wrapping is the responsibility of the message handler.
233-
*/
234-
Info = 'info',
235-
236-
/**
237-
* The message will be displayed only when "verbose" output is requested, e.g. using the `--verbose`
238-
* command line option.
239-
*/
240-
Verbose = 'verbose',
241-
242-
/**
243-
* The message will be discarded entirely.
244-
*/
245-
None = 'none'
246-
}
247-
248203
/**
249204
* Configures reporting for a given message identifier.
250205
*
@@ -260,7 +215,7 @@ export interface IConfigMessageReportingRule {
260215
* @remarks
261216
* Note that the `addToApiReviewFile` property may supersede this option.
262217
*/
263-
logLevel: ExtractorMessageLogLevel;
218+
logLevel: ExtractorLogLevel;
264219

265220
/**
266221
* If API Extractor is configured to write an API review file (.api.md), then the message will be written

apps/api-extractor/src/collector/MessageRouter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import {
1818
import { ExtractorMessageId, allExtractorMessageIds } from '../api/ExtractorMessageId';
1919
import {
2020
IExtractorMessagesConfig,
21-
ExtractorMessageLogLevel,
2221
IConfigMessageReportingRule
2322
} from '../api/IConfigFile';
2423
import { ILogger } from '../api/ILogger';
2524
import { SourceMapper } from './SourceMapper';
25+
import { ExtractorLogLevel } from '../api/ExtractorLogLevel';
2626

2727
interface IReportingRule {
28-
logLevel: ExtractorMessageLogLevel;
28+
logLevel: ExtractorLogLevel;
2929
addToApiReviewFile: boolean;
3030
}
3131

@@ -43,11 +43,11 @@ export class MessageRouter {
4343

4444
// Normalized representation of the routing rules from api-extractor.json
4545
private _reportingRuleByMessageId: Map<string, IReportingRule> = new Map<string, IReportingRule>();
46-
private _compilerDefaultRule: IReportingRule = { logLevel: ExtractorMessageLogLevel.None,
46+
private _compilerDefaultRule: IReportingRule = { logLevel: ExtractorLogLevel.None,
4747
addToApiReviewFile: false };
48-
private _extractorDefaultRule: IReportingRule = { logLevel: ExtractorMessageLogLevel.None,
48+
private _extractorDefaultRule: IReportingRule = { logLevel: ExtractorLogLevel.None,
4949
addToApiReviewFile: false };
50-
private _tsdocDefaultRule: IReportingRule = { logLevel: ExtractorMessageLogLevel.None,
50+
private _tsdocDefaultRule: IReportingRule = { logLevel: ExtractorLogLevel.None,
5151
addToApiReviewFile: false };
5252

5353
public constructor(messagesConfig: IExtractorMessagesConfig) {
@@ -334,13 +334,13 @@ export class MessageRouter {
334334
// Is this message type configured to go to the console?
335335
const reportingRule: IReportingRule = this._getRuleForMessage(message);
336336
switch (reportingRule.logLevel) {
337-
case ExtractorMessageLogLevel.Error:
337+
case ExtractorLogLevel.Error:
338338
logger.logError('Error: ' + message.formatMessageWithLocation(workingPackageFolderPath));
339339
break;
340-
case ExtractorMessageLogLevel.Warning:
340+
case ExtractorLogLevel.Warning:
341341
logger.logWarning('Warning: ' + message.formatMessageWithLocation(workingPackageFolderPath));
342342
break;
343-
case ExtractorMessageLogLevel.None:
343+
case ExtractorLogLevel.None:
344344
break;
345345
default:
346346
throw new Error(`Invalid logLevel value: ${JSON.stringify(reportingRule.logLevel)}`);

apps/api-extractor/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export {
2222
ExtractorConfig
2323
} from './api/ExtractorConfig';
2424

25+
export { ExtractorLogLevel } from './api/ExtractorLogLevel';
26+
2527
export {
2628
ExtractorMessage,
2729
IExtractorMessageProperties,
@@ -36,7 +38,6 @@ export {
3638
IConfigDocModel,
3739
IConfigDtsRollup,
3840
IConfigTsdocMetadata,
39-
ExtractorMessageLogLevel,
4041
IConfigMessageReportingRule,
4142
IConfigMessageReportingTable,
4243
IExtractorMessagesConfig,

common/reviews/api/api-extractor.api.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ export class ExtractorConfig {
5454
readonly untrimmedFilePath: string;
5555
}
5656

57+
// @public
58+
export const enum ExtractorLogLevel {
59+
Error = "error",
60+
Info = "info",
61+
None = "none",
62+
Verbose = "verbose",
63+
Warning = "warning"
64+
}
65+
5766
// @public
5867
export class ExtractorMessage {
5968
// Warning: (ae-forgotten-export) The symbol "IExtractorMessageOptions" needs to be exported by the entry point index.d.ts
@@ -64,6 +73,8 @@ export class ExtractorMessage {
6473
formatMessageWithLocation(workingPackageFolderPath: string): string;
6574
// (undocumented)
6675
formatMessageWithoutLocation(): string;
76+
handled: boolean;
77+
logLevel: ExtractorLogLevel;
6778
readonly messageId: tsdoc.TSDocMessageId | ExtractorMessageId | string;
6879
readonly properties: IExtractorMessageProperties;
6980
readonly sourceFileColumn: number | undefined;
@@ -96,13 +107,6 @@ export const enum ExtractorMessageId {
96107
UnresolvedLink = "ae-unresolved-link"
97108
}
98109

99-
// @public
100-
export const enum ExtractorMessageLogLevel {
101-
Error = "error",
102-
None = "none",
103-
Warning = "warning"
104-
}
105-
106110
// @public
107111
export class ExtractorResult {
108112
// @internal
@@ -167,7 +171,7 @@ export interface IConfigFile {
167171
// @public
168172
export interface IConfigMessageReportingRule {
169173
addToApiReviewFile?: boolean;
170-
logLevel: ExtractorMessageLogLevel;
174+
logLevel: ExtractorLogLevel;
171175
}
172176

173177
// @public
@@ -194,6 +198,7 @@ export interface IExtractorInvokeOptions {
194198
compilerState?: CompilerState;
195199
customLogger?: Partial<ILogger>;
196200
localBuild?: boolean;
201+
messageCallback?: (message: ExtractorMessage) => void;
197202
typescriptCompilerFolder?: string;
198203
}
199204

0 commit comments

Comments
 (0)