Skip to content
Permalink
Browse files

feat: Do not parse similar files .ts .d.ts

  • Loading branch information...
iamthes committed Nov 13, 2017
1 parent 82180da commit bb324ecacb8977fad01eaeccdd233d54b19ee44c
Showing with 9 additions and 8 deletions.
  1. +1 −1 package.json
  2. +7 −6 src/directory.ts
  3. +1 −1 src/fixtures.spec.ts
@@ -56,7 +56,7 @@
"lib": "lib"
},
"engines": {
"node" : ">=6",
"node": ">=6",
"npm": ">=3"
},
"config": {
@@ -30,7 +30,7 @@ export function directory(path: string, options: DirectoryOptions = {}): Promise
return Promise.resolve([]);
}
return new Promise<{ directories: string[], files: string[] }>((done, reject) => {
const names = Object.create(null);
const names: { [name: string]: [number, string] } = Object.create(null);
items.forEach(item => {
stat(resolvePath(dirpath, item), (err, stats) => {
if (err) {
@@ -40,16 +40,17 @@ export function directory(path: string, options: DirectoryOptions = {}): Promise
directories.push(item);
} else if (stats.isFile()) {
const { name, ext } = parsePath(item);
if (names[name] === undefined) {
if (findFileExtensions.includes(ext)) {
files.push(item);
names[name] = true;
const extIndex = findFileExtensions.indexOf(ext);
if (extIndex !== - 1) {
let [nameIndex] = names[name] || [Infinity];
if (extIndex < nameIndex) {
names[name] = [extIndex, item];
}
}
}
count--;
if (count === 0) {
done({ directories, files });
done({ directories, files: Object.values(names).map(([, file]) => file) });
}
});
});
@@ -2,7 +2,7 @@ import * as assert from 'assert';
import { directory } from '.';
import { normalize } from 'path';

it.only('should take only file by findFileExtensions', async () => {
it('should take only file by findFileExtensions', async () => {
const result = await directory(__dirname + '/../fixtures');
assert(result);
assert.equal(result.length, 1);

0 comments on commit bb324ec

Please sign in to comment.
You can’t perform that action at this time.