8000 Add "--diagnostics" logging for ignored globals · rbuckton/rushstack@2e11017 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e11017

Browse files
committed
Add "--diagnostics" logging for ignored globals
1 parent 1aa968d commit 2e11017

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

apps/api-extractor/src/analyzer/AstSymbolTable.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { AstImport } from './AstImport';
1414
import { MessageRouter } from '../collector/MessageRouter';
1515
import { TypeScriptInternals, IGlobalVariableAnalyzer } from './TypeScriptInternals';
1616
import { StringChecks } from './StringChecks';
17+
import { SourceFileLocationFormatter } from './SourceFileLocationFormatter';
1718

1819
export type AstEntity = AstSymbol | AstImport;
1920

@@ -61,9 +62,11 @@ export interface IFetchAstSymbolOptions {
6162
export class AstSymbolTable {
6263
private readonly _program: ts.Program;
6364
private readonly _typeChecker: ts.TypeChecker;
65+
private readonly _messageRouter: MessageRouter;
6466
private readonly _globalVariableAnalyzer: IGlobalVariableAnalyzer;
6567
private readonly _packageMetadataManager: PackageMetadataManager;
6668
private readonly _exportAnalyzer: ExportAnalyzer;
69+
private readonly _alreadyWarnedGlobalNames: Set<string>;
6770

6871
/**
6972
* A mapping from ts.Symbol --> AstSymbol
@@ -90,6 +93,7 @@ export class AstSymbolTable {
9093

9194
this._program = program;
9295
this._typeChecker = typeChecker;
96+
this._messageRouter = messageRouter;
9397
this._globalVariableAnalyzer = TypeScriptInternals.getGlobalVariableAnalyzer(program);
9498
this._packageMetadataManager = new PackageMetadataManager(packageJsonLookup, messageRouter);
9599

@@ -102,6 +106,8 @@ export class AstSymbolTable {
102106
fetchAstSymbol: this._fetchAstSymbol.bind(this)
103107
}
104108
);
109+
110+
this._alreadyWarnedGlobalNames = new Set<string>();
105111
}
106112

107113
/**
@@ -345,7 +351,13 @@ export class AstSymbolTable {
345351
// that include interesting global variables in their API, but API Extractor doesn't support
346352
// that yet; it would be a feature request.)
347353

348-
// console.log(`Ignoring reference to global variable ${identifierNode.text}`);
354+
if (this._messageRouter.showDiagnostics) {
355+
if (!this._alreadyWarnedGlobalNames.has(identifierNode.text)) {
356+
this._alreadyWarnedGlobalNames.add(identifierNode.text);
357+
this._messageRouter.logDiagnostic(`Ignoring reference to global variable "${identifierNode.text}"`
358+
+ ` in ` + SourceFileLocationFormatter.formatDeclaration(identifierNode));
359+
}
360+
}
349361
} else {
350362
// If you encounter this, please report a bug with a repro. We're interested to know
351363
// how it can occur.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ export class Extractor {
228228
const modelBuilder: ApiModelGenerator = new ApiModelGenerator(collector);
229229
const apiPackage: ApiPackage = modelBuilder.buildApiPackage();
230230

231+
if (messageRouter.showDiagnostics) {
232+
messageRouter.logDiagnostic(''); // skip a line after any diagnostic messages
233+
}
234+
231235
if (extractorConfig.docModelEnabled) {
232236
messageRouter.logVerbose(ConsoleMessageId.WritingDocModelFile, 'Writing: ' + extractorConfig.apiJsonFilePath);
233237
apiPackage.saveToJsonFile(extractorConfig.apiJsonFilePath, {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ export class MessageRouter {
465465
}
466466

467467
public logDiagnostic(message: string): void {
468-
this.logVerbose(ConsoleMessageId.Diagnostics, message);
468+
if (this.showDiagnostics) {
469+
this.logVerbose(ConsoleMessageId.Diagnostics, message);
470+
}
469471
}
470472

471473
/**

0 commit comments

Comments
 (0)
0