Skip to content

Commit

Permalink
build: Patch api-extractor to not trim imports when generating type r…
Browse files Browse the repository at this point in the history
…ollups (#18621)

Expands on existing API-Extractor patching in place.

This patch mitigates an issue where imports (potentially from other
packages) are trimmed from the generated type rollups based on the
release tags associated with the imported items.
This issue has the potential to create invalid type rollups.
The mitigation is to simply not trim imports in the type rollups -
introducing (potentially) unused type imports is benign and should have
negligible impact on file sizes in most cases.
The relevant changes can be found on this branch:
https://github.com/Josmithr/rushstack/tree/dont-trim-imports
Related github issue: microsoft/rushstack#4425
  • Loading branch information
Josmithr authored Dec 6, 2023
1 parent ee948b5 commit 7a8b0b1
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 112 deletions.
25 changes: 24 additions & 1 deletion patches/@microsoft__api-extractor@7.38.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,27 @@ index 3511bb2fd2269cce8c45197ef8dc61c28158f743..61101cea95d362b94be8b9e9ccc3e833
+ if (!collectorEntity || !collectorEntity.consumable) {
const entryPointFilename = path.basename(collector.workingPackage.entryPointSourceFile.fileName);
if (!alreadyWarnedEntities.has(referencedEntity)) {
alreadyWarnedEntities.add(referencedEntity);
alreadyWarnedEntities.add(referencedEntity);
diff --git a/lib/generators/DtsRollupGenerator.js b/lib/generators/DtsRollupGenerator.js
index 5a6490760417c2cbefc8ff277f9183a7c870e797..4b93942c049e1fe3940f9cc71c781c591d2bb97a 100644
--- a/lib/generators/DtsRollupGenerator.js
+++ b/lib/generators/DtsRollupGenerator.js
@@ -103,16 +103,9 @@ class DtsRollupGenerator {
// Emit the imports
for (const entity of collector.entities) {
if (entity.astEntity instanceof AstImport_1.AstImport) {
+ // BUG MITIGATION: don't trim imports based on their release tags
const 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 = collector.tryFetchMetadataForAstEntity(astImport);
- const maxEffectiveReleaseTag = symbolMetadata
- ? symbolMetadata.maxEffectiveReleaseTag
- : api_extractor_model_1.ReleaseTag.None;
- if (this._shouldIncludeReleaseTag(maxEffectiveReleaseTag, dtsKind)) {
- DtsEmitHelpers_1.DtsEmitHelpers.emitImport(writer, entity, astImport);
- }
+ DtsEmitHelpers_1.DtsEmitHelpers.emitImport(writer, entity, astImport);
}
}
writer.ensureSkippedLine();
6 changes: 6 additions & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Related github issue: https://github.com/microsoft/rushstack/issues/4430
It also adds the ability to specify `bundledPackages` using regular expressions, rather than exact-match package names.
The relevant changes can be found on this branch: https://github.com/Josmithr/rushstack/tree/regexp-bundledPackages
Related github issue: https://github.com/microsoft/rushstack/issues/4426

Finally, it mitigates an issue where imports (potentially from other packages) are trimmed from the generated type rollups based on the release tags associated with the imported items.
This issue has the potential to create invalid type rollups.
The mitigation is to simply not trim imports in the type rollups - introducing (potentially) unused type imports is benign and should have negligable impact on file sizes in most cases.
The relevant changes can be found on this branch: https://github.com/Josmithr/rushstack/tree/dont-trim-imports
Related github issue: https://github.com/microsoft/rushstack/issues/4425
Loading

0 comments on commit 7a8b0b1

Please sign in to comment.