Skip to content

Commit 291f6cf

Browse files
devversionjosephperrott
authored andcommitted
chore: filter alias exports in docs (#8782)
1 parent 444784b commit 291f6cf

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tools/dgeni/index.ts

Lines changed: 3 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 {FilterExportAliases} from './processors/filter-export-aliases';
45
import {ComponentGrouper} from './processors/component-grouper';
56
import {ReadTypeScriptModules} from 'dgeni-packages/typescript/processors/readTypeScriptModules';
67
import {TsParser} from 'dgeni-packages/typescript/services/TsParser';
@@ -47,6 +48,8 @@ const materialPackages = globSync(path.join(sourceDir, 'lib', '*/'))
4748

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

51+
// Processor that filters out aliased exports that should not be shown in the docs.
52+
apiDocsPackage.processor(new FilterExportAliases());
5053

5154
// Processor that filters out symbols that should not be shown in the docs.
5255
apiDocsPackage.processor(new DocsPrivateFilter());
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {DocCollection, Processor} from 'dgeni';
2+
import {ExportDoc} from 'dgeni-packages/typescript/api-doc-types/ExportDoc';
3+
import {ModuleDoc} from 'dgeni-packages/typescript/api-doc-types/ModuleDoc';
4+
5+
/**
6+
* Processor to filter out Dgeni documents that are export aliases. Keeping them means
7+
* that a given document shows up multiple times in the docs.
8+
*
9+
* ```ts
10+
* export {ObserveContent} from './X';
11+
* export {ObserveContent as CdkObserveContent} from './X';
12+
* ```
13+
*
14+
* This is a common pattern inside of Angular Material, but causes Dgeni to generate
15+
* documents for both exports. The second document is identical to the original document and
16+
* doesn't even show the aliased name.
17+
*
18+
* See: https://github.com/angular/dgeni-packages/issues/248
19+
*/
20+
export class FilterExportAliases implements Processor {
21+
name = 'filter-export-aliases';
22+
$runBefore = ['categorizer'];
23+
24+
$process(docs: DocCollection) {
25+
return docs.filter(doc => this.filterAliasExport(doc));
26+
}
27+
28+
private filterAliasExport(doc: ExportDoc) {
29+
if (!doc.moduleDoc) {
30+
return true;
31+
}
32+
33+
const moduleDoc = doc.moduleDoc as ModuleDoc;
34+
const duplicateDocs = moduleDoc.exports.filter(exportDoc => exportDoc.id === doc.id);
35+
36+
// Remove the current export document if there are multiple Dgeni export documents with the
37+
// same document id. If there are multiple docs with the same id, we can assume that this doc
38+
// is an alias export.
39+
if (duplicateDocs && duplicateDocs.length > 1) {
40+
moduleDoc.exports.splice(
41+
moduleDoc.exports.findIndex(exportDoc => exportDoc.id === doc.id), 1);
42+
return false;
43+
}
44+
45+
return true;
46+
}
47+
48+
}

0 commit comments

Comments
 (0)