diff --git a/src/lib/application.ts b/src/lib/application.ts index f72a13f5f..4f3901964 100644 --- a/src/lib/application.ts +++ b/src/lib/application.ts @@ -17,7 +17,13 @@ import { ProjectReflection } from './models/index'; import { Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile } from './utils/index'; import { createMinimatch } from './utils/paths'; -import { AbstractComponent, ChildableComponent, Component, Option, DUMMY_APPLICATION_OWNER } from './utils/component'; +import { + AbstractComponent, + ChildableComponent, + Component, + Option, + DUMMY_APPLICATION_OWNER +} from './utils/component'; import { Options, OptionsReadMode, OptionsReadResult } from './utils/options/index'; import { ParameterType } from './utils/options/declaration'; @@ -35,7 +41,7 @@ import { ParameterType } from './utils/options/declaration'; * and emit a series of events while processing the project. Subscribe to these Events * to control the application flow or alter the output. */ -@Component({name: 'application', internal: true}) +@Component({ name: 'application', internal: true }) export class Application extends ChildableComponent> { options: Options; @@ -63,11 +69,11 @@ export class Application extends ChildableComponent('converter', Converter); this.serializer = this.addComponent('serializer', Serializer); - this.renderer = this.addComponent('renderer', Renderer); - this.plugins = this.addComponent('plugins', PluginHost); - this.options = this.addComponent('options', Options); + this.renderer = this.addComponent('renderer', Renderer); + this.plugins = this.addComponent('plugins', PluginHost); + this.options = this.addComponent('options', Options); this.bootstrap(options); } @@ -156,7 +162,11 @@ export class Application extends ChildableComponent mm.match(fileName)); } const supportedFileRegex = this.options.getCompilerOptions().allowJs ? /\.[tj]sx?$/ : /\.tsx?$/; - function add(dirname: string) { - FS.readdirSync(dirname).forEach((file) => { - const realpath = Path.join(dirname, file); - if (FS.statSync(realpath).isDirectory()) { - add(realpath); - } else if (supportedFileRegex.test(realpath)) { - if (isExcluded(realpath.replace(/\\/g, '/'))) { - return; - } - - files.push(realpath); - } - }); - } + function add(file: string) { + if (isExcluded(file.replace(/\\/g, '/'))) { + return; + } - inputFiles.forEach((file) => { - file = Path.resolve(file); if (FS.statSync(file).isDirectory()) { - add(file); - } else if (!isExcluded(file)) { + FS.readdirSync(file).forEach(next => { + add(Path.join(file, next)); + }); + } else if (supportedFileRegex.test(file)) { files.push(file); } + } + + inputFiles.forEach(file => { + add(Path.resolve(file)); }); return files; diff --git a/src/test/typedoc.test.ts b/src/test/typedoc.test.ts index efb7b48dc..dd79afcfc 100644 --- a/src/test/typedoc.test.ts +++ b/src/test/typedoc.test.ts @@ -66,16 +66,26 @@ describe('TypeDoc', function() { Assert(!expanded.includes(inputFiles)); }); it('Honors the exclude option even if a module is imported', () => { - application.options.setValue('exclude', '**/b.d.ts'); + application.options.setValue('exclude', '**/b.ts', Assert.fail); + application.options.setValue('module', 'commonjs', Assert.fail); function handler(context: Context) { Assert.deepStrictEqual(context.fileNames, [ - Path.resolve(__dirname, 'module', 'a.d.ts').replace(/\\/g, '/') + Path.resolve(__dirname, 'module', 'a.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); + application.converter.once(Converter.EVENT_END, handler); + application.convert([ Path.join(__dirname, 'module', 'a.ts')]); + }); + + it('supports directory excludes', function() { + const inputFiles = Path.join(__dirname, 'converter'); + application.options.setValue('exclude', [ '**/access' ]); + const expanded = application.expandInputFiles([inputFiles]); + + Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'class', 'class.ts')), true); + Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'access', 'access.ts')), false); + Assert.strictEqual(expanded.includes(inputFiles), false); }); }); });