Skip to content
Permalink
Browse files

fix: Ignore node_modules

  • Loading branch information...
iamthes committed Nov 13, 2017
1 parent 727e73e commit dff6187fc6757299aecca5847a7b719cf67909f2
Showing with 12 additions and 1 deletion.
  1. +8 −0 src/directory.spec.ts
  2. +4 −1 src/directory.ts
@@ -30,3 +30,11 @@ it('relative target', async () => {
const result = await directory('src');
assert.notEqual(result.length, 0);
});

it('should ignore node_modules', async () => {
const result = await directory(`${rootPath}`);
const ts = result.filter(item => item.module === 'typescript');
assert.equal(ts.length, 0);
const nodeModules = result.filter(item => item.filepath && item.filepath.indexOf('node_modules') !== -1);
assert.equal(nodeModules.length, 0);
});
@@ -4,6 +4,7 @@ import { file as parse } from './file';
import { extname, resolve as resolvePath, parse as parsePath } from 'path';

export const findFileExtensions = ['.ts', '.d.ts', '.js', '.tsx', '.jsx'];
const ignoreDirectoryList = ['node_modules'];

type DirectoryOptions = {
basedir?: string;
@@ -37,7 +38,9 @@ export function directory(path: string, options: DirectoryOptions = {}): Promise
return reject(err);
}
if (stats.isDirectory()) {
directories.push(item);
if (!ignoreDirectoryList.includes(item)) {
directories.push(item);
}
} else if (stats.isFile()) {
const { name, ext } = parsePath(item);
const extIndex = findFileExtensions.indexOf(ext);

0 comments on commit dff6187

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