Skip to content
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

Reduce the travese if glob is filepath. #1385

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 14 additions & 5 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,35 @@ function findFiles( baseDir, options ) {
}

function getFilesFromArgs( args ) {
let globs = args.slice();
const globs = args.slice();

// Default to files in the test directory
if ( !globs.length ) {
globs.push( "test/**/*.js" );
}

const files = [];
const filteredGlobs = [];

// For each of the potential globs, we check if it is a directory path and
// update it so that it matches the JS files in that directory.
globs = globs.map( glob => {
// Filter out if glob is file path.
globs.forEach( glob => {
const stat = existsStat( glob );

if ( stat && stat.isDirectory() ) {
return `${glob}/**/*.js`;
filteredGlobs.push( `${glob}/**/*.js` );
} else if ( stat && stat.isFile() ) {
files.push( glob );
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is return false meant to do? I suspect it may be intended for jQuery.each which uses it to break the for-loop, however Array#forEach does not do that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. return false doesn't actually mean anything for forEach.

} else {
return glob;
filteredGlobs.push( glob );
}
} );

const files = findFiles( process.cwd(), { match: globs } );
if ( filteredGlobs.length ) {
files.push.apply( files, findFiles( process.cwd(), { match: filteredGlobs } ) );
}

if ( !files.length ) {
error( "No files were found matching: " + args.join( ", " ) );
Expand Down