@@ -2,6 +2,7 @@ import fs from 'fs';
22import paths from 'path' ;
33import ignore , { Ignore } from 'ignore' ;
44import parseGitignore from './parse-gitignore' ;
5+ import { normPath , normAbsPath } from './norm-path' ;
56
67let allFiles : Set < string > ;
78let allFolders : Set < string > ;
@@ -17,8 +18,6 @@ interface WalkInput {
1718 folders : string [ ] ,
1819 /** An instantiated Ignore object listing ignored files */
1920 ignored : Ignore ,
20- /** A list of regexes to ignore */
21- regexIgnores : RegExp [ ] ,
2221} ;
2322
2423interface WalkOutput {
@@ -28,7 +27,7 @@ interface WalkOutput {
2827
2928/** Generate list of files in a directory. */
3029export default function walk ( data : WalkInput ) : WalkOutput {
31- const { init, commonRoot, folderRoots, folders, ignored, regexIgnores } = data ;
30+ const { init, commonRoot, folderRoots, folders, ignored } = data ;
3231
3332 // Initialise files and folders lists
3433 if ( init ) {
@@ -44,47 +43,46 @@ export default function walk(data: WalkInput): WalkOutput {
4443 // Get list of files and folders inside this folder
4544 const files = fs . readdirSync ( folder ) . map ( file => {
4645 // Create path relative to root
47- const base = paths . resolve ( folder , file ) . replace ( / \\ / g , '/' ) . replace ( commonRoot , '.' ) ;
46+ const base = normAbsPath ( folder , file ) . replace ( commonRoot , '.' ) ;
4847 // Add trailing slash to mark directories
4948 const isDir = fs . lstatSync ( paths . resolve ( commonRoot , base ) ) . isDirectory ( ) ;
5049 return isDir ? `${ base } /` : base ;
5150 } ) ;
5251
5352 // Read and apply gitignores
54- const gitignoreFilename = paths . join ( folder , '.gitignore' ) ;
53+ const gitignoreFilename = normPath ( folder , '.gitignore' ) ;
5554 if ( fs . existsSync ( gitignoreFilename ) ) {
5655 const gitignoreContents = fs . readFileSync ( gitignoreFilename , 'utf-8' ) ;
5756 const ignoredPaths = parseGitignore ( gitignoreContents ) ;
5857 ignored . add ( ignoredPaths ) ;
5958 }
6059
6160 // Add gitattributes if present
62- const gitattributesPath = paths . join ( folder , '.gitattributes' ) ;
61+ const gitattributesPath = normPath ( folder , '.gitattributes' ) ;
6362 if ( fs . existsSync ( gitattributesPath ) ) {
6463 allFiles . add ( gitattributesPath ) ;
6564 }
6665
6766 // Loop through files and folders
6867 for ( const file of files ) {
6968 // Create absolute path for disc operations
70- const path = paths . resolve ( commonRoot , file ) . replace ( / \\ / g , '/' ) ;
69+ const path = normAbsPath ( commonRoot , file ) ;
7170 const localPath = localRoot ? file . replace ( `./${ localRoot } /` , '' ) : file . replace ( './' , '' ) ;
7271
7372 // Skip if nonexistant
7473 const nonExistant = ! fs . existsSync ( path ) ;
7574 if ( nonExistant ) continue ;
76- // Skip if marked as ignored
75+ // Skip if marked in gitignore
7776 const isIgnored = ignored . test ( localPath ) . ignored ;
78- const isRegexIgnored = regexIgnores . some ( pattern => pattern . test ( localPath ) ) ;
79- if ( isIgnored || isRegexIgnored ) continue ;
77+ if ( isIgnored ) continue ;
8078
8179 // Add absolute folder path to list
82- allFolders . add ( paths . resolve ( folder ) . replace ( / \\ / g , '/' ) ) ;
80+ allFolders . add ( normAbsPath ( folder ) ) ;
8381 // Check if this is a folder or file
8482 if ( file . endsWith ( '/' ) ) {
8583 // Recurse into subfolders
8684 allFolders . add ( path ) ;
87- walk ( { init : false , commonRoot, folderRoots, folders : [ path ] , ignored, regexIgnores } ) ;
85+ walk ( { init : false , commonRoot, folderRoots, folders : [ path ] , ignored } ) ;
8886 }
8987 else {
9088 // Add file path to list
@@ -95,7 +93,7 @@ export default function walk(data: WalkInput): WalkOutput {
9593 // Recurse into all folders
9694 else {
9795 for ( const i in folders ) {
98- walk ( { init : false , commonRoot, folderRoots : [ folderRoots [ i ] ] , folders : [ folders [ i ] ] , ignored, regexIgnores } ) ;
96+ walk ( { init : false , commonRoot, folderRoots : [ folderRoots [ i ] ] , folders : [ folders [ i ] ] , ignored } ) ;
9997 }
10098 }
10199 // Return absolute files and folders lists
0 commit comments