@@ -37,6 +37,7 @@ interface InputFileSystem {
3737 encoding : null | undefined ,
3838 callback : ( err : Error | null , stats : Buffer ) => void
3939 ) => void ;
40+ statSync : ( path : string ) => any ;
4041}
4142
4243/**
@@ -48,6 +49,22 @@ interface InputFileSystem {
4849 */
4950const EXTRA_SCSS_WORK_UNITS = 100 ;
5051
52+ const fileCheckCache = new Map ( ) ;
53+ function isFile ( inputFileSystem : InputFileSystem , path : string ) {
54+ if ( fileCheckCache . has ( path ) ) {
55+ return fileCheckCache . get ( path ) ;
56+ }
57+
58+ try {
59+ const result = inputFileSystem . statSync ( path ) . isFile ( ) ;
60+ fileCheckCache . set ( path , result ) ;
61+ return result ;
62+ } catch ( err ) {
63+ fileCheckCache . set ( path , false ) ;
64+ return false ; // Path does not exist or is not a file
65+ }
66+ }
67+
5168export class PopulateBundleCachePlugin {
5269 constructor (
5370 private readonly workerConfig : WorkerConfig ,
@@ -78,7 +95,7 @@ export class PopulateBundleCachePlugin {
7895 // in webpack v5 there a lot of paths collected that are not real files
7996 // but instead folders or partial paths.
8097 // Here we're verifying if what we have as indeed a filepath
81- if ( Path . extname ( path ) . length > 0 ) {
98+ if ( isFile ( inputFs , path ) ) {
8299 realFileDeps . push ( path ) ;
83100 allFileDepsPathSet . add ( path ) ;
84101 }
@@ -127,7 +144,7 @@ export class PopulateBundleCachePlugin {
127144 for ( const module of compilation . modules ) {
128145 if ( isNormalModule ( module ) ) {
129146 const path = getModulePath ( module ) ;
130- if ( Path . extname ( path ) . length === 0 ) {
147+ if ( ! isFile ( inputFs , path ) ) {
131148 continue ;
132149 }
133150
0 commit comments