Skip to content

Commit 3cf2789

Browse files
committed
Add "--debug" command line option
1 parent fcf0bc4 commit 3cf2789

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

apps/api-extractor/.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"program": "${workspaceFolder}/lib/start.js",
1313
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-01",
1414
"args": [
15+
"-d",
1516
"run",
1617
"-l"
1718
]
@@ -23,6 +24,7 @@
2324
"program": "${workspaceFolder}/lib/start.js",
2425
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-02",
2526
"args": [
27+
"-d",
2628
"run",
2729
"-l"
2830
]
@@ -34,6 +36,7 @@
3436
"program": "${workspaceFolder}/lib/start.js",
3537
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-04",
3638
"args": [
39+
"-d",
3740
"run",
3841
"-l"
3942
]

apps/api-extractor/src/cli/ApiExtractorCommandLine.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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 { CommandLineParser } from '@microsoft/ts-command-line';
4+
import { CommandLineParser, CommandLineFlagParameter } from '@microsoft/ts-command-line';
55
import { RunAction } from './RunAction';
66

77
export class ApiExtractorCommandLine extends CommandLineParser {
8+
private _debugParameter: CommandLineFlagParameter;
9+
810
constructor() {
911
super({
1012
toolFilename: 'api-extractor',
@@ -14,6 +16,24 @@ export class ApiExtractorCommandLine extends CommandLineParser {
1416
}
1517

1618
protected onDefineParameters(): void { // override
19+
this._debugParameter = this.defineFlagParameter({
20+
parameterLongName: '--debug',
21+
parameterShortName: '-d',
22+
description: 'Show the full call stack if an error occurs while executing the tool'
23+
});
24+
}
25+
26+
protected onExecute(): Promise<void> { // override
27+
return super.onExecute().catch((error) => {
28+
29+
if (this._debugParameter.value) {
30+
console.error(os.EOL + error.stack);
31+
} else {
32+
console.error(os.EOL + colors.red('ERROR: ' + error.message.trim()));
33+
}
34+
35+
process.exitCode = 1;
36+
});
1737
}
1838

1939
private _populateActions(): void {

apps/api-extractor/src/generators/packageTypings/SymbolAnalyzer.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ export class SymbolAnalyzer {
9393
current = currentAlias;
9494
}
9595

96+
// Is the followedSymbol actually the kind of thing that can be ambient?
97+
if (isAmbient) {
98+
for (const declaration of current.declarations || []) {
99+
switch (declaration.kind) {
100+
case ts.SyntaxKind.ClassDeclaration:
101+
case ts.SyntaxKind.InterfaceDeclaration:
102+
case ts.SyntaxKind.FunctionDeclaration:
103+
case ts.SyntaxKind.ModuleDeclaration:
104+
case ts.SyntaxKind.VariableDeclaration:
105+
// These actually need "export" keywords
106+
break;
107+
default:
108+
// Everything else we assume is some kind of nested declaration that
109+
// doesn't need it.
110+
isAmbient = false;
111+
break;
112+
}
113+
}
114+
}
115+
96116
return {
97117
followedSymbol: current,
98118
localName: declarationName || current.name,

0 commit comments

Comments
 (0)