fix(aio): ignore private exports

Closes #14992
This commit is contained in:
Peter Bacon Darwin 2017-03-12 13:27:47 +00:00 committed by Chuck Jazdzewski
parent 62d5543b01
commit 3f7cfde476
7 changed files with 93 additions and 4 deletions

View File

@ -46,6 +46,7 @@ module.exports =
.processor(require('./processors/matchUpDirectiveDecorators'))
.processor(require('./processors/filterMemberDocs'))
.processor(require('./processors/convertToJson'))
.processor(require('./processors/markBarredODocsAsPrivate'))
// overrides base packageInfo and returns the one for the 'angular/angular' repo.
.factory('packageInfo', function() { return require(path.resolve(PROJECT_ROOT, 'package.json')); })

View File

@ -24,7 +24,9 @@ function getModuleInfo(moduleDoc) {
return {
name: moduleName.toLowerCase(),
title: moduleName,
items: moduleDoc.exports.filter(doc => !doc.internal).map(getExportInfo)
items: moduleDoc.exports
// Ignore internals and private exports (indicated by the ɵ prefix)
.filter(doc => !doc.internal && !doc.privateExport).map(getExportInfo)
};
}

View File

@ -83,11 +83,12 @@ describe('generateApiListDoc processor', () => {
]);
});
it('should ignore internal exports', () => {
it('should ignore internal and private exports', () => {
const processor = processorFactory();
const docs = [
{ docType: 'module', id: '@angular/common/index', exports: [
{ docType: 'directive', name: 'AaaAaa', path: 'aaa', internal: true },
{ docType: 'class', name: 'XxxXxx', path: 'xxx', privateExport: true },
{ docType: 'pipe', name: 'BbbBbb', path: 'bbb' }
]}
];

View File

@ -76,8 +76,11 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) {
}
// We are only interested in docs that live in the right area
const filteredDocs = docs.filter(function(doc) { return !docTypesToIgnore[doc.docType]; });
const filteredDocs = docs
// We are not interested in some docTypes
.filter(function(doc) { return !docTypesToIgnore[doc.docType]; })
// Ignore internals and private exports (indicated by the ɵ prefix)
.filter(function(doc) { return !doc.internal && !doc.privateExport; });
filteredDocs.forEach(function(doc) {

View File

@ -0,0 +1,41 @@
const testPackage = require('../../helpers/test-package');
const mockLogger = require('dgeni/lib/mocks/log')(false);
const processorFactory = require('./generateKeywords');
const Dgeni = require('dgeni');
const mockReadFilesProcessor = {
basePath: 'base/path'
};
describe('generateKeywords processor', () => {
it('should be available on the injector', () => {
const dgeni = new Dgeni([testPackage('angular.io-package')]);
const injector = dgeni.configureInjector();
const processor = injector.get('generateKeywordsProcessor');
expect(processor.$process).toBeDefined();
});
it('should run after "paths-computed"', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
expect(processor.$runAfter).toEqual(['paths-computed']);
});
it('should run before "rendering-docs"', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
expect(processor.$runBefore).toEqual(['rendering-docs']);
});
it('should ignore internal and private exports', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
const docs = [
{ docType: 'class', name: 'PublicExport' },
{ docType: 'class', name: 'PrivateExport', privateExport: true },
{ docType: 'class', name: 'InternalExport', internal: true }
];
processor.$process(docs);
expect(docs[docs.length - 1].data).toEqual([
jasmine.objectContaining({ title: 'PublicExport', type: 'class'})
]);
});
});

View File

@ -0,0 +1,13 @@
module.exports = function markBarredODocsAsPrivate() {
return {
$runAfter: ['readTypeScriptModules'],
$runBefore: ['adding-extra-docs'],
$process: function(docs) {
docs.forEach(doc => {
if (doc.name && doc.name.indexOf('ɵ') === 0) {
doc.privateExport = true;
}
});
}
};
};

View File

@ -0,0 +1,28 @@
const testPackage = require('../../helpers/test-package');
const processorFactory = require('./markBarredODocsAsPrivate');
const Dgeni = require('dgeni');
describe('generateApiListDoc processor', () => {
it('should be available on the injector', () => {
const dgeni = new Dgeni([testPackage('angular.io-package')]);
const injector = dgeni.configureInjector();
const processor = injector.get('markBarredODocsAsPrivate');
expect(processor.$process).toBeDefined();
expect(processor.$runAfter).toContain('readTypeScriptModules');
expect(processor.$runBefore).toContain('adding-extra-docs');
});
it('should mark docs starting with barred-o ɵ as private', () => {
const processor = processorFactory();
const docs = [
{ name: 'ɵPrivate' },
{ name: 'public' }
]
processor.$process(docs);
expect(docs[0].privateExport).toBeTruthy();
expect(docs[1].privateExport).toBeFalsy();
});
});