Skip to content

Commit

Permalink
Merge pull request #4529 from Josmithr/dont-trim-imports
Browse files Browse the repository at this point in the history
fix(api-extractor): Don't trim imports from external packages based on their release tags
  • Loading branch information
octogonz authored Feb 21, 2024
2 parents ab3bc75 + ef715d3 commit 97ab367
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 5 additions & 11 deletions apps/api-extractor/src/generators/DtsRollupGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,12 @@ export class DtsRollupGenerator {
// Emit the imports
for (const entity of collector.entities) {
if (entity.astEntity instanceof AstImport) {
// Note: it isn't valid to trim imports based on their release tags.
// E.g. class Foo (`@public`) extends interface Bar (`@beta`) from some external library.
// API-Extractor cannot trim `import { Bar } from "externa-library"` when generating its public rollup,
// or the export of `Foo` would include a broken reference to `Bar`.
const astImport: AstImport = entity.astEntity;

// For example, if the imported API comes from an external package that supports AEDoc,
// and it was marked as `@internal`, then don't emit it.
const symbolMetadata: SymbolMetadata | undefined = collector.tryFetchMetadataForAstEntity(astImport);
const maxEffectiveReleaseTag: ReleaseTag = symbolMetadata
? symbolMetadata.maxEffectiveReleaseTag
: ReleaseTag.None;

if (this._shouldIncludeReleaseTag(maxEffectiveReleaseTag, dtsKind)) {
DtsEmitHelpers.emitImport(writer, entity, astImport);
}
DtsEmitHelpers.emitImport(writer, entity, astImport);
}
}
writer.ensureSkippedLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Fix an issue where imports were trimmed from external packages based when generating .d.ts rollups",
"type": "patch"
}
],
"packageName": "@microsoft/api-extractor"
}

0 comments on commit 97ab367

Please sign in to comment.