@microsoft/api-extractor 7.29.4 → 7.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rollup.d.ts +26 -2
- package/lib/api/ExtractorConfig.d.ts +4 -0
- package/lib/api/ExtractorConfig.d.ts.map +1 -1
- package/lib/api/ExtractorConfig.js +8 -0
- package/lib/api/ExtractorConfig.js.map +1 -1
- package/lib/api/ExtractorMessageId.d.ts +1 -1
- package/lib/api/ExtractorMessageId.js.map +1 -1
- package/lib/api/IConfigFile.d.ts +21 -1
- package/lib/api/IConfigFile.d.ts.map +1 -1
- package/lib/api/IConfigFile.js.map +1 -1
- package/lib/collector/Collector.d.ts +1 -1
- package/lib/collector/Collector.d.ts.map +1 -1
- package/lib/collector/Collector.js +43 -32
- package/lib/collector/Collector.js.map +1 -1
- package/lib/collector/CollectorEntity.d.ts +56 -28
- package/lib/collector/CollectorEntity.d.ts.map +1 -1
- package/lib/collector/CollectorEntity.js +82 -31
- package/lib/collector/CollectorEntity.js.map +1 -1
- package/lib/enhancers/DocCommentEnhancer.d.ts.map +1 -1
- package/lib/enhancers/DocCommentEnhancer.js +3 -1
- package/lib/enhancers/DocCommentEnhancer.js.map +1 -1
- package/lib/enhancers/ValidationEnhancer.d.ts.map +1 -1
- package/lib/enhancers/ValidationEnhancer.js +7 -5
- package/lib/enhancers/ValidationEnhancer.js.map +1 -1
- package/lib/generators/ApiModelGenerator.d.ts +1 -1
- package/lib/generators/ApiModelGenerator.d.ts.map +1 -1
- package/lib/generators/ApiModelGenerator.js +100 -75
- package/lib/generators/ApiModelGenerator.js.map +1 -1
- package/lib/generators/ApiReportGenerator.js +2 -2
- package/lib/generators/ApiReportGenerator.js.map +1 -1
- package/lib/generators/DeclarationReferenceGenerator.d.ts +4 -8
- package/lib/generators/DeclarationReferenceGenerator.d.ts.map +1 -1
- package/lib/generators/DeclarationReferenceGenerator.js +50 -67
- package/lib/generators/DeclarationReferenceGenerator.js.map +1 -1
- package/lib/schemas/api-extractor-defaults.json +4 -2
- package/lib/schemas/api-extractor-template.json +24 -5
- package/lib/schemas/api-extractor.schema.json +11 -1
- package/package.json +4 -5
|
@@ -33,18 +33,14 @@ const node_core_library_1 = require("@rushstack/node-core-library");
|
|
|
33
33
|
const TypeScriptHelpers_1 = require("../analyzer/TypeScriptHelpers");
|
|
34
34
|
const TypeScriptInternals_1 = require("../analyzer/TypeScriptInternals");
|
|
35
35
|
class DeclarationReferenceGenerator {
|
|
36
|
-
constructor(
|
|
37
|
-
this.
|
|
38
|
-
this._workingPackageName = workingPackageName;
|
|
39
|
-
this._program = program;
|
|
40
|
-
this._typeChecker = typeChecker;
|
|
41
|
-
this._bundledPackageNames = bundledPackageNames;
|
|
36
|
+
constructor(collector) {
|
|
37
|
+
this._collector = collector;
|
|
42
38
|
}
|
|
43
39
|
/**
|
|
44
40
|
* Gets the UID for a TypeScript Identifier that references a type.
|
|
45
41
|
*/
|
|
46
42
|
getDeclarationReferenceForIdentifier(node) {
|
|
47
|
-
const symbol = this.
|
|
43
|
+
const symbol = this._collector.typeChecker.getSymbolAtLocation(node);
|
|
48
44
|
if (symbol !== undefined) {
|
|
49
45
|
const isExpression = DeclarationReferenceGenerator._isInExpressionContext(node);
|
|
50
46
|
return (this.getDeclarationReferenceForSymbol(symbol, isExpression ? ts.SymbolFlags.Value : ts.SymbolFlags.Type) ||
|
|
@@ -80,59 +76,48 @@ class DeclarationReferenceGenerator {
|
|
|
80
76
|
right.valueDeclaration &&
|
|
81
77
|
left.valueDeclaration === right.valueDeclaration));
|
|
82
78
|
}
|
|
83
|
-
|
|
79
|
+
_getNavigationToSymbol(symbol) {
|
|
80
|
+
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
81
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
84
82
|
const parent = TypeScriptInternals_1.TypeScriptInternals.getSymbolParent(symbol);
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
// If it's global or from an external library, then use either Members or Exports. It's not possible for
|
|
84
|
+
// global symbols or external library symbols to be Locals.
|
|
85
|
+
const isGlobal = !!sourceFile && !ts.isExternalModule(sourceFile);
|
|
86
|
+
const isFromExternalLibrary = !!sourceFile && this._collector.program.isSourceFileFromExternalLibrary(sourceFile);
|
|
87
|
+
if (isGlobal || isFromExternalLibrary) {
|
|
88
|
+
if (parent &&
|
|
89
|
+
parent.members &&
|
|
92
90
|
DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)) {
|
|
93
91
|
return "#" /* Navigation.Members */;
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
DeclarationReferenceGenerator._isSameSymbol(parent.globalExports.get(symbol.escapedName), symbol)) {
|
|
97
|
-
return 'global';
|
|
98
|
-
}
|
|
93
|
+
return "." /* Navigation.Exports */;
|
|
99
94
|
}
|
|
100
|
-
//
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
if (ts.isTypeElement(declaration) || ts.isObjectLiteralElement(declaration)) {
|
|
112
|
-
// type and object literal element members are just members
|
|
113
|
-
return "#" /* Navigation.Members */;
|
|
114
|
-
}
|
|
115
|
-
if (ts.isEnumMember(declaration)) {
|
|
116
|
-
// enum members are exports
|
|
117
|
-
return "." /* Navigation.Exports */;
|
|
118
|
-
}
|
|
119
|
-
if (ts.isExportSpecifier(declaration) ||
|
|
120
|
-
ts.isExportAssignment(declaration) ||
|
|
121
|
-
ts.isExportSpecifier(declaration) ||
|
|
122
|
-
ts.isExportDeclaration(declaration) ||
|
|
123
|
-
ts.isNamedExports(declaration)) {
|
|
124
|
-
return "." /* Navigation.Exports */;
|
|
95
|
+
// Otherwise, this symbol is from the current package.
|
|
96
|
+
if (parent) {
|
|
97
|
+
// If we've found an exported CollectorEntity, then it's exported from the package entry point, so
|
|
98
|
+
// use Exports.
|
|
99
|
+
const namedDeclaration = declaration === null || declaration === void 0 ? void 0 : declaration.name;
|
|
100
|
+
if (namedDeclaration && ts.isIdentifier(namedDeclaration)) {
|
|
101
|
+
const collectorEntity = this._collector.tryGetEntityForNode(namedDeclaration);
|
|
102
|
+
if (collectorEntity && collectorEntity.exported) {
|
|
103
|
+
return "." /* Navigation.Exports */;
|
|
104
|
+
}
|
|
125
105
|
}
|
|
126
|
-
//
|
|
127
|
-
|
|
106
|
+
// If its parent symbol is not a source file, then use either Exports or Members. If the parent symbol
|
|
107
|
+
// is a source file, but it wasn't exported from the package entry point (in the check above), then the
|
|
108
|
+
// symbol is a local, so fall through below.
|
|
109
|
+
if (!DeclarationReferenceGenerator._isExternalModuleSymbol(parent)) {
|
|
110
|
+
if (parent.members &&
|
|
111
|
+
DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)) {
|
|
112
|
+
return "#" /* Navigation.Members */;
|
|
113
|
+
}
|
|
128
114
|
return "." /* Navigation.Exports */;
|
|
129
115
|
}
|
|
130
|
-
if (ts.isSourceFile(declaration.parent) && !ts.isExternalModule(declaration.parent)) {
|
|
131
|
-
// declarations in a source file are global if the source file is not a module.
|
|
132
|
-
return 'global';
|
|
133
|
-
}
|
|
134
116
|
}
|
|
135
|
-
//
|
|
117
|
+
// Otherwise, we have a local symbol, so use a Locals navigation. These are either:
|
|
118
|
+
//
|
|
119
|
+
// 1. Symbols that are exported from a file module but not the package entry point.
|
|
120
|
+
// 2. Symbols that are not exported from their parent module.
|
|
136
121
|
return "~" /* Navigation.Locals */;
|
|
137
122
|
}
|
|
138
123
|
static _getMeaningOfSymbol(symbol, meaning) {
|
|
@@ -184,19 +169,19 @@ class DeclarationReferenceGenerator {
|
|
|
184
169
|
return undefined;
|
|
185
170
|
}
|
|
186
171
|
_symbolToDeclarationReference(symbol, meaning, includeModuleSymbols) {
|
|
172
|
+
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
173
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
187
174
|
let followedSymbol = symbol;
|
|
188
175
|
if (followedSymbol.flags & ts.SymbolFlags.ExportValue) {
|
|
189
|
-
followedSymbol = this.
|
|
176
|
+
followedSymbol = this._collector.typeChecker.getExportSymbolOfSymbol(followedSymbol);
|
|
190
177
|
}
|
|
191
178
|
if (followedSymbol.flags & ts.SymbolFlags.Alias) {
|
|
192
|
-
followedSymbol = this.
|
|
179
|
+
followedSymbol = this._collector.typeChecker.getAliasedSymbol(followedSymbol);
|
|
193
180
|
}
|
|
194
181
|
if (DeclarationReferenceGenerator._isExternalModuleSymbol(followedSymbol)) {
|
|
195
182
|
if (!includeModuleSymbols) {
|
|
196
183
|
return undefined;
|
|
197
184
|
}
|
|
198
|
-
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
199
|
-
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
200
185
|
return new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
201
186
|
}
|
|
202
187
|
// Do not generate a declaration reference for a type parameter.
|
|
@@ -231,12 +216,10 @@ class DeclarationReferenceGenerator {
|
|
|
231
216
|
}
|
|
232
217
|
}
|
|
233
218
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
navigation = "." /* Navigation.Exports */;
|
|
219
|
+
const navigation = this._getNavigationToSymbol(followedSymbol);
|
|
220
|
+
// If the symbol is a global, ensure the source is global.
|
|
221
|
+
if (sourceFile && !ts.isExternalModule(sourceFile) && parentRef.source !== DeclarationReference_1.GlobalSource.instance) {
|
|
222
|
+
parentRef = new DeclarationReference_1.DeclarationReference(DeclarationReference_1.GlobalSource.instance);
|
|
240
223
|
}
|
|
241
224
|
return parentRef
|
|
242
225
|
.addNavigationStep(navigation, localName)
|
|
@@ -265,7 +248,7 @@ class DeclarationReferenceGenerator {
|
|
|
265
248
|
// but its reference still needs to be qualified with the parent reference for `n`.
|
|
266
249
|
const grandParent = (_a = declaration === null || declaration === void 0 ? void 0 : declaration.parent) === null || _a === void 0 ? void 0 : _a.parent;
|
|
267
250
|
if (grandParent && ts.isModuleDeclaration(grandParent)) {
|
|
268
|
-
const grandParentSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(grandParent, this.
|
|
251
|
+
const grandParentSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(grandParent, this._collector.typeChecker);
|
|
269
252
|
if (grandParentSymbol) {
|
|
270
253
|
return this._symbolToDeclarationReference(grandParentSymbol, grandParentSymbol.flags,
|
|
271
254
|
/*includeModuleSymbols*/ true);
|
|
@@ -281,23 +264,23 @@ class DeclarationReferenceGenerator {
|
|
|
281
264
|
}
|
|
282
265
|
}
|
|
283
266
|
_getPackageName(sourceFile) {
|
|
284
|
-
if (this.
|
|
285
|
-
const packageJson = this.
|
|
267
|
+
if (this._collector.program.isSourceFileFromExternalLibrary(sourceFile)) {
|
|
268
|
+
const packageJson = this._collector.packageJsonLookup.tryLoadNodePackageJsonFor(sourceFile.fileName);
|
|
286
269
|
if (packageJson && packageJson.name) {
|
|
287
270
|
return packageJson.name;
|
|
288
271
|
}
|
|
289
272
|
return DeclarationReferenceGenerator.unknownReference;
|
|
290
273
|
}
|
|
291
|
-
return this.
|
|
274
|
+
return this._collector.workingPackage.name;
|
|
292
275
|
}
|
|
293
276
|
_sourceFileToModuleSource(sourceFile) {
|
|
294
277
|
if (sourceFile && ts.isExternalModule(sourceFile)) {
|
|
295
278
|
const packageName = this._getPackageName(sourceFile);
|
|
296
|
-
if (this.
|
|
279
|
+
if (this._collector.bundledPackageNames.has(packageName)) {
|
|
297
280
|
// The api-extractor.json config file has a "bundledPackages" setting, which causes imports from
|
|
298
281
|
// certain NPM packages to be treated as part of the working project. In this case, we need to
|
|
299
282
|
// substitute the working package name.
|
|
300
|
-
return new DeclarationReference_1.ModuleSource(this.
|
|
283
|
+
return new DeclarationReference_1.ModuleSource(this._collector.workingPackage.name);
|
|
301
284
|
}
|
|
302
285
|
else {
|
|
303
286
|
return new DeclarationReference_1.ModuleSource(packageName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeclarationReferenceGenerator.js","sourceRoot":"","sources":["../../src/generators/DeclarationReferenceGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+BAA+B;AAC/B,+CAAiC;AACjC,kGAMiE;AACjE,oEAAkG;AAClG,qEAAkE;AAClE,yEAAsE;AAEtE,MAAa,6BAA6B;IASxC,YACE,iBAAoC,EACpC,kBAA0B,EAC1B,OAAmB,EACnB,WAA2B,EAC3B,mBAAwC;QAExC,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;IAClD,CAAC;IAED;;OAEG;IACI,oCAAoC,CAAC,IAAmB;QAC7D,MAAM,MAAM,GAA0B,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAClF,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,YAAY,GAAY,6BAA6B,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;YACzF,OAAO,CACL,IAAI,CAAC,gCAAgC,CACnC,MAAM,EACN,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAA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jG,UAAU,CAAC,QAAQ,CACpB,CAAC;YAEF,IAAI,WAAW,IAAI,WAAW,CAAC,IAAI,EAAE;gBACnC,OAAO,WAAW,CAAC,IAAI,CAAC;aACzB;YACD,OAAO,6BAA6B,CAAC,gBAAgB,CAAC;SACvD;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAEO,yBAAyB,CAAC,UAAqC;QACrE,IAAI,UAAU,IAAI,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE;YACjD,MAAM,WAAW,GAAW,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YAE7D,IAAI,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;gBAC9C,gGAAgG;gBAChG,+FAA+F;gBAC/F,uCAAuC;gBACvC,OAAO,IAAI,mCAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;aACnD;iBAAM;gBACL,OAAO,IAAI,mCAAY,CAAC,WAAW,CAAC,CAAC;aACtC;SACF;QACD,OAAO,mCAAY,CAAC,QAAQ,CAAC;IAC/B,CAAC;;AA3VH,sEA4VC;AA3VwB,8CAAgB,GAAW,GAAG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/* eslint-disable no-bitwise */\nimport * as ts from 'typescript';\nimport {\n DeclarationReference,\n ModuleSource,\n GlobalSource,\n Navigation,\n Meaning\n} from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { PackageJsonLookup, INodePackageJson, InternalError } from '@rushstack/node-core-library';\nimport { TypeScriptHelpers } from '../analyzer/TypeScriptHelpers';\nimport { TypeScriptInternals } from '../analyzer/TypeScriptInternals';\n\nexport class DeclarationReferenceGenerator {\n public static readonly unknownReference: string = '?';\n\n private _packageJsonLookup: PackageJsonLookup;\n private _workingPackageName: string;\n private _program: ts.Program;\n private _typeChecker: ts.TypeChecker;\n private _bundledPackageNames: ReadonlySet<string>;\n\n public constructor(\n packageJsonLookup: PackageJsonLookup,\n workingPackageName: string,\n program: ts.Program,\n typeChecker: ts.TypeChecker,\n bundledPackageNames: ReadonlySet<string>\n ) {\n this._packageJsonLookup = packageJsonLookup;\n this._workingPackageName = workingPackageName;\n this._program = program;\n this._typeChecker = typeChecker;\n this._bundledPackageNames = bundledPackageNames;\n }\n\n /**\n * Gets the UID for a TypeScript Identifier that references a type.\n */\n public getDeclarationReferenceForIdentifier(node: ts.Identifier): DeclarationReference | undefined {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(node);\n if (symbol !== undefined) {\n const isExpression: boolean = DeclarationReferenceGenerator._isInExpressionContext(node);\n return (\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Value : ts.SymbolFlags.Type\n ) ||\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Type : ts.SymbolFlags.Value\n ) ||\n this.getDeclarationReferenceForSymbol(symbol, ts.SymbolFlags.Namespace)\n );\n }\n }\n\n /**\n * Gets the DeclarationReference for a TypeScript Symbol for a given meaning.\n */\n public getDeclarationReferenceForSymbol(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags\n ): DeclarationReference | undefined {\n return this._symbolToDeclarationReference(symbol, meaning, /*includeModuleSymbols*/ false);\n }\n\n private static _isInExpressionContext(node: ts.Node): boolean {\n switch (node.parent.kind) {\n case ts.SyntaxKind.TypeQuery:\n return true;\n case ts.SyntaxKind.QualifiedName:\n return DeclarationReferenceGenerator._isInExpressionContext(node.parent);\n default:\n return false;\n }\n }\n\n private static _isExternalModuleSymbol(symbol: ts.Symbol): boolean {\n return (\n !!(symbol.flags & ts.SymbolFlags.ValueModule) &&\n symbol.valueDeclaration !== undefined &&\n ts.isSourceFile(symbol.valueDeclaration)\n );\n }\n\n private static _isSameSymbol(left: ts.Symbol | undefined, right: ts.Symbol): boolean {\n return (\n left === right ||\n !!(\n left &&\n left.valueDeclaration &&\n right.valueDeclaration &&\n left.valueDeclaration === right.valueDeclaration\n )\n );\n }\n\n private static _getNavigationToSymbol(symbol: ts.Symbol): Navigation | 'global' {\n const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n // First, try to determine navigation to symbol via its parent.\n if (parent) {\n if (\n parent.exports &&\n DeclarationReferenceGenerator._isSameSymbol(parent.exports.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Exports;\n }\n if (\n parent.members &&\n DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Members;\n }\n if (\n parent.globalExports &&\n DeclarationReferenceGenerator._isSameSymbol(parent.globalExports.get(symbol.escapedName), symbol)\n ) {\n return 'global';\n }\n }\n\n // Next, try determining navigation to symbol by its node\n if (symbol.valueDeclaration) {\n const declaration: ts.Declaration = ts.isBindingElement(symbol.valueDeclaration)\n ? ts.walkUpBindingElementsAndPatterns(symbol.valueDeclaration)\n : symbol.valueDeclaration;\n if (ts.isClassElement(declaration) && ts.isClassLike(declaration.parent)) {\n // class members are an \"export\" if they have the static modifier.\n return ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Static\n ? Navigation.Exports\n : Navigation.Members;\n }\n if (ts.isTypeElement(declaration) || ts.isObjectLiteralElement(declaration)) {\n // type and object literal element members are just members\n return Navigation.Members;\n }\n if (ts.isEnumMember(declaration)) {\n // enum members are exports\n return Navigation.Exports;\n }\n if (\n ts.isExportSpecifier(declaration) ||\n ts.isExportAssignment(declaration) ||\n ts.isExportSpecifier(declaration) ||\n ts.isExportDeclaration(declaration) ||\n ts.isNamedExports(declaration)\n ) {\n return Navigation.Exports;\n }\n // declarations are exports if they have an `export` modifier.\n if (ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export) {\n return Navigation.Exports;\n }\n if (ts.isSourceFile(declaration.parent) && !ts.isExternalModule(declaration.parent)) {\n // declarations in a source file are global if the source file is not a module.\n return 'global';\n }\n }\n // all other declarations are locals\n return Navigation.Locals;\n }\n\n private static _getMeaningOfSymbol(symbol: ts.Symbol, meaning: ts.SymbolFlags): Meaning | undefined {\n if (symbol.flags & meaning & ts.SymbolFlags.Class) {\n return Meaning.Class;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Enum) {\n return Meaning.Enum;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Interface) {\n return Meaning.Interface;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeAlias) {\n return Meaning.TypeAlias;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Function) {\n return Meaning.Function;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Variable) {\n return Meaning.Variable;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Module) {\n return Meaning.Namespace;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.ClassMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Constructor) {\n return Meaning.Constructor;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.EnumMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Signature) {\n if (symbol.escapedName === ts.InternalSymbolName.Call) {\n return Meaning.CallSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.New) {\n return Meaning.ConstructSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.Index) {\n return Meaning.IndexSignature;\n }\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeParameter) {\n // This should have already been handled in `getDeclarationReferenceOfSymbol`.\n throw new InternalError('Not supported.');\n }\n return undefined;\n }\n\n private _symbolToDeclarationReference(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags,\n includeModuleSymbols: boolean\n ): DeclarationReference | undefined {\n let followedSymbol: ts.Symbol = symbol;\n if (followedSymbol.flags & ts.SymbolFlags.ExportValue) {\n followedSymbol = this._typeChecker.getExportSymbolOfSymbol(followedSymbol);\n }\n if (followedSymbol.flags & ts.SymbolFlags.Alias) {\n followedSymbol = this._typeChecker.getAliasedSymbol(followedSymbol);\n }\n\n if (DeclarationReferenceGenerator._isExternalModuleSymbol(followedSymbol)) {\n if (!includeModuleSymbols) {\n return undefined;\n }\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n }\n\n // Do not generate a declaration reference for a type parameter.\n if (followedSymbol.flags & ts.SymbolFlags.TypeParameter) {\n return undefined;\n }\n\n let parentRef: DeclarationReference | undefined = this._getParentReference(followedSymbol);\n if (!parentRef) {\n return undefined;\n }\n\n let localName: string = followedSymbol.name;\n if (followedSymbol.escapedName === ts.InternalSymbolName.Constructor) {\n localName = 'constructor';\n } else {\n const wellKnownName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(\n followedSymbol.escapedName\n );\n if (wellKnownName) {\n // TypeScript binds well-known ECMAScript symbols like 'Symbol.iterator' as '__@iterator'.\n // This converts a string like '__@iterator' into the property name '[Symbol.iterator]'.\n localName = wellKnownName;\n } else if (TypeScriptHelpers.isUniqueSymbolName(followedSymbol.escapedName)) {\n for (const decl of followedSymbol.declarations || []) {\n const declName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(decl);\n if (declName && ts.isComputedPropertyName(declName)) {\n const lateName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declName);\n if (lateName !== undefined) {\n localName = lateName;\n break;\n }\n }\n }\n }\n }\n\n let navigation: Navigation | 'global' =\n DeclarationReferenceGenerator._getNavigationToSymbol(followedSymbol);\n if (navigation === 'global') {\n if (parentRef.source !== GlobalSource.instance) {\n parentRef = new DeclarationReference(GlobalSource.instance);\n }\n navigation = Navigation.Exports;\n }\n\n return parentRef\n .addNavigationStep(navigation, localName)\n .withMeaning(DeclarationReferenceGenerator._getMeaningOfSymbol(followedSymbol, meaning));\n }\n\n private _getParentReference(symbol: ts.Symbol): DeclarationReference | undefined {\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n\n // First, try to find a parent symbol via the symbol tree.\n const parentSymbol: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n if (parentSymbol) {\n return this._symbolToDeclarationReference(\n parentSymbol,\n parentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n\n // If that doesn't work, try to find a parent symbol via the node tree. As far as we can tell,\n // this logic is only needed for local symbols within namespaces. For example:\n //\n // ```\n // export namespace n {\n // type SomeType = number;\n // export function someFunction(): SomeType { return 5; }\n // }\n // ```\n //\n // In the example above, `SomeType` doesn't have a parent symbol per the TS internal API above,\n // but its reference still needs to be qualified with the parent reference for `n`.\n const grandParent: ts.Node | undefined = declaration?.parent?.parent;\n if (grandParent && ts.isModuleDeclaration(grandParent)) {\n const grandParentSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetSymbolForDeclaration(\n grandParent,\n this._typeChecker\n );\n if (grandParentSymbol) {\n return this._symbolToDeclarationReference(\n grandParentSymbol,\n grandParentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n }\n\n // At this point, we have a local symbol in a module.\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n } else {\n return new DeclarationReference(GlobalSource.instance);\n }\n }\n\n private _getPackageName(sourceFile: ts.SourceFile): string {\n if (this._program.isSourceFileFromExternalLibrary(sourceFile)) {\n const packageJson: INodePackageJson | undefined = this._packageJsonLookup.tryLoadNodePackageJsonFor(\n sourceFile.fileName\n );\n\n if (packageJson && packageJson.name) {\n return packageJson.name;\n }\n return DeclarationReferenceGenerator.unknownReference;\n }\n return this._workingPackageName;\n }\n\n private _sourceFileToModuleSource(sourceFile: ts.SourceFile | undefined): GlobalSource | ModuleSource {\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n const packageName: string = this._getPackageName(sourceFile);\n\n if (this._bundledPackageNames.has(packageName)) {\n // The api-extractor.json config file has a \"bundledPackages\" setting, which causes imports from\n // certain NPM packages to be treated as part of the working project. In this case, we need to\n // substitute the working package name.\n return new ModuleSource(this._workingPackageName);\n } else {\n return new ModuleSource(packageName);\n }\n }\n return GlobalSource.instance;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DeclarationReferenceGenerator.js","sourceRoot":"","sources":["../../src/generators/DeclarationReferenceGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+BAA+B;AAC/B,+CAAiC;AACjC,kGAMiE;AACjE,oEAA+E;AAC/E,qEAAkE;AAClE,yEAAsE;AAItE,MAAa,6BAA6B;IAKxC,YAAmB,SAAoB;QACrC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,oCAAoC,CAAC,IAAmB;QAC7D,MAAM,MAAM,GAA0B,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC5F,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,YAAY,GAAY,6BAA6B,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;YACzF,OAAO,CACL,IAAI,CAAC,gCAAgC,CACnC,MAAM,EACN,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAC1D;gBACD,IAAI,CAAC,gCAAgC,CACnC,MAAM,EACN,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAC1D;gBACD,IAAI,CAAC,gCAAgC,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CACxE,CAAC;SACH;IACH,CAAC;IAED;;OAEG;IACI,gCAAgC,CACrC,MAA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B,GAAW,GAAG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/* eslint-disable no-bitwise */\nimport * as ts from 'typescript';\nimport {\n DeclarationReference,\n ModuleSource,\n GlobalSource,\n Navigation,\n Meaning\n} from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { INodePackageJson, InternalError } from '@rushstack/node-core-library';\nimport { TypeScriptHelpers } from '../analyzer/TypeScriptHelpers';\nimport { TypeScriptInternals } from '../analyzer/TypeScriptInternals';\nimport { Collector } from '../collector/Collector';\nimport { CollectorEntity } from '../collector/CollectorEntity';\n\nexport class DeclarationReferenceGenerator {\n public static readonly unknownReference: string = '?';\n\n private _collector: Collector;\n\n public constructor(collector: Collector) {\n this._collector = collector;\n }\n\n /**\n * Gets the UID for a TypeScript Identifier that references a type.\n */\n public getDeclarationReferenceForIdentifier(node: ts.Identifier): DeclarationReference | undefined {\n const symbol: ts.Symbol | undefined = this._collector.typeChecker.getSymbolAtLocation(node);\n if (symbol !== undefined) {\n const isExpression: boolean = DeclarationReferenceGenerator._isInExpressionContext(node);\n return (\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Value : ts.SymbolFlags.Type\n ) ||\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Type : ts.SymbolFlags.Value\n ) ||\n this.getDeclarationReferenceForSymbol(symbol, ts.SymbolFlags.Namespace)\n );\n }\n }\n\n /**\n * Gets the DeclarationReference for a TypeScript Symbol for a given meaning.\n */\n public getDeclarationReferenceForSymbol(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags\n ): DeclarationReference | undefined {\n return this._symbolToDeclarationReference(symbol, meaning, /*includeModuleSymbols*/ false);\n }\n\n private static _isInExpressionContext(node: ts.Node): boolean {\n switch (node.parent.kind) {\n case ts.SyntaxKind.TypeQuery:\n return true;\n case ts.SyntaxKind.QualifiedName:\n return DeclarationReferenceGenerator._isInExpressionContext(node.parent);\n default:\n return false;\n }\n }\n\n private static _isExternalModuleSymbol(symbol: ts.Symbol): boolean {\n return (\n !!(symbol.flags & ts.SymbolFlags.ValueModule) &&\n symbol.valueDeclaration !== undefined &&\n ts.isSourceFile(symbol.valueDeclaration)\n );\n }\n\n private static _isSameSymbol(left: ts.Symbol | undefined, right: ts.Symbol): boolean {\n return (\n left === right ||\n !!(\n left &&\n left.valueDeclaration &&\n right.valueDeclaration &&\n left.valueDeclaration === right.valueDeclaration\n )\n );\n }\n\n private _getNavigationToSymbol(symbol: ts.Symbol): Navigation {\n const declaration: ts.Declaration | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n\n // If it's global or from an external library, then use either Members or Exports. It's not possible for\n // global symbols or external library symbols to be Locals.\n const isGlobal: boolean = !!sourceFile && !ts.isExternalModule(sourceFile);\n const isFromExternalLibrary: boolean =\n !!sourceFile && this._collector.program.isSourceFileFromExternalLibrary(sourceFile);\n if (isGlobal || isFromExternalLibrary) {\n if (\n parent &&\n parent.members &&\n DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Members;\n }\n\n return Navigation.Exports;\n }\n\n // Otherwise, this symbol is from the current package.\n if (parent) {\n // If we've found an exported CollectorEntity, then it's exported from the package entry point, so\n // use Exports.\n const namedDeclaration: ts.DeclarationName | undefined = (\n declaration as ts.NamedDeclaration | undefined\n )?.name;\n if (namedDeclaration && ts.isIdentifier(namedDeclaration)) {\n const collectorEntity: CollectorEntity | undefined =\n this._collector.tryGetEntityForNode(namedDeclaration);\n if (collectorEntity && collectorEntity.exported) {\n return Navigation.Exports;\n }\n }\n\n // If its parent symbol is not a source file, then use either Exports or Members. If the parent symbol\n // is a source file, but it wasn't exported from the package entry point (in the check above), then the\n // symbol is a local, so fall through below.\n if (!DeclarationReferenceGenerator._isExternalModuleSymbol(parent)) {\n if (\n parent.members &&\n DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Members;\n }\n\n return Navigation.Exports;\n }\n }\n\n // Otherwise, we have a local symbol, so use a Locals navigation. These are either:\n //\n // 1. Symbols that are exported from a file module but not the package entry point.\n // 2. Symbols that are not exported from their parent module.\n return Navigation.Locals;\n }\n\n private static _getMeaningOfSymbol(symbol: ts.Symbol, meaning: ts.SymbolFlags): Meaning | undefined {\n if (symbol.flags & meaning & ts.SymbolFlags.Class) {\n return Meaning.Class;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Enum) {\n return Meaning.Enum;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Interface) {\n return Meaning.Interface;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeAlias) {\n return Meaning.TypeAlias;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Function) {\n return Meaning.Function;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Variable) {\n return Meaning.Variable;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Module) {\n return Meaning.Namespace;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.ClassMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Constructor) {\n return Meaning.Constructor;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.EnumMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Signature) {\n if (symbol.escapedName === ts.InternalSymbolName.Call) {\n return Meaning.CallSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.New) {\n return Meaning.ConstructSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.Index) {\n return Meaning.IndexSignature;\n }\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeParameter) {\n // This should have already been handled in `getDeclarationReferenceOfSymbol`.\n throw new InternalError('Not supported.');\n }\n return undefined;\n }\n\n private _symbolToDeclarationReference(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags,\n includeModuleSymbols: boolean\n ): DeclarationReference | undefined {\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n\n let followedSymbol: ts.Symbol = symbol;\n if (followedSymbol.flags & ts.SymbolFlags.ExportValue) {\n followedSymbol = this._collector.typeChecker.getExportSymbolOfSymbol(followedSymbol);\n }\n if (followedSymbol.flags & ts.SymbolFlags.Alias) {\n followedSymbol = this._collector.typeChecker.getAliasedSymbol(followedSymbol);\n }\n\n if (DeclarationReferenceGenerator._isExternalModuleSymbol(followedSymbol)) {\n if (!includeModuleSymbols) {\n return undefined;\n }\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n }\n\n // Do not generate a declaration reference for a type parameter.\n if (followedSymbol.flags & ts.SymbolFlags.TypeParameter) {\n return undefined;\n }\n\n let parentRef: DeclarationReference | undefined = this._getParentReference(followedSymbol);\n if (!parentRef) {\n return undefined;\n }\n\n let localName: string = followedSymbol.name;\n if (followedSymbol.escapedName === ts.InternalSymbolName.Constructor) {\n localName = 'constructor';\n } else {\n const wellKnownName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(\n followedSymbol.escapedName\n );\n if (wellKnownName) {\n // TypeScript binds well-known ECMAScript symbols like 'Symbol.iterator' as '__@iterator'.\n // This converts a string like '__@iterator' into the property name '[Symbol.iterator]'.\n localName = wellKnownName;\n } else if (TypeScriptHelpers.isUniqueSymbolName(followedSymbol.escapedName)) {\n for (const decl of followedSymbol.declarations || []) {\n const declName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(decl);\n if (declName && ts.isComputedPropertyName(declName)) {\n const lateName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declName);\n if (lateName !== undefined) {\n localName = lateName;\n break;\n }\n }\n }\n }\n }\n\n const navigation: Navigation = this._getNavigationToSymbol(followedSymbol);\n\n // If the symbol is a global, ensure the source is global.\n if (sourceFile && !ts.isExternalModule(sourceFile) && parentRef.source !== GlobalSource.instance) {\n parentRef = new DeclarationReference(GlobalSource.instance);\n }\n\n return parentRef\n .addNavigationStep(navigation, localName)\n .withMeaning(DeclarationReferenceGenerator._getMeaningOfSymbol(followedSymbol, meaning));\n }\n\n private _getParentReference(symbol: ts.Symbol): DeclarationReference | undefined {\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n\n // First, try to find a parent symbol via the symbol tree.\n const parentSymbol: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n if (parentSymbol) {\n return this._symbolToDeclarationReference(\n parentSymbol,\n parentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n\n // If that doesn't work, try to find a parent symbol via the node tree. As far as we can tell,\n // this logic is only needed for local symbols within namespaces. For example:\n //\n // ```\n // export namespace n {\n // type SomeType = number;\n // export function someFunction(): SomeType { return 5; }\n // }\n // ```\n //\n // In the example above, `SomeType` doesn't have a parent symbol per the TS internal API above,\n // but its reference still needs to be qualified with the parent reference for `n`.\n const grandParent: ts.Node | undefined = declaration?.parent?.parent;\n if (grandParent && ts.isModuleDeclaration(grandParent)) {\n const grandParentSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetSymbolForDeclaration(\n grandParent,\n this._collector.typeChecker\n );\n if (grandParentSymbol) {\n return this._symbolToDeclarationReference(\n grandParentSymbol,\n grandParentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n }\n\n // At this point, we have a local symbol in a module.\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n } else {\n return new DeclarationReference(GlobalSource.instance);\n }\n }\n\n private _getPackageName(sourceFile: ts.SourceFile): string {\n if (this._collector.program.isSourceFileFromExternalLibrary(sourceFile)) {\n const packageJson: INodePackageJson | undefined =\n this._collector.packageJsonLookup.tryLoadNodePackageJsonFor(sourceFile.fileName);\n\n if (packageJson && packageJson.name) {\n return packageJson.name;\n }\n return DeclarationReferenceGenerator.unknownReference;\n }\n return this._collector.workingPackage.name;\n }\n\n private _sourceFileToModuleSource(sourceFile: ts.SourceFile | undefined): GlobalSource | ModuleSource {\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n const packageName: string = this._getPackageName(sourceFile);\n\n if (this._collector.bundledPackageNames.has(packageName)) {\n // The api-extractor.json config file has a \"bundledPackages\" setting, which causes imports from\n // certain NPM packages to be treated as part of the working project. In this case, we need to\n // substitute the working package name.\n return new ModuleSource(this._collector.workingPackage.name);\n } else {\n return new ModuleSource(packageName);\n }\n }\n return GlobalSource.instance;\n }\n}\n"]}
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
// ("enabled" is required)
|
|
19
19
|
"reportFileName": "<unscopedPackageName>.api.md",
|
|
20
20
|
"reportFolder": "<projectFolder>/etc/",
|
|
21
|
-
"reportTempFolder": "<projectFolder>/temp/"
|
|
21
|
+
"reportTempFolder": "<projectFolder>/temp/",
|
|
22
|
+
"includeForgottenExports": false
|
|
22
23
|
},
|
|
23
24
|
|
|
24
25
|
"docModel": {
|
|
25
26
|
// ("enabled" is required)
|
|
26
|
-
"apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
|
27
|
+
"apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json",
|
|
28
|
+
"includeForgottenExports": false
|
|
27
29
|
},
|
|
28
30
|
|
|
29
31
|
"dtsRollup": {
|
|
@@ -80,12 +80,13 @@
|
|
|
80
80
|
// "testMode": false,
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Specifies how API Extractor sorts members of an enum when generating api.json. By default, the output
|
|
84
|
-
* will be sorted alphabetically, which is "by-name". To keep the ordering in the source code, specify
|
|
83
|
+
* Specifies how API Extractor sorts members of an enum when generating the .api.json file. By default, the output
|
|
84
|
+
* files will be sorted alphabetically, which is "by-name". To keep the ordering in the source code, specify
|
|
85
|
+
* "preserve".
|
|
85
86
|
*
|
|
86
87
|
* DEFAULT VALUE: "by-name"
|
|
87
88
|
*/
|
|
88
|
-
// enumMemberOrder
|
|
89
|
+
// "enumMemberOrder": "by-name",
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
|
|
@@ -175,7 +176,16 @@
|
|
|
175
176
|
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
|
176
177
|
* DEFAULT VALUE: "<projectFolder>/temp/"
|
|
177
178
|
*/
|
|
178
|
-
// "reportTempFolder": "<projectFolder>/temp/"
|
|
179
|
+
// "reportTempFolder": "<projectFolder>/temp/",
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether "forgotten exports" should be included in the API report file. Forgotten exports are declarations
|
|
183
|
+
* flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to
|
|
184
|
+
* learn more.
|
|
185
|
+
*
|
|
186
|
+
* DEFAULT VALUE: "false"
|
|
187
|
+
*/
|
|
188
|
+
// "includeForgottenExports": false
|
|
179
189
|
},
|
|
180
190
|
|
|
181
191
|
/**
|
|
@@ -196,7 +206,16 @@
|
|
|
196
206
|
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
|
197
207
|
* DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
|
198
208
|
*/
|
|
199
|
-
// "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
|
209
|
+
// "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json",
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Whether "forgotten exports" should be included in the doc model file. Forgotten exports are declarations
|
|
213
|
+
* flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to
|
|
214
|
+
* learn more.
|
|
215
|
+
*
|
|
216
|
+
* DEFAULT VALUE: "false"
|
|
217
|
+
*/
|
|
218
|
+
// "includeForgottenExports": false
|
|
200
219
|
},
|
|
201
220
|
|
|
202
221
|
/**
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
|
|
34
34
|
"enumMemberOrder": {
|
|
35
|
-
"description":
|
|
35
|
+
"description": "Specifies how API Extractor sorts the members of an enum when generating the .api.json doc model. \n 'by-name': sort the items according to the enum member name \n 'preserve': keep the original order that items appear in the source code",
|
|
36
36
|
"type": "string",
|
|
37
37
|
"enum": ["by-name", "preserve"],
|
|
38
38
|
"default": "by-name"
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"reportTempFolder": {
|
|
81
81
|
"description": "Specifies the folder where the temporary report file is written. The file name portion is determined by the \"reportFileName\" setting. After the temporary file is written to disk, it is compared with the file in the \"reportFolder\". If they are different, a production build will fail. The path is resolved relative to the folder of the config file that contains the setting; to change this, prepend a folder token such as \"<projectFolder>\".",
|
|
82
82
|
"type": "string"
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
"includeForgottenExports": {
|
|
86
|
+
"description": "Whether \"forgotten exports\" should be included in the API report file. Forgotten exports are declarations flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to learn more.",
|
|
87
|
+
"type": "boolean"
|
|
83
88
|
}
|
|
84
89
|
},
|
|
85
90
|
"required": ["enabled"],
|
|
@@ -97,6 +102,11 @@
|
|
|
97
102
|
"apiJsonFilePath": {
|
|
98
103
|
"description": "The output path for the doc model file. The file extension should be \".api.json\". The path is resolved relative to the folder of the config file that contains the setting; to change this, prepend a folder token such as \"<projectFolder>\".",
|
|
99
104
|
"type": "string"
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
"includeForgottenExports": {
|
|
108
|
+
"description": "Whether \"forgotten exports\" should be included in the doc model file. Forgotten exports are declarations flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to learn more.",
|
|
109
|
+
"type": "boolean"
|
|
100
110
|
}
|
|
101
111
|
},
|
|
102
112
|
"required": ["enabled"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/api-extractor",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.30.1",
|
|
4
4
|
"description": "Analyze the exported API for a TypeScript library and generate reviews, documentation, and .d.ts rollups",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@microsoft/api-extractor-model": "7.
|
|
35
|
+
"@microsoft/api-extractor-model": "7.24.0",
|
|
36
36
|
"@microsoft/tsdoc": "0.14.1",
|
|
37
37
|
"@microsoft/tsdoc-config": "~0.16.1",
|
|
38
|
-
"@rushstack/node-core-library": "3.51.
|
|
38
|
+
"@rushstack/node-core-library": "3.51.1",
|
|
39
39
|
"@rushstack/rig-package": "0.3.14",
|
|
40
40
|
"@rushstack/ts-command-line": "4.12.2",
|
|
41
41
|
"colors": "~1.2.1",
|
|
@@ -59,6 +59,5 @@
|
|
|
59
59
|
"build": "heft build --clean",
|
|
60
60
|
"_phase:build": "heft build --clean",
|
|
61
61
|
"_phase:test": "heft test --no-build"
|
|
62
|
-
}
|
|
63
|
-
"readme": "# @microsoft/api-extractor\n\n\n\n<br />\n https://api-extractor.com/\n\n<!-- ------------------------------------------------------------------ -->\n<!-- Text below this line should stay in sync with the web site content -->\n<!-- ------------------------------------------------------------------ -->\n\n**API Extractor** helps you build better [TypeScript](https://www.typescriptlang.org/) library packages. Suppose for example that your company has published an NPM package called \"**awesome-widgets**\" that exports many classes and interfaces. As developers start to depend on your library, you may encounter issues such as...\n\n- **Accidental breaks:** People keep reporting that their code won't compile after a supposedly \"minor\" update. To address this, you boldly propose that every **awesome-widgets** pull request must be approved by an experienced developer from your team. But that proves unrealistic -- nobody has time to look at every single PR! What you really need is a way to detect PRs that change API contracts, and flag them for review. That would focus attention in the right place... but how to do that?\n\n- **Missing exports:** Suppose the **awesome-widgets** package exports an API function `AwesomeButton.draw()` that requires a parameter of type `DrawStyle`, but you forgot to export this enum. Things seem fine at first, but when a developer tries to call that function, they discover that there's no way to specify the `DrawStyle`. How to avoid these oversights?\n\n- **Accidental exports:** You meant for your `DrawHelper` class to be kept internal, but one day you realize it's being exported. When you try to remove it, consumers complain that they're using it. How do we avoid this in the future?\n\n- **Alpha/Beta graduation:** You want to release previews of new APIs that are not ready for prime time yet. But if you did a major SemVer bump every time these definitions evolve, the villagers would be after you with torches and pitchforks! A better approach is to designate certain classes/members as **alpha** quality, then promote them to **beta** and finally to **public** as they mature. But how to indicate this to your consumers? (And how to detect scoping mistakes? A **public** function should never return a **beta** result.)\n\n- **\\*.d.ts rollup:** You webpacked your library into a nice **\\*.js** bundle file -- so why ship your typings as a messy tree of **lib/\\*.d.ts** files full of private definitions? Can't we consolidate them into a tidy **\\*.d.ts** rollup file? And if you publish internal/beta/public releases, each release type should get its own **\\*.d.ts** file with appropriate trimming. Developers building a production project don't want to see a bunch of **internal** and **beta** members in their VS Code IntelliSense!\n\n- **Online documentation:** You have faithfully annotated each TypeScript member with nice [TSDoc](https://github.com/microsoft/tsdoc) descriptions. Now that your library has shipped, it's time to set up [a nicely formatted](https://docs.microsoft.com/en-us/javascript/api/sp-http) API reference. What tool to use?\n\n**API Extractor** provides an integrated, professional-quality solution for all these problems. It is invoked at build time by your toolchain and leverages the TypeScript compiler engine to:\n\n- Detect a project's exported API surface\n- Capture the contracts in a concise report designed to facilitate review\n- Warn about common mistakes (e.g. missing exports, inconsistent visibility, etc.)\n- Generate \\*.d.ts rollups with trimming according to release type\n- Output API documentation in a portable format that's easy to integrate with your content pipeline\n\nBest of all, **API Extractor** is free and open source. Join the community and create a pull request!\n\n<!-- ------------------------------------------------------------------ -->\n<!-- Text above this line should stay in sync with the web site content -->\n<!-- ------------------------------------------------------------------ -->\n\n## Getting Started\n\nFor more details and support resources, please visit: https://api-extractor.com/\n\n## Links\n\n- [CHANGELOG.md](\n https://github.com/microsoft/rushstack/blob/main/apps/api-extractor/CHANGELOG.md) - Find\n out what's new in the latest version\n- [API Reference](https://rushstack.io/pages/api/api-extractor/)\n\nAPI Extractor is part of the [Rush Stack](https://rushstack.io/) family of projects.\n"
|
|
62
|
+
}
|
|
64
63
|
}
|