@@ -100,21 +100,24 @@ export async function checkSiblingFilesInTargetOrBuildParent(excludeDir: string,
100100 : buildIndex !== - 1 ? pathParts . slice ( 0 , buildIndex ) . join ( path . sep )
101101 : path . dirname ( path . dirname ( excludeDir ) ) ;
102102
103- // Read all files in the parent directory
104- const files = await fs . promises . readdir ( parentDir ) ;
103+ // Read all entries ( files and directories) in the parent directory with type information
104+ const entries = await fs . promises . readdir ( parentDir , { withFileTypes : true } ) ;
105105
106- // Check if 'fileType' is in the parent directory or its subdirectories
107- if ( files . includes ( fileType ) ) {
106+ // Check if 'fileType' is directly in the parent directory
107+ if ( entries . some ( entry => entry . isFile ( ) && entry . name === fileType ) ) {
108108 console . log ( `Found ${ fileType } directly in the parent directory: ${ parentDir } ` ) ;
109- return true ;
109+ return true ;
110110 }
111111
112112 // Loop through subdirectories and check for the file
113- for ( const file of files ) {
114- const filePath = path . join ( parentDir , file ) ;
115- if ( ( await fs . promises . stat ( filePath ) ) . isDirectory ( ) ) {
116- const subdirFiles = await fs . promises . readdir ( filePath ) ;
117- if ( subdirFiles . includes ( fileType ) ) {
113+ for ( const entry of entries ) {
114+ const filePath = path . join ( parentDir , entry . name ) ;
115+ if ( entry . isDirectory ( ) ) {
116+ // Read entries in the subdirectory
117+ const subdirEntries = await fs . promises . readdir ( filePath , { withFileTypes : true } ) ;
118+
119+ // Check if 'fileType' exists in the subdirectory
120+ if ( subdirEntries . some ( subentry => subentry . isFile ( ) && subentry . name === fileType ) ) {
118121 console . log ( `Found sibling ${ fileType } in directory: ${ filePath } ` ) ;
119122 return true ;
120123 }
0 commit comments