@@ -711,19 +711,26 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
711711
712712 const processReaddirResult = ( args : any ) => ( args . context . withFileTypes ? handleDirents ( args ) : handleFilePaths ( args ) ) ;
713713
714- function handleDirents ( { result, currentPath, context } : { result : string [ ] , currentPath : string , context : any } ) {
715- const { 0 : names , 1 : types } = result ;
716- const { length } = names ;
717-
714+ function handleDirents ( { result, currentPath, context } : { result : any [ ] , currentPath : string , context : any } ) {
715+ const length = result [ 0 ] . length ;
718716 for ( let i = 0 ; i < length ; i ++ ) {
719- // Avoid excluding symlinks, as they are not directories.
720- // Refs: https://github.com/nodejs/node/issues/52663
721- const fullPath = path . join ( currentPath , names [ i ] ) ;
722- const dirent = getDirent ( currentPath , names [ i ] , types [ i ] ) ;
723- context . readdirResults . push ( dirent ) ;
717+ const resultPath = path . join ( currentPath , result [ 0 ] [ i ] ) ;
718+ const info = splitPath ( resultPath ) ;
719+
720+ let type = result [ 1 ] [ i ] ;
721+ if ( info . isAsar ) {
722+ const archive = getOrCreateArchive ( info . asarPath ) ;
723+ if ( ! archive ) return ;
724+ const stats = archive . stat ( info . filePath ) ;
725+ if ( ! stats ) continue ;
726+ type = stats . type ;
727+ }
724728
725- if ( dirent . isDirectory ( ) || binding . internalModuleStat ( binding , fullPath ) === 1 ) {
726- context . pathsQueue . push ( fullPath ) ;
729+ const dirent = getDirent ( currentPath , result [ 0 ] [ i ] , type ) ;
730+
731+ context . readdirResults . push ( dirent ) ;
732+ if ( dirent . isDirectory ( ) || binding . internalModuleStat ( binding , resultPath ) === 1 ) {
733+ context . pathsQueue . push ( path . join ( dirent . path , dirent . name ) ) ;
727734 }
728735 }
729736 }
@@ -1108,40 +1115,15 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
11081115 ) ;
11091116 }
11101117
1111- if ( readdirResult === undefined ) return ;
1112-
1113- if ( context . withFileTypes ) {
1114- const length = readdirResult [ 0 ] . length ;
1115- for ( let i = 0 ; i < length ; i ++ ) {
1116- const resultPath = path . join ( pathArg , readdirResult [ 0 ] [ i ] ) ;
1117- const info = splitPath ( resultPath ) ;
1118-
1119- let type = readdirResult [ 1 ] [ i ] ;
1120- if ( info . isAsar ) {
1121- const archive = getOrCreateArchive ( info . asarPath ) ;
1122- if ( ! archive ) return ;
1123- const stats = archive . stat ( info . filePath ) ;
1124- if ( ! stats ) continue ;
1125- type = stats . type ;
1126- }
1127-
1128- const dirent = getDirent ( pathArg , readdirResult [ 0 ] [ i ] , type ) ;
1129-
1130- context . readdirResults . push ( dirent ) ;
1131- if ( dirent . isDirectory ( ) ) {
1132- context . pathsQueue . push ( path . join ( dirent . path , dirent . name ) ) ;
1133- }
1134- }
1135- } else {
1136- for ( let i = 0 ; i < readdirResult . length ; i ++ ) {
1137- const resultPath = path . join ( pathArg , readdirResult [ i ] ) ;
1138- const relativeResultPath = path . relative ( basePath , resultPath ) ;
1139- const stat = internalBinding ( 'fs' ) . internalModuleStat ( binding , resultPath ) ;
1140-
1141- context . readdirResults . push ( relativeResultPath ) ;
1142- if ( stat === 1 ) context . pathsQueue . push ( resultPath ) ;
1143- }
1118+ if ( readdirResult === undefined ) {
1119+ return ;
11441120 }
1121+
1122+ processReaddirResult ( {
1123+ result : readdirResult ,
1124+ currentPath : path ,
1125+ context
1126+ } ) ;
11451127 }
11461128
11471129 for ( let i = 0 ; i < context . pathsQueue . length ; i ++ ) {
0 commit comments