build(docs-infra): process and render ngmodule exports (#25734)
All directives and pipes must now be tagged with one ore more public NgModule, from which they are exported. If an item is exported transitively via a re-exported internal NgModule then it may be that the item appears to be exported from more than one public NgModule. For example, there are shared directives that are exported in this way from `FormsModule` and `ReactiveFormsModule`. The doc-gen will error and fail if a directive or pipe is not tagged correctly. NgModule pages now list all the directives and pipes that are exported from it. Directive and Pipe pages now list any NgModule from which they are exported. Packages also now list any NgModules that are contained - previously they were missed. PR Close #25734
This commit is contained in:

committed by
Kara Erickson

parent
bc5cb8153e
commit
b94436d86c
@ -1,7 +1,7 @@
|
||||
module.exports = function processNgModuleDocs() {
|
||||
module.exports = function processNgModuleDocs(getDocFromAlias, createDocMessage, log) {
|
||||
return {
|
||||
$runAfter: ['extractDecoratedClassesProcessor'],
|
||||
$runBefore: ['docs-processed'],
|
||||
$runAfter: ['extractDecoratedClassesProcessor', 'computeIdsProcessor'],
|
||||
$runBefore: ['createSitemap'],
|
||||
$process(docs) {
|
||||
docs.forEach(doc => {
|
||||
if (doc.docType === 'ngmodule') {
|
||||
@ -13,6 +13,43 @@ module.exports = function processNgModuleDocs() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Match all the directives/pipes to their module
|
||||
const errors = [];
|
||||
docs.forEach(doc => {
|
||||
if (['directive', 'pipe'].indexOf(doc.docType) !== -1) {
|
||||
if (!doc.ngModules || doc.ngModules.length === 0) {
|
||||
errors.push(createDocMessage(`"${doc.id}" has no @ngModule tag. Docs of type "${doc.docType}" must have this tag.`, doc));
|
||||
return;
|
||||
}
|
||||
|
||||
doc.ngModules.forEach((ngModule, index) => {
|
||||
|
||||
const ngModuleDocs = getDocFromAlias(ngModule, doc);
|
||||
|
||||
if (ngModuleDocs.length === 0) {
|
||||
errors.push(createDocMessage(`"@ngModule ${ngModule}" does not match a public NgModule`, doc));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ngModuleDocs.length > 1) {
|
||||
errors.push(createDocMessage(`"@ngModule ${ngModule}" is ambiguous. Matches: ${ngModuleDocs.map(d => d.id).join(', ')}`, doc));
|
||||
return;
|
||||
}
|
||||
|
||||
const ngModuleDoc = ngModuleDocs[0];
|
||||
const container = ngModuleDoc[doc.docType + 's'] = ngModuleDoc[doc.docType + 's'] || [];
|
||||
container.push(doc);
|
||||
|
||||
doc.ngModules[index] = ngModuleDoc;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (errors.length) {
|
||||
errors.forEach(error => log.error(error));
|
||||
throw new Error('Failed to process NgModule relationships.');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user