Skip to content

Commit 5e6822d

Browse files
devversiontinayuangao
authored andcommitted
chore(dgeni): fix duplicate api doc entries (#9666)
* Fixes that some API document entries are showing up twice (e.g. https://material.angular.io/cdk/scrolling/api). This happens because the `ScrollDispatcher` is exported multiple times across different packages (`cdk/scrolling` and `cdk/overlay`).
1 parent 664d69e commit 5e6822d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tools/dgeni/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Package} from 'dgeni';
22
import {DocsPrivateFilter} from './processors/docs-private-filter';
33
import {Categorizer} from './processors/categorizer';
4+
import {FilterDuplicateExports} from './processors/filter-duplicate-exports';
45
import {FilterExportAliases} from './processors/filter-export-aliases';
56
import {MergeInheritedProperties} from './processors/merge-inherited-properties';
67
import {ComponentGrouper} from './processors/component-grouper';
@@ -49,6 +50,9 @@ const materialPackages = globSync(path.join(sourceDir, 'lib', '*/'))
4950

5051
export const apiDocsPackage = new Package('material2-api-docs', dgeniPackageDeps);
5152

53+
// Processor that filters out duplicate exports that should not be shown in the docs.
54+
apiDocsPackage.processor(new FilterDuplicateExports());
55+
5256
// Processor that filters out aliased exports that should not be shown in the docs.
5357
apiDocsPackage.processor(new FilterExportAliases());
5458

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {DocCollection, Processor} from 'dgeni';
2+
import {ExportDoc} from 'dgeni-packages/typescript/api-doc-types/ExportDoc';
3+
4+
/**
5+
* Processor to filter out Dgeni documents that are exported multiple times. This is necessary
6+
* to avoid that API entries are showing up multiple times in the docs.
7+
*
8+
* ```ts
9+
* // Some file in @angular/cdk/scrolling
10+
* export {ScrollDispatcher} from './scroll-dispatcher.ts';
11+
*
12+
* // Other file in @angular/cdk/overlay
13+
* export {ScrollDispatcher} from '@angular/cdk/scrolling';
14+
* ```
15+
*
16+
* This issue occurs sometimes in the Angular Material repository, if specific imports are
17+
* re-exported from a different secondary entry-point (e.g. ScrollDispatcher in the overlay).
18+
*/
19+
export class FilterDuplicateExports implements Processor {
20+
name = 'filter-duplicate-exports';
21+
$runBefore = ['filter-export-aliases'];
22+
23+
$process(docs: DocCollection) {
24+
return docs.forEach(this.checkForDuplicateExports);
25+
}
26+
27+
checkForDuplicateExports = (doc: ExportDoc, index: number, docs: DocCollection) => {
28+
if (!(doc instanceof ExportDoc)) {
29+
return;
30+
}
31+
32+
// Checks for export documents that have the same name, originate from the same module, but
33+
// have a different Dgeni document id. Those documents can be considered as duplicates.
34+
const duplicateDocs = docs.filter(d => doc.name === d.name &&
35+
doc.originalModule === d.originalModule && doc.id !== d.id);
36+
37+
if (duplicateDocs.length > 0) {
38+
docs.splice(index, 1);
39+
}
40+
}
41+
42+
}

0 commit comments

Comments
 (0)