From 837af390f66cb03154c50f6d29641d812e311b01 Mon Sep 17 00:00:00 2001 From: SparshithNRai Date: Thu, 13 Jun 2019 17:10:21 -0700 Subject: [PATCH] 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. --- src/cli/run.js | 6 ++++-- src/cli/utils.js | 13 ++++++++++++- test/cli/fixtures/.gitignore | 2 ++ test/cli/utils.js | 8 ++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/cli/fixtures/.gitignore create mode 100644 test/cli/utils.js diff --git a/src/cli/run.js b/src/cli/run.js index fcda91da9..4347a0bf2 100644 --- a/src/cli/run.js +++ b/src/cli/run.js @@ -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; diff --git a/src/cli/utils.js b/src/cli/utils.js index 2f47fb883..d6522bf24 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -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 ); @@ -85,5 +95,6 @@ module.exports = { findFiles, capitalize, error, - getFilesFromArgs + getFilesFromArgs, + getIgnoreList }; diff --git a/test/cli/fixtures/.gitignore b/test/cli/fixtures/.gitignore new file mode 100644 index 000000000..787f73d47 --- /dev/null +++ b/test/cli/fixtures/.gitignore @@ -0,0 +1,2 @@ +/abcd +/efgh diff --git a/test/cli/utils.js b/test/cli/utils.js new file mode 100644 index 000000000..6bc8e9691 --- /dev/null +++ b/test/cli/utils.js @@ -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" ] ); + } ); +} );