Skip to content

Avoid documenting excluded files. (#896) #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function multiply(a: number, b: number) {
return a * b;
}
15 changes: 14 additions & 1 deletion src/test/typedoc.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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