Skip to content

Commit

Permalink
Avoid documenting excluded files. (#896)
Browse files Browse the repository at this point in the history
Fixes #319
Fixes #839
  • Loading branch information
Gerrit0 authored and aciccarello committed Dec 19, 2018
1 parent e650aa7 commit 1c4c515
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/lib/converter/converter.ts
Expand Up @@ -10,6 +10,7 @@ import { ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, Typ
import { CompilerHost } from './utils/compiler-host';
import { Component, Option, ChildableComponent, ComponentClass } from '../utils/component';
import { normalizePath } from '../utils/fs';
import { createMinimatch } from '../utils/paths';

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

program.getSourceFiles().forEach((sourceFile) => {
const exclude = createMinimatch(this.application.exclude || []);
const isExcluded = (file: ts.SourceFile) => exclude.some(mm => mm.match(file.fileName));

const includedSourceFiles = program.getSourceFiles()
.filter(file => !isExcluded(file));
const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file);

includedSourceFiles.forEach((sourceFile) => {
this.convertNode(context, sourceFile);
});

let diagnostics = program.getOptionsDiagnostics();
let diagnostics = program.getOptionsDiagnostics().filter(isRelevantError);
if (diagnostics.length) {
return diagnostics;
}

diagnostics = program.getSyntacticDiagnostics();
diagnostics = program.getSyntacticDiagnostics().filter(isRelevantError);
if (diagnostics.length) {
return diagnostics;
}

diagnostics = program.getGlobalDiagnostics();
diagnostics = program.getGlobalDiagnostics().filter(isRelevantError);
if (diagnostics.length) {
return diagnostics;
}

diagnostics = program.getSemanticDiagnostics();
diagnostics = program.getSemanticDiagnostics().filter(isRelevantError);
if (diagnostics.length) {
return diagnostics;
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/module/a.ts
@@ -0,0 +1,5 @@
import { multiply } from './b';

export function add(a: number, b: number) {
return a + multiply(b, 1);
}
3 changes: 3 additions & 0 deletions src/test/module/b.ts
@@ -0,0 +1,3 @@
export function multiply(a: number, b: number) {
return a * b;
}
15 changes: 14 additions & 1 deletion src/test/typedoc.ts
Expand Up @@ -2,12 +2,13 @@ import { Application } from '..';
import * as Path from 'path';
import Assert = require('assert');
import './.dot';
import { Converter, Context } from '../lib/converter';

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

describe('Application', function() {
it('constructs', function() {
before('constructs', function() {
application = new Application();
});
it('expands input directory', function() {
Expand Down Expand Up @@ -64,5 +65,17 @@ describe('TypeDoc', function() {
Assert.equal(expanded.indexOf(Path.join(inputFiles, '.dot', 'index.d.ts')), -1);
Assert.equal(expanded.indexOf(inputFiles), -1);
});
it('Honors the exclude option even if a module is imported', () => {
application.options.setValue('exclude', '**/b.d.ts');

function handler(context: Context) {
Assert.deepStrictEqual(context.fileNames, [
Path.resolve(__dirname, 'module', 'a.d.ts').replace(/\\/g, '/')
]);
}
application.converter.on(Converter.EVENT_END, handler);
application.convert([ Path.join(__dirname, 'module', 'a.d.ts')]);
application.converter.off(Converter.EVENT_END, handler);
});
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -6,7 +6,8 @@
"es5",
"es2015.core",
"es2015.collection",
"es2015.iterable"
"es2015.iterable",
"es2016.array.include" // Supported by Node 6+
],
"target": "es2015",
"noImplicitAny": false,
Expand Down

0 comments on commit 1c4c515

Please sign in to comment.