@@ -29,39 +29,38 @@ const isPathInside = (parent, child) => {
2929 * @param {boolean } [options.relative] - Whether filepaths to should be relative to gitDir
3030 * @returns {Promise }
3131 */
32- module . exports = async function generateTasks ( {
32+ module . exports = function generateTasks ( {
3333 config,
3434 cwd = process . cwd ( ) ,
3535 gitDir,
3636 files,
3737 relative = false
3838} ) {
3939 debug ( 'Generating linter tasks' )
40-
41- const stagedFiles = files . map ( file => path . resolve ( gitDir , file ) )
42-
43- return Object . keys ( config ) . map ( pattern => {
40+ return Object . entries ( config ) . map ( ( [ pattern , commands ] ) => {
4441 const isParentDirPattern = pattern . startsWith ( '../' )
45- const commands = config [ pattern ]
46-
4742 const fileList = micromatch (
48- stagedFiles
43+ files
4944 // Only worry about children of the CWD unless the pattern explicitly
5045 // specifies that it concerns a parent directory.
51- . filter ( file => isParentDirPattern || isPathInside ( cwd , file ) )
52- // Make the paths relative to CWD for filtering
53- . map ( file => path . relative ( cwd , file ) ) ,
46+ . filter ( file => {
47+ if ( isParentDirPattern ) return true
48+ const absolutePath = path . resolve ( gitDir , file )
49+ return isPathInside ( cwd , absolutePath )
50+ } ) ,
5451 pattern ,
5552 {
53+ cwd,
54+ dot : true ,
5655 // If pattern doesn't look like a path, enable `matchBase` to
5756 // match against filenames in every directory. This makes `*.js`
5857 // match both `test.js` and `subdirectory/test.js`.
5958 matchBase : ! pattern . includes ( '/' ) ,
60- dot : true
59+ posixSlashes : true
6160 }
6261 ) . map ( file =>
6362 // Return absolute path after the filter is run
64- relative ? path . normalize ( file ) : path . resolve ( cwd , file )
63+ relative ? file : cwd + '/' + file
6564 )
6665
6766 const task = { pattern, commands, fileList }
0 commit comments