Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-extractor] Don't export trimmed namespace members during rollup #2793

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/api-extractor/src/generators/DtsRollupGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export class DtsRollupGenerator {
);
}

// If the entity's declaration won't be included, then neither should the namespace export it
// This fixes the issue encountered here: https://github.com/microsoft/rushstack/issues/2791
const exportedSymbolMetadata: SymbolMetadata | undefined =
collector.tryFetchMetadataForAstEntity(exportedEntity);
const exportedMaxEffectiveReleaseTag: ReleaseTag = exportedSymbolMetadata
? exportedSymbolMetadata.maxEffectiveReleaseTag
: ReleaseTag.None;
if (!this._shouldIncludeReleaseTag(exportedMaxEffectiveReleaseTag, dtsKind)) {
continue;
}

if (collectorEntity.nameForEmit === exportedName) {
exportClauses.push(collectorEntity.nameForEmit);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
{
"metadata": {
"toolPackage": "@microsoft/api-extractor",
"toolVersion": "[test mode]",
"schemaVersion": 1011,
"oldestForwardsCompatibleVersion": 1001,
"tsdocConfig": {
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"noStandardTags": true,
"tagDefinitions": [
{
"tagName": "@alpha",
"syntaxKind": "modifier"
},
{
"tagName": "@beta",
"syntaxKind": "modifier"
},
{
"tagName": "@defaultValue",
"syntaxKind": "block"
},
{
"tagName": "@decorator",
"syntaxKind": "block",
"allowMultiple": true
},
{
"tagName": "@deprecated",
"syntaxKind": "block"
},
{
"tagName": "@eventProperty",
"syntaxKind": "modifier"
},
{
"tagName": "@example",
"syntaxKind": "block",
"allowMultiple": true
},
{
"tagName": "@experimental",
"syntaxKind": "modifier"
},
{
"tagName": "@inheritDoc",
"syntaxKind": "inline"
},
{
"tagName": "@internal",
"syntaxKind": "modifier"
},
{
"tagName": "@label",
"syntaxKind": "inline"
},
{
"tagName": "@link",
"syntaxKind": "inline",
"allowMultiple": true
},
{
"tagName": "@override",
"syntaxKind": "modifier"
},
{
"tagName": "@packageDocumentation",
"syntaxKind": "modifier"
},
{
"tagName": "@param",
"syntaxKind": "block",
"allowMultiple": true
},
{
"tagName": "@privateRemarks",
"syntaxKind": "block"
},
{
"tagName": "@public",
"syntaxKind": "modifier"
},
{
"tagName": "@readonly",
"syntaxKind": "modifier"
},
{
"tagName": "@remarks",
"syntaxKind": "block"
},
{
"tagName": "@returns",
"syntaxKind": "block"
},
{
"tagName": "@sealed",
"syntaxKind": "modifier"
},
{
"tagName": "@see",
"syntaxKind": "block"
},
{
"tagName": "@throws",
"syntaxKind": "block",
"allowMultiple": true
},
{
"tagName": "@typeParam",
"syntaxKind": "block",
"allowMultiple": true
},
{
"tagName": "@virtual",
"syntaxKind": "modifier"
},
{
"tagName": "@betaDocumentation",
"syntaxKind": "modifier"
},
{
"tagName": "@internalRemarks",
"syntaxKind": "block"
},
{
"tagName": "@preapproved",
"syntaxKind": "modifier"
}
],
"supportForTags": {
"@alpha": true,
"@beta": true,
"@defaultValue": true,
"@decorator": true,
"@deprecated": true,
"@eventProperty": true,
"@example": true,
"@experimental": true,
"@inheritDoc": true,
"@internal": true,
"@label": true,
"@link": true,
"@override": true,
"@packageDocumentation": true,
"@param": true,
"@privateRemarks": true,
"@public": true,
"@readonly": true,
"@remarks": true,
"@returns": true,
"@sealed": true,
"@see": true,
"@throws": true,
"@typeParam": true,
"@virtual": true,
"@betaDocumentation": true,
"@internalRemarks": true,
"@preapproved": true
},
"reportUnsupportedHtmlElements": false
}
},
"kind": "Package",
"canonicalReference": "api-extractor-scenarios!",
"docComment": "",
"name": "api-extractor-scenarios",
"preserveMemberOrder": false,
"members": [
{
"kind": "EntryPoint",
"canonicalReference": "api-extractor-scenarios!",
"name": "",
"preserveMemberOrder": false,
"members": [
{
"kind": "Namespace",
"canonicalReference": "api-extractor-scenarios!NS:namespace",
"docComment": "",
"excerptTokens": [],
"fileUrlPath": "src/exportImportStarAs3/index.ts",
"releaseTag": "None",
"name": "NS",
"preserveMemberOrder": false,
"members": [
{
"kind": "Variable",
"canonicalReference": "api-extractor-scenarios!NS.NS_BETA:var",
"docComment": "/**\n * @beta\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "NS_BETA = "
},
{
"kind": "Content",
"text": "\"BETA\""
}
],
"fileUrlPath": "src/exportImportStarAs3/NamespaceWithTrimming.ts",
"initializerTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"isReadonly": true,
"releaseTag": "Beta",
"name": "NS_BETA",
"variableTypeTokenRange": {
"startIndex": 0,
"endIndex": 0
}
},
{
"kind": "Variable",
"canonicalReference": "api-extractor-scenarios!NS.NS_PUBLIC:var",
"docComment": "/**\n * @public\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "NS_PUBLIC = "
},
{
"kind": "Content",
"text": "\"PUBLIC\""
}
],
"fileUrlPath": "src/exportImportStarAs3/NamespaceWithTrimming.ts",
"initializerTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"isReadonly": true,
"releaseTag": "Public",
"name": "NS_PUBLIC",
"variableTypeTokenRange": {
"startIndex": 0,
"endIndex": 0
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## API Report File for "api-extractor-scenarios"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

declare namespace NS {
export {
NS_PUBLIC,
NS_BETA,
NS_INTERNAL
}
}
export { NS }

// @beta (undocumented)
const NS_BETA = "BETA";

// @internal (undocumented)
const NS_INTERNAL = "INTERNAL";

// @public (undocumented)
const NS_PUBLIC = "PUBLIC";

// (No @packageDocumentation comment for this package)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare namespace NS {
export {
NS_PUBLIC
}
}
export { NS }

/* Excluded from this release type: NS_BETA */

/* Excluded from this release type: NS_INTERNAL */

/** @public */
declare const NS_PUBLIC = "PUBLIC";

export { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare namespace NS {
export {
NS_PUBLIC,
NS_BETA,
NS_INTERNAL
}
}
export { NS }

/** @beta */
declare const NS_BETA = "BETA";

/** @internal */
declare const NS_INTERNAL = "INTERNAL";

/** @public */
declare const NS_PUBLIC = "PUBLIC";

export { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @public */
export const NS_PUBLIC = 'PUBLIC';

/** @beta */
export const NS_BETA = 'BETA';

/** @internal */
export const NS_INTERNAL = 'INTERNAL';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/temp/etc/exportImportStarAs3/rollup.d.ts",
"publicTrimmedFilePath": "<projectFolder>/temp/etc/exportImportStarAs3/rollup-public.d.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Test that when exporting namespaces, we don't export members that got trimmed.
* See this issue: https://github.com/microsoft/rushstack/issues/2791
*/
import * as NS from './NamespaceWithTrimming';
export { NS };
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export namespace EntangledNamespace {
export type ExportedAlias = AlphaClass;

// Warning: (ae-internal-missing-underscore) The name "InternalClass" should be prefixed with an underscore because the declaration is marked as @internal
//
//
// @internal
export class InternalClass {
undecoratedMember(): void;
}

// Warning: (ae-internal-missing-underscore) The name "IPublicClassInternalParameters" should be prefixed with an underscore because the declaration is marked as @internal
//
//
// @internal
export interface IPublicClassInternalParameters {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Don't export trimmed namespace members during rollup (#2791)",
"type": "patch"
}
],
"packageName": "@microsoft/api-extractor",
"email": "14597409+SchoofsKelvin@users.noreply.github.com"
}