Skip to content

Commit 7340197

Browse files
committed
fix(files): fix getFilesPathsUnder methods that now return correct contents
1 parent 8baf251 commit 7340197

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

sources/file-system/files.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import fs from 'fs'
1212
import {
1313
isArray,
14+
isDirectoryPath,
15+
isFilePath,
1416
isInvalidPath
1517
} from 'itee-validators'
1618
import path from 'path'
@@ -22,9 +24,8 @@ function getPathsUnder ( directoryPath ) {
2224
/**
2325
* Allow to search all files under filePaths in a recursive way
2426
*
25-
* @param {Array.<string>|string} filePaths - The files paths where search files
27+
* @param {Array.<string>|string} paths - The files paths where search files
2628
* @returns {Array} - The paths of finded files
27-
* @private
2829
*/
2930
function getFilesPathsUnder ( paths ) {
3031

@@ -36,20 +37,20 @@ function getFilesPathsUnder ( paths ) {
3637
const localPath = _paths[ pathIndex ]
3738

3839
if ( isInvalidPath( localPath ) ) {
40+
3941
console.error( `The path "${localPath}" is not valid !` )
40-
continue
41-
}
4242

43-
const stats = fs.statSync( localPath )
44-
if ( stats.isFile() ) {
43+
} else if ( isFilePath( localPath ) ) {
4544

4645
files.push( localPath )
4746

48-
} else if ( stats.isDirectory() ) {
47+
} else if ( isDirectoryPath( localPath ) ) {
4948

5049
const subPaths = getPathsUnder( localPath )
51-
const subFilesPaths = subPaths.forEach( ( name ) => { getFilesPathsUnder( path.resolve( localPath, name ) ) } )
52-
Array.prototype.push.apply( files, subFilesPaths )
50+
const subFilesPaths = subPaths.map( ( subPath ) => { return getFilesPathsUnder( path.resolve( localPath, subPath ) ) } )
51+
if ( subFilesPaths ) {
52+
files = [].concat( ...subFilesPaths )
53+
}
5354

5455
} else {
5556

0 commit comments

Comments
 (0)