Skip to content

Commit

Permalink
fix(docs-infra): correctly handle entry-points with no public exports (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
gkalpak authored and alxhub committed Feb 9, 2021
1 parent 67333a9 commit 9aa3e9f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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);
Expand All @@ -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', () => {
Expand Down
3 changes: 3 additions & 0 deletions aio/tools/transforms/templates/api/package.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ <h2>Entry points</h2>
{% endif %}

<h2>{% if doc.isPrimaryPackage %}Primary entry{% else %}Entry{% endif %} point exports</h2>
{% if not doc.hasPublicExports %}
<p><i>No public exports.</i></p>
{% endif %}
{% include "includes/deprecation.html" %}
{$ listItems(doc.ngmodules, 'NgModules') $}
{$ listItems(doc.classes, 'Classes') $}
Expand Down

0 comments on commit 9aa3e9f

Please sign in to comment.