Skip to content

build: api-docs can display incorrect module for entry-point #16470

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tools/dgeni/common/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export function isDeprecatedDoc(doc: any) {
return (doc.tags && doc.tags.tags || []).some((tag: any) => tag.tagName === 'deprecated');
}

/** Whether the given document is annotated with the "@docs-primary-module" jsdoc tag. */
export function isPrimaryModuleDoc(doc: any) {
return (doc.tags && doc.tags.tags || [])
.some((tag: any) => tag.tagName === 'docs-primary-module');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in another PR, but we should have some docs about our custom JsDoc tags

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally. I had the same thought when creating that PR and created #16469 for tracking.

}

export function getDirectiveSelectors(classDoc: CategorizedClassDoc) {
if (!classDoc.directiveMetadata) {
return;
Expand Down
1 change: 1 addition & 0 deletions tools/dgeni/docs-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ apiDocsPackage.config(function(parseTagsProcessor: any) {
parseTagsProcessor.tagDefinitions = parseTagsProcessor.tagDefinitions.concat([
{name: 'docs-private'},
{name: 'docs-public'},
{name: 'docs-primary-module'},
{name: 'breaking-change'},
]);
});
Expand Down
34 changes: 31 additions & 3 deletions tools/dgeni/processors/entry-point-grouper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/Interf
import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc';
import * as path from 'path';
import {computeApiDocumentUrl} from '../common/compute-api-url';
import {isDeprecatedDoc, isPrimaryModuleDoc} from '../common/decorators';
import {CategorizedClassDoc} from '../common/dgeni-definitions';

export interface ModuleInfo {
Expand Down Expand Up @@ -64,8 +65,11 @@ export class EntryPointDoc {
/** Constants that belong to the entry-point. */
constants: ConstExportDoc[] = [];

/** NgModule that defines the current entry-point. */
ngModule: CategorizedClassDoc | null = null;
/** List of NgModules which are exported in the current entry-point. */
exportedNgModules: CategorizedClassDoc[] = [];

/** NgModule that defines the current entry-point. Null if no module could be found. */
ngModule: CategorizedClassDoc|null = null;

constructor(name: string) {
this.name = name;
Expand Down Expand Up @@ -117,7 +121,12 @@ export class EntryPointGrouper implements Processor {
} else if (doc.isService) {
entryPoint.services.push(doc);
} else if (doc.isNgModule) {
entryPoint.ngModule = doc;
entryPoint.exportedNgModules.push(doc);
// If the module is explicitly marked as primary module using the "@docs-primary-module"
// annotation, we set is as primary entry-point module.
if (isPrimaryModuleDoc(doc)) {
entryPoint.ngModule = doc;
}
} else if (doc.docType === 'class') {
entryPoint.classes.push(doc);
} else if (doc.docType === 'interface') {
Expand All @@ -131,6 +140,25 @@ export class EntryPointGrouper implements Processor {
}
});

// For each entry-point we determine a primary NgModule that defines the entry-point
// if no primary module has been explicitly declared (using "@docs-primary-module").
entryPoints.forEach(entryPoint => {
if (entryPoint.ngModule !== null) {
return;
}

// Usually the first module that is not deprecated is used, but in case there are
// only deprecated modules, the last deprecated module is used. We don't want to
// always skip deprecated modules as they could be still needed for documentation
// of a deprecated entry-point.
for (let ngModule of entryPoint.exportedNgModules) {
entryPoint.ngModule = ngModule;
if (!isDeprecatedDoc(ngModule)) {
break;
}
}
});

return Array.from(entryPoints.values());
}
}
Expand Down