Skip to content

Commit c10e3f9

Browse files
committed
Add api extractor config overrides, fix child method trimming
1 parent a7d5bd2 commit c10e3f9

File tree

8 files changed

+84
-12
lines changed

8 files changed

+84
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ export class Collector {
526526
astDeclaration.declaration.kind === ts.SyntaxKind.FunctionDeclaration ||
527527
astDeclaration.declaration.kind === ts.SyntaxKind.MethodDeclaration
528528
) {
529-
// For functions overrides, take the highest accessability from multiple declarations
529+
// For function and method overloads, take the highest release from multiple declarations
530530
if (effectiveReleaseTag < declaredReleaseTag) {
531531
effectiveReleaseTag = declaredReleaseTag;
532532
}

apps/api-extractor/src/generators/ApiModelGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ export class ApiModelGenerator {
433433
if (declaredReleaseTag === ReleaseTag.Internal || declaredReleaseTag === ReleaseTag.Alpha) {
434434
return; // trim out items marked as "@internal" or "@alpha"
435435
}
436-
// If we have less accessible function overloads, include that information
436+
// If we have lower-release function overloads, include that information
437437
const symbolMetadata: SymbolMetadata = this._collector.fetchMetadata(astDeclaration.astSymbol);
438438
const releaseTag: ReleaseTag = (
439439
declaredReleaseTag !== ReleaseTag.None &&
@@ -573,7 +573,7 @@ export class ApiModelGenerator {
573573
if (declaredReleaseTag === ReleaseTag.Internal || declaredReleaseTag === ReleaseTag.Alpha) {
574574
return; // trim out items marked as "@internal" or "@alpha"
575575
}
576-
// If we have less accessible function overloads, include that information
576+
// If we have lower-release function overloads, include that information
577577
const symbolMetadata: SymbolMetadata = this._collector.fetchMetadata(astDeclaration.astSymbol);
578578
const releaseTag: ReleaseTag = (
579579
declaredReleaseTag !== ReleaseTag.None &&

apps/api-extractor/src/generators/ApiReportGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export class ApiReportGenerator {
374374

375375
const declarationMetadata: DeclarationMetadata = collector.fetchMetadata(astDeclaration);
376376
const symbolMetadata: SymbolMetadata = collector.fetchMetadata(astDeclaration.astSymbol);
377-
// If we have less accessible function overloads, include that information
377+
// If we have lower-release function overloads, include that information
378378
const useDeclarationReleaseTag: boolean = (
379379
astDeclaration.declaration.kind === ts.SyntaxKind.FunctionDeclaration ||
380380
astDeclaration.declaration.kind === ts.SyntaxKind.MethodDeclaration

apps/api-extractor/src/generators/DtsRollupGenerator.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,10 @@ export class DtsRollupGenerator {
113113
// Emit all the declarations for this entry
114114
for (const astDeclaration of entity.astEntity.astDeclarations || []) {
115115
const declarationMetadata: DeclarationMetadata = collector.fetchMetadata(astDeclaration);
116-
const checkDeclarationReleaseTag: boolean = (
117-
astDeclaration.declaration.kind === ts.SyntaxKind.FunctionDeclaration ||
118-
astDeclaration.declaration.kind === ts.SyntaxKind.MethodDeclaration
119-
) && !!declarationMetadata;
120116

121117
if (
122-
checkDeclarationReleaseTag &&
118+
astDeclaration.declaration.kind === ts.SyntaxKind.FunctionDeclaration &&
119+
!!declarationMetadata &&
123120
!this._shouldIncludeReleaseTag(declarationMetadata.declaredReleaseTag, dtsKind)
124121
) {
125122
if (!collector.extractorConfig.omitTrimmingComments) {
@@ -279,8 +276,17 @@ export class DtsRollupGenerator {
279276
let trimmed: boolean = false;
280277
if (AstDeclaration.isSupportedSyntaxKind(child.kind)) {
281278
childAstDeclaration = collector.astSymbolTable.getChildAstDeclarationByNode(child.node, astDeclaration);
279+
const childDeclarationMetadata: DeclarationMetadata = collector.fetchMetadata(childAstDeclaration);
280+
const symbolMetadata: SymbolMetadata = collector.fetchMetadata(childAstDeclaration.astSymbol);
281+
// If we have lower-release method overloads, include that information
282+
const useDeclarationReleaseTag: boolean = (
283+
childAstDeclaration.declaration.kind === ts.SyntaxKind.MethodDeclaration &&
284+
!!childDeclarationMetadata
285+
);
286+
const releaseTag: ReleaseTag = useDeclarationReleaseTag
287+
? childDeclarationMetadata.declaredReleaseTag
288+
: symbolMetadata.releaseTag;
282289

283-
const releaseTag: ReleaseTag = collector.fetchMetadata(childAstDeclaration.astSymbol).releaseTag;
284290
if (!this._shouldIncludeReleaseTag(releaseTag, dtsKind)) {
285291
let nodeToTrim: Span = child;
286292

@@ -301,7 +307,9 @@ export class DtsRollupGenerator {
301307
modification.omitChildren = true;
302308

303309
if (!collector.extractorConfig.omitTrimmingComments) {
304-
modification.prefix = `/* Excluded from this release type: ${name} */`;
310+
modification.prefix = useDeclarationReleaseTag
311+
? `/* Excluded from this release type: ${name} overload */`
312+
: `/* Excluded from this release type: ${name} */`;
305313
} else {
306314
modification.prefix = '';
307315
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
/* Excluded from this release type: combine overload */
3+
4+
/**
5+
* @beta
6+
*/
7+
export declare function combine(x: string, y: string): string;
8+
9+
/**
10+
* @public
11+
*/
12+
export declare function combine(x: number, y: number): number;
13+
14+
/**
15+
* @public
16+
*/
17+
export declare class Combiner {
18+
/* Excluded from this release type: combine overload */
19+
/**
20+
* @beta
21+
*/
22+
combine(x: string, y: string): string;
23+
/**
24+
* @public
25+
*/
26+
combine(x: number, y: number): number;
27+
}
28+
29+
export { }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
/* Excluded from this release type: combine overload */
3+
4+
/* Excluded from this release type: combine overload */
5+
6+
/**
7+
* @public
8+
*/
9+
export declare function combine(x: number, y: number): number;
10+
11+
/**
12+
* @public
13+
*/
14+
export declare class Combiner {
15+
/* Excluded from this release type: combine overload */
16+
/* Excluded from this release type: combine overload */
17+
/**
18+
* @public
19+
*/
20+
combine(x: number, y: number): number;
21+
}
22+
23+
export { }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dtsRollup": {
3+
"enabled": true,
4+
"untrimmedFilePath": "<projectFolder>/etc/test-outputs/functionOverload/rollup.d.ts",
5+
"betaTrimmedFilePath": "<projectFolder>/etc/test-outputs/functionOverload/beta-rollup.d.ts",
6+
"publicTrimmedFilePath": "<projectFolder>/etc/test-outputs/functionOverload/public-rollup.d.ts"
7+
},
8+
}

build-tests/api-extractor-scenarios/src/runScenarios.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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 * as fs from 'fs';
45
import * as path from 'path';
56
import { JsonFile } from '@microsoft/node-core-library';
67
import {
@@ -24,6 +25,8 @@ export function runScenarios(buildConfigPath: string): void {
2425
const entryPoint: string = path.resolve(`./lib/${scenarioFolderName}/index.d.ts`);
2526
entryPoints.push(entryPoint);
2627

28+
const overridesPath = path.resolve(`./src/${scenarioFolderName}/config/api-extractor-overrides.json`);
29+
const apiExtractorJsonOverrides = fs.existsSync(overridesPath) ? JsonFile.load(overridesPath) : {};
2730
const apiExtractorJson = {
2831
'$schema': 'https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json',
2932

@@ -59,7 +62,8 @@ export function runScenarios(buildConfigPath: string): void {
5962
}
6063
},
6164

62-
'testMode': true
65+
'testMode': true,
66+
...apiExtractorJsonOverrides
6367
};
6468

6569
const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;

0 commit comments

Comments
 (0)