Skip to content

Commit 92f0f25

Browse files
stoicallyGerrit0
authored andcommitted
Support negations in directory excludes
1 parent b328537 commit 92f0f25

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/lib/application.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,27 @@ export class Application extends ChildableComponent<Application, AbstractCompone
266266
}
267267

268268
const supportedFileRegex = this.options.getCompilerOptions().allowJs ? /\.[tj]sx?$/ : /\.tsx?$/;
269-
function add(file: string) {
270-
if (isExcluded(file.replace(/\\/g, '/'))) {
269+
function add(file: string, entryPoint: boolean) {
270+
const fileIsDir = FS.statSync(file).isDirectory();
271+
if (fileIsDir && file.slice(-1) !== '/') {
272+
file = `${file}/`;
273+
}
274+
275+
if ((!fileIsDir || !entryPoint) && isExcluded(file.replace(/\\/g, '/'))) {
271276
return;
272277
}
273278

274-
if (FS.statSync(file).isDirectory()) {
279+
if (fileIsDir) {
275280
FS.readdirSync(file).forEach(next => {
276-
add(Path.join(file, next));
281+
add(Path.join(file, next), false);
277282
});
278283
} else if (supportedFileRegex.test(file)) {
279284
files.push(file);
280285
}
281286
}
282287

283288
inputFiles.forEach(file => {
284-
add(Path.resolve(file));
289+
add(Path.resolve(file), true);
285290
});
286291

287292
return files;

src/test/typedoc.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,15 @@ describe('TypeDoc', function() {
8787
Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'access', 'access.ts')), false);
8888
Assert.strictEqual(expanded.includes(inputFiles), false);
8989
});
90+
91+
it('supports negations in directory excludes', function() {
92+
const inputFiles = Path.join(__dirname, 'converter');
93+
application.options.setValue('exclude', [ '**/!(access)/' ]);
94+
const expanded = application.expandInputFiles([inputFiles]);
95+
96+
Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'class', 'class.ts')), false);
97+
Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'access', 'access.ts')), true);
98+
Assert.strictEqual(expanded.includes(inputFiles), false);
99+
});
90100
});
91101
});

0 commit comments

Comments
 (0)