Skip to content

Commit 837af39

Browse files
SparshithNRaiKrinkle
authored andcommitted
CLI: Ignore those folders mentioned in the gitignore
* Ignore node_modules and .git folders always. * Also ignore additional patterns from the .gitignore file, if it exists. Closes #1384.
1 parent 4444f5e commit 837af39

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/cli/run.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ const requireQUnit = require( "./require-qunit" );
77
const utils = require( "./utils" );
88

99
const IGNORED_GLOBS = [
10-
"**/node_modules/**"
11-
];
10+
".git",
11+
"node_modules"
12+
].concat( utils.getIgnoreList( process.cwd() ) );
13+
1214
const RESTART_DEBOUNCE_LENGTH = 200;
1315

1416
let QUnit;

src/cli/utils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ function existsStat() {
1212
}
1313
}
1414

15+
16+
function getIgnoreList( baseDir ) {
17+
const gitFilePath = path.join( baseDir, ".gitignore" );
18+
if ( fs.existsSync( gitFilePath ) ) {
19+
const gitIgnore = fs.readFileSync( gitFilePath, "utf-8" );
20+
return gitIgnore.trim().split( "\n" );
21+
}
22+
return [];
23+
}
24+
1525
function findFilesInternal( dir, options, result = [], prefix = "" ) {
1626
fs.readdirSync( dir ).forEach( ( name ) => {
1727
const fullName = path.join( dir, name );
@@ -85,5 +95,6 @@ module.exports = {
8595
findFiles,
8696
capitalize,
8797
error,
88-
getFilesFromArgs
98+
getFilesFromArgs,
99+
getIgnoreList
89100
};

test/cli/fixtures/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/abcd
2+
/efgh

test/cli/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { getIgnoreList } = require( "../../src/cli/utils" );
2+
3+
QUnit.module( "getIgnoreList", function() {
4+
QUnit.test( "reads .gitignore", function( assert ) {
5+
const ignoreList = getIgnoreList( "test/cli/fixtures" );
6+
assert.deepEqual( ignoreList, [ "/abcd", "/efgh" ] );
7+
} );
8+
} );

0 commit comments

Comments
 (0)