From 4e4fcacb6d1d4e2c063eeba3a56c31c9e11fae88 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Sat, 6 Feb 2021 15:59:12 +0200 Subject: [PATCH] fix(docs-infra): correctly handle entry-points with no public exports (#40737) Previously, if an entry-point had no public exports (such as the `@angular/platform-server/shims` introduced in #40559, which is a side-effect-ful entry-point), it was incorrectly marked as having all its exports deprecated (which marks the entry-point as deprecated as well). This commit fixes this by ensuring that an entry-point is not marked as having all its exports deprecated if it has no public exports. PR Close #40737 --- .../processors/processPackages.js | 3 +- .../processors/processPackages.spec.js | 48 +++++++++++++++++++ .../templates/api/package.template.html | 3 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/aio/tools/transforms/angular-api-package/processors/processPackages.js b/aio/tools/transforms/angular-api-package/processors/processPackages.js index b4cb80fd59..d9af8ac3a1 100644 --- a/aio/tools/transforms/angular-api-package/processors/processPackages.js +++ b/aio/tools/transforms/angular-api-package/processors/processPackages.js @@ -18,6 +18,7 @@ module.exports = function processPackages(collectPackageContentDocsProcessor) { // Partition the exports into groups by type if (doc.exports) { const publicExports = doc.exports.filter(doc => !doc.privateExport); + doc.hasPublicExports = publicExports.length > 0; doc.ngmodules = publicExports.filter(doc => doc.docType === 'ngmodule').sort(byId); doc.classes = publicExports.filter(doc => doc.docType === 'class').sort(byId); doc.decorators = publicExports.filter(doc => doc.docType === 'decorator').sort(byId); @@ -26,7 +27,7 @@ module.exports = function processPackages(collectPackageContentDocsProcessor) { doc.directives = publicExports.filter(doc => doc.docType === 'directive').sort(byId); doc.pipes = publicExports.filter(doc => doc.docType === 'pipe').sort(byId); doc.types = publicExports.filter(doc => doc.docType === 'type-alias' || doc.docType === 'const').sort(byId); - if (publicExports.every(doc => !!doc.deprecated)) { + if (doc.hasPublicExports && publicExports.every(doc => !!doc.deprecated)) { doc.deprecated = 'all exports of this entry point are deprecated.'; } } diff --git a/aio/tools/transforms/angular-api-package/processors/processPackages.spec.js b/aio/tools/transforms/angular-api-package/processors/processPackages.spec.js index 13fc326338..7fa4b11acc 100644 --- a/aio/tools/transforms/angular-api-package/processors/processPackages.spec.js +++ b/aio/tools/transforms/angular-api-package/processors/processPackages.spec.js @@ -163,6 +163,47 @@ describe('processPackages processor', () => { ]); }); + it('should compute whether the entry point has public exports', () => { + const docs = [ + { + fileInfo: { filePath: 'some/package-1/index' }, + docType: 'module', + id: 'package-1', + exports: [ + { docType: 'class', id: 'class-1' }, + ] + }, + { + fileInfo: { filePath: 'some/package-1/sub-1index' }, + docType: 'module', + id: 'package-1/sub-1', + exports: [], + }, + { + fileInfo: { filePath: 'some/package-2/index' }, + docType: 'module', + id: 'package-2', + exports: [], + }, + { + fileInfo: { filePath: 'some/package-1/sub-1index' }, + docType: 'module', + id: 'package-1/sub-1', + exports: [ + { docType: 'const', id: 'const-2' }, + { docType: 'enum', id: 'enum-3' }, + ], + }, + ]; + const processor = processorFactory({ packageContentFiles: {} }); + processor.$process(docs); + + expect(docs[0].hasPublicExports).toBeTrue(); + expect(docs[1].hasPublicExports).toBeFalse(); + expect(docs[2].hasPublicExports).toBeFalse(); + expect(docs[3].hasPublicExports).toBeTrue(); + }); + it('should compute the deprecated status of each entry point', () => { const docs = [ { @@ -199,6 +240,12 @@ describe('processPackages processor', () => { { docType: 'class', id: 'class-6' }, ] }, + { + fileInfo: { filePath: 'some/package-4/index' }, + docType: 'module', + id: 'package-4', + exports: [] + }, ]; const processor = processorFactory({ packageContentFiles: {} }); processor.$process(docs); @@ -207,6 +254,7 @@ describe('processPackages processor', () => { expect(docs[1].deprecated).toBeTruthy(); expect(docs[2].deprecated).toBeUndefined(); expect(docs[3].deprecated).toBeUndefined(); + expect(docs[4].deprecated).toBeUndefined(); }); it('should compute the deprecated status of packages', () => { diff --git a/aio/tools/transforms/templates/api/package.template.html b/aio/tools/transforms/templates/api/package.template.html index 22e902b147..4d0952ac8d 100644 --- a/aio/tools/transforms/templates/api/package.template.html +++ b/aio/tools/transforms/templates/api/package.template.html @@ -43,6 +43,9 @@ {% endif %}

{% if doc.isPrimaryPackage %}Primary entry{% else %}Entry{% endif %} point exports

+ {% if not doc.hasPublicExports %} +

No public exports.

+ {% endif %} {% include "includes/deprecation.html" %} {$ listItems(doc.ngmodules, 'NgModules') $} {$ listItems(doc.classes, 'Classes') $}