Skip to content

Commit 9aa3e9f

Browse files
gkalpakalxhub
authored andcommitted
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
1 parent 67333a9 commit 9aa3e9f

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

aio/tools/transforms/angular-api-package/processors/processPackages.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = function processPackages(collectPackageContentDocsProcessor) {
1818
// Partition the exports into groups by type
1919
if (doc.exports) {
2020
const publicExports = doc.exports.filter(doc => !doc.privateExport);
21+
doc.hasPublicExports = publicExports.length > 0;
2122
doc.ngmodules = publicExports.filter(doc => doc.docType === 'ngmodule').sort(byId);
2223
doc.classes = publicExports.filter(doc => doc.docType === 'class').sort(byId);
2324
doc.decorators = publicExports.filter(doc => doc.docType === 'decorator').sort(byId);
@@ -26,7 +27,7 @@ module.exports = function processPackages(collectPackageContentDocsProcessor) {
2627
doc.directives = publicExports.filter(doc => doc.docType === 'directive').sort(byId);
2728
doc.pipes = publicExports.filter(doc => doc.docType === 'pipe').sort(byId);
2829
doc.types = publicExports.filter(doc => doc.docType === 'type-alias' || doc.docType === 'const').sort(byId);
29-
if (publicExports.every(doc => !!doc.deprecated)) {
30+
if (doc.hasPublicExports && publicExports.every(doc => !!doc.deprecated)) {
3031
doc.deprecated = 'all exports of this entry point are deprecated.';
3132
}
3233
}

aio/tools/transforms/angular-api-package/processors/processPackages.spec.js

+48
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,47 @@ describe('processPackages processor', () => {
163163
]);
164164
});
165165

166+
it('should compute whether the entry point has public exports', () => {
167+
const docs = [
168+
{
169+
fileInfo: { filePath: 'some/package-1/index' },
170+
docType: 'module',
171+
id: 'package-1',
172+
exports: [
173+
{ docType: 'class', id: 'class-1' },
174+
]
175+
},
176+
{
177+
fileInfo: { filePath: 'some/package-1/sub-1index' },
178+
docType: 'module',
179+
id: 'package-1/sub-1',
180+
exports: [],
181+
},
182+
{
183+
fileInfo: { filePath: 'some/package-2/index' },
184+
docType: 'module',
185+
id: 'package-2',
186+
exports: [],
187+
},
188+
{
189+
fileInfo: { filePath: 'some/package-1/sub-1index' },
190+
docType: 'module',
191+
id: 'package-1/sub-1',
192+
exports: [
193+
{ docType: 'const', id: 'const-2' },
194+
{ docType: 'enum', id: 'enum-3' },
195+
],
196+
},
197+
];
198+
const processor = processorFactory({ packageContentFiles: {} });
199+
processor.$process(docs);
200+
201+
expect(docs[0].hasPublicExports).toBeTrue();
202+
expect(docs[1].hasPublicExports).toBeFalse();
203+
expect(docs[2].hasPublicExports).toBeFalse();
204+
expect(docs[3].hasPublicExports).toBeTrue();
205+
});
206+
166207
it('should compute the deprecated status of each entry point', () => {
167208
const docs = [
168209
{
@@ -199,6 +240,12 @@ describe('processPackages processor', () => {
199240
{ docType: 'class', id: 'class-6' },
200241
]
201242
},
243+
{
244+
fileInfo: { filePath: 'some/package-4/index' },
245+
docType: 'module',
246+
id: 'package-4',
247+
exports: []
248+
},
202249
];
203250
const processor = processorFactory({ packageContentFiles: {} });
204251
processor.$process(docs);
@@ -207,6 +254,7 @@ describe('processPackages processor', () => {
207254
expect(docs[1].deprecated).toBeTruthy();
208255
expect(docs[2].deprecated).toBeUndefined();
209256
expect(docs[3].deprecated).toBeUndefined();
257+
expect(docs[4].deprecated).toBeUndefined();
210258
});
211259

212260
it('should compute the deprecated status of packages', () => {

aio/tools/transforms/templates/api/package.template.html

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ <h2>Entry points</h2>
4343
{% endif %}
4444

4545
<h2>{% if doc.isPrimaryPackage %}Primary entry{% else %}Entry{% endif %} point exports</h2>
46+
{% if not doc.hasPublicExports %}
47+
<p><i>No public exports.</i></p>
48+
{% endif %}
4649
{% include "includes/deprecation.html" %}
4750
{$ listItems(doc.ngmodules, 'NgModules') $}
4851
{$ listItems(doc.classes, 'Classes') $}

0 commit comments

Comments
 (0)