Skip to content

Commit

Permalink
CLI: Ignore those folders mentioned in the gitignore
Browse files Browse the repository at this point in the history
* Ignore node_modules and .git folders always.
* Also ignore additional patterns from the .gitignore file, if it exists.

Closes #1384.
  • Loading branch information
SparshithNR authored and Krinkle committed Jun 14, 2019
1 parent 4444f5e commit 837af39
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const requireQUnit = require( "./require-qunit" );
const utils = require( "./utils" );

const IGNORED_GLOBS = [
"**/node_modules/**"
];
".git",
"node_modules"
].concat( utils.getIgnoreList( process.cwd() ) );

const RESTART_DEBOUNCE_LENGTH = 200;

let QUnit;
Expand Down
13 changes: 12 additions & 1 deletion src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ function existsStat() {
}
}


function getIgnoreList( baseDir ) {
const gitFilePath = path.join( baseDir, ".gitignore" );
if ( fs.existsSync( gitFilePath ) ) {
const gitIgnore = fs.readFileSync( gitFilePath, "utf-8" );
return gitIgnore.trim().split( "\n" );
}
return [];
}

function findFilesInternal( dir, options, result = [], prefix = "" ) {
fs.readdirSync( dir ).forEach( ( name ) => {
const fullName = path.join( dir, name );
Expand Down Expand Up @@ -85,5 +95,6 @@ module.exports = {
findFiles,
capitalize,
error,
getFilesFromArgs
getFilesFromArgs,
getIgnoreList
};
2 changes: 2 additions & 0 deletions test/cli/fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/abcd
/efgh
8 changes: 8 additions & 0 deletions test/cli/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { getIgnoreList } = require( "../../src/cli/utils" );

QUnit.module( "getIgnoreList", function() {
QUnit.test( "reads .gitignore", function( assert ) {
const ignoreList = getIgnoreList( "test/cli/fixtures" );
assert.deepEqual( ignoreList, [ "/abcd", "/efgh" ] );
} );
} );

0 comments on commit 837af39

Please sign in to comment.