Skip to content

Commit 1c4c515

Browse files
Gerrit0aciccarello
authored andcommitted
Avoid documenting excluded files. (#896)
Fixes #319 Fixes #839
1 parent e650aa7 commit 1c4c515

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

src/lib/converter/converter.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, Typ
1010
import { CompilerHost } from './utils/compiler-host';
1111
import { Component, Option, ChildableComponent, ComponentClass } from '../utils/component';
1212
import { normalizePath } from '../utils/fs';
13+
import { createMinimatch } from '../utils/paths';
1314

1415
/**
1516
* Result structure of the [[Converter.convert]] method.
@@ -384,26 +385,33 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
384385
private compile(context: Context): ReadonlyArray<ts.Diagnostic> {
385386
const program = context.program;
386387

387-
program.getSourceFiles().forEach((sourceFile) => {
388+
const exclude = createMinimatch(this.application.exclude || []);
389+
const isExcluded = (file: ts.SourceFile) => exclude.some(mm => mm.match(file.fileName));
390+
391+
const includedSourceFiles = program.getSourceFiles()
392+
.filter(file => !isExcluded(file));
393+
const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file);
394+
395+
includedSourceFiles.forEach((sourceFile) => {
388396
this.convertNode(context, sourceFile);
389397
});
390398

391-
let diagnostics = program.getOptionsDiagnostics();
399+
let diagnostics = program.getOptionsDiagnostics().filter(isRelevantError);
392400
if (diagnostics.length) {
393401
return diagnostics;
394402
}
395403

396-
diagnostics = program.getSyntacticDiagnostics();
404+
diagnostics = program.getSyntacticDiagnostics().filter(isRelevantError);
397405
if (diagnostics.length) {
398406
return diagnostics;
399407
}
400408

401-
diagnostics = program.getGlobalDiagnostics();
409+
diagnostics = program.getGlobalDiagnostics().filter(isRelevantError);
402410
if (diagnostics.length) {
403411
return diagnostics;
404412
}
405413

406-
diagnostics = program.getSemanticDiagnostics();
414+
diagnostics = program.getSemanticDiagnostics().filter(isRelevantError);
407415
if (diagnostics.length) {
408416
return diagnostics;
409417
}

src/test/module/a.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { multiply } from './b';
2+
3+
export function add(a: number, b: number) {
4+
return a + multiply(b, 1);
5+
}

src/test/module/b.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function multiply(a: number, b: number) {
2+
return a * b;
3+
}

src/test/typedoc.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { Application } from '..';
22
import * as Path from 'path';
33
import Assert = require('assert');
44
import './.dot';
5+
import { Converter, Context } from '../lib/converter';
56

67
describe('TypeDoc', function() {
78
let application: Application;
89

910
describe('Application', function() {
10-
it('constructs', function() {
11+
before('constructs', function() {
1112
application = new Application();
1213
});
1314
it('expands input directory', function() {
@@ -64,5 +65,17 @@ describe('TypeDoc', function() {
6465
Assert.equal(expanded.indexOf(Path.join(inputFiles, '.dot', 'index.d.ts')), -1);
6566
Assert.equal(expanded.indexOf(inputFiles), -1);
6667
});
68+
it('Honors the exclude option even if a module is imported', () => {
69+
application.options.setValue('exclude', '**/b.d.ts');
70+
71+
function handler(context: Context) {
72+
Assert.deepStrictEqual(context.fileNames, [
73+
Path.resolve(__dirname, 'module', 'a.d.ts').replace(/\\/g, '/')
74+
]);
75+
}
76+
application.converter.on(Converter.EVENT_END, handler);
77+
application.convert([ Path.join(__dirname, 'module', 'a.d.ts')]);
78+
application.converter.off(Converter.EVENT_END, handler);
79+
});
6780
});
6881
});

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"es5",
77
"es2015.core",
88
"es2015.collection",
9-
"es2015.iterable"
9+
"es2015.iterable",
10+
"es2016.array.include" // Supported by Node 6+
1011
],
1112
"target": "es2015",
1213
"noImplicitAny": false,

0 commit comments

Comments
 (0)