@@ -101,6 +101,24 @@ function deregisterVFS(vfs) {
101101 // as another VFS might be registered later.
102102}
103103
104+ /**
105+ * Returns the stat result code for a VFS path.
106+ * @param {VirtualFileSystem } vfs The VFS instance
107+ * @param {string } filePath The path to check
108+ * @returns {number } 0 for file, 1 for directory, -2 for not found
109+ */
110+ function vfsStat ( vfs , filePath ) {
111+ try {
112+ const stats = vfs . statSync ( filePath ) ;
113+ if ( stats . isDirectory ( ) ) {
114+ return 1 ;
115+ }
116+ return 0 ;
117+ } catch {
118+ return - 2 ;
119+ }
120+ }
121+
104122/**
105123 * Checks all active VFS instances for a file/directory.
106124 * @param {string } filename The absolute path to check
@@ -111,7 +129,7 @@ function findVFSForStat(filename) {
111129 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
112130 const vfs = activeVFSList [ i ] ;
113131 if ( vfs . shouldHandle ( normalized ) ) {
114- const result = vfs . internalModuleStat ( normalized ) ;
132+ const result = vfsStat ( vfs , normalized ) ;
115133 // For mounted VFS, always return result (even -2 for ENOENT within mount)
116134 // For overlay VFS, only return if found
117135 if ( vfs . mounted || result >= 0 ) {
@@ -136,7 +154,7 @@ function findVFSForRead(filename, options) {
136154 // Check if the file actually exists in VFS
137155 if ( vfs . existsSync ( normalized ) ) {
138156 // Only read files, not directories
139- const statResult = vfs . internalModuleStat ( normalized ) ;
157+ const statResult = vfsStat ( vfs , normalized ) ;
140158 if ( statResult !== 0 ) {
141159 // Not a file (1 = dir, -2 = not found)
142160 // Let the real fs handle it (will throw appropriate error)
@@ -377,7 +395,7 @@ function getVFSPackageType(vfs, filePath) {
377395 break ;
378396 }
379397 const pjsonPath = normalizeVFSPath ( resolve ( currentDir , 'package.json' ) ) ;
380- if ( vfs . shouldHandle ( pjsonPath ) && vfs . internalModuleStat ( pjsonPath ) === 0 ) {
398+ if ( vfs . shouldHandle ( pjsonPath ) && vfsStat ( vfs , pjsonPath ) === 0 ) {
381399 try {
382400 const content = vfs . readFileSync ( pjsonPath , 'utf8' ) ;
383401 const parsed = JSONParse ( content ) ;
@@ -420,7 +438,7 @@ function tryExtensions(vfs, basePath) {
420438 const extensions = [ '.js' , '.json' , '.node' , '.mjs' , '.cjs' ] ;
421439 for ( let i = 0 ; i < extensions . length ; i ++ ) {
422440 const candidate = basePath + extensions [ i ] ;
423- if ( vfs . internalModuleStat ( candidate ) === 0 ) {
441+ if ( vfsStat ( vfs , candidate ) === 0 ) {
424442 return candidate ;
425443 }
426444 }
@@ -437,7 +455,7 @@ function tryIndexFiles(vfs, dirPath) {
437455 const indexFiles = [ 'index.js' , 'index.mjs' , 'index.cjs' , 'index.json' ] ;
438456 for ( let i = 0 ; i < indexFiles . length ; i ++ ) {
439457 const candidate = normalizeVFSPath ( resolve ( dirPath , indexFiles [ i ] ) ) ;
440- if ( vfs . internalModuleStat ( candidate ) === 0 ) {
458+ if ( vfsStat ( vfs , candidate ) === 0 ) {
441459 const url = pathToFileURL ( candidate ) . href ;
442460 const format = getVFSFormat ( vfs , candidate ) ;
443461 return { url, format, shortCircuit : true } ;
@@ -462,7 +480,7 @@ function resolveConditions(vfs, pkgDir, condMap, conditions) {
462480 const value = condMap [ key ] ;
463481 if ( typeof value === 'string' ) {
464482 const resolved = normalizeVFSPath ( resolve ( pkgDir , value ) ) ;
465- if ( vfs . internalModuleStat ( resolved ) === 0 ) {
483+ if ( vfsStat ( vfs , resolved ) === 0 ) {
466484 const url = pathToFileURL ( resolved ) . href ;
467485 const format = getVFSFormat ( vfs , resolved ) ;
468486 return { url, format, shortCircuit : true } ;
@@ -497,7 +515,7 @@ function resolvePackageExports(vfs, pkgDir, packageSubpath, exports, context) {
497515 if ( typeof exports === 'string' ) {
498516 if ( packageSubpath === '.' ) {
499517 const resolved = normalizeVFSPath ( resolve ( pkgDir , exports ) ) ;
500- if ( vfs . internalModuleStat ( resolved ) === 0 ) {
518+ if ( vfsStat ( vfs , resolved ) === 0 ) {
501519 const url = pathToFileURL ( resolved ) . href ;
502520 const format = getVFSFormat ( vfs , resolved ) ;
503521 return { url, format, shortCircuit : true } ;
@@ -527,7 +545,7 @@ function resolvePackageExports(vfs, pkgDir, packageSubpath, exports, context) {
527545
528546 if ( typeof target === 'string' ) {
529547 const resolved = normalizeVFSPath ( resolve ( pkgDir , target ) ) ;
530- if ( vfs . internalModuleStat ( resolved ) === 0 ) {
548+ if ( vfsStat ( vfs , resolved ) === 0 ) {
531549 const url = pathToFileURL ( resolved ) . href ;
532550 const format = getVFSFormat ( vfs , resolved ) ;
533551 return { url, format, shortCircuit : true } ;
@@ -552,7 +570,7 @@ function resolvePackageExports(vfs, pkgDir, packageSubpath, exports, context) {
552570 */
553571function resolveDirectoryEntry ( vfs , dirPath , context ) {
554572 const pjsonPath = normalizeVFSPath ( resolve ( dirPath , 'package.json' ) ) ;
555- if ( vfs . internalModuleStat ( pjsonPath ) === 0 ) {
573+ if ( vfsStat ( vfs , pjsonPath ) === 0 ) {
556574 try {
557575 const content = vfs . readFileSync ( pjsonPath , 'utf8' ) ;
558576 const parsed = JSONParse ( content ) ;
@@ -567,7 +585,7 @@ function resolveDirectoryEntry(vfs, dirPath, context) {
567585 // Try main
568586 if ( parsed . main ) {
569587 const mainPath = normalizeVFSPath ( resolve ( dirPath , parsed . main ) ) ;
570- if ( vfs . internalModuleStat ( mainPath ) === 0 ) {
588+ if ( vfsStat ( vfs , mainPath ) === 0 ) {
571589 const url = pathToFileURL ( mainPath ) . href ;
572590 const format = getVFSFormat ( vfs , mainPath ) ;
573591 return { url, format, shortCircuit : true } ;
@@ -623,7 +641,7 @@ function resolveVFSPath(checkPath, context, nextResolve, specifier) {
623641 const vfs = activeVFSList [ i ] ;
624642 if ( ! vfs . shouldHandle ( normalized ) ) continue ;
625643
626- const stat = vfs . internalModuleStat ( normalized ) ;
644+ const stat = vfsStat ( vfs , normalized ) ;
627645
628646 if ( stat === 0 ) {
629647 // It's a file
@@ -701,10 +719,10 @@ function resolveBareSpecifier(specifier, context, nextResolve) {
701719 resolve ( currentDir , 'node_modules' , packageName ) ) ;
702720
703721 if ( parentVfs . shouldHandle ( pkgDir ) &&
704- parentVfs . internalModuleStat ( pkgDir ) === 1 ) {
722+ vfsStat ( parentVfs , pkgDir ) === 1 ) {
705723 // Found the package directory
706724 const pjsonPath = normalizeVFSPath ( resolve ( pkgDir , 'package.json' ) ) ;
707- if ( parentVfs . internalModuleStat ( pjsonPath ) === 0 ) {
725+ if ( vfsStat ( parentVfs , pjsonPath ) === 0 ) {
708726 try {
709727 const content = parentVfs . readFileSync ( pjsonPath , 'utf8' ) ;
710728 const parsed = JSONParse ( content ) ;
@@ -720,7 +738,7 @@ function resolveBareSpecifier(specifier, context, nextResolve) {
720738 if ( packageSubpath === '.' ) {
721739 if ( parsed . main ) {
722740 const mainPath = normalizeVFSPath ( resolve ( pkgDir , parsed . main ) ) ;
723- if ( parentVfs . internalModuleStat ( mainPath ) === 0 ) {
741+ if ( vfsStat ( parentVfs , mainPath ) === 0 ) {
724742 const url = pathToFileURL ( mainPath ) . href ;
725743 const format = getVFSFormat ( parentVfs , mainPath ) ;
726744 return { url, format, shortCircuit : true } ;
@@ -738,7 +756,7 @@ function resolveBareSpecifier(specifier, context, nextResolve) {
738756 // Resolve subpath like './feature'
739757 const subResolved = normalizeVFSPath (
740758 resolve ( pkgDir , packageSubpath ) ) ;
741- if ( parentVfs . internalModuleStat ( subResolved ) === 0 ) {
759+ if ( vfsStat ( parentVfs , subResolved ) === 0 ) {
742760 const url = pathToFileURL ( subResolved ) . href ;
743761 const format = getVFSFormat ( parentVfs , subResolved ) ;
744762 return { url, format, shortCircuit : true } ;
@@ -840,7 +858,7 @@ function vfsLoadHook(url, context, nextLoad) {
840858 const vfs = activeVFSList [ i ] ;
841859 if ( vfs . shouldHandle ( normalized ) && vfs . existsSync ( normalized ) ) {
842860 // Only load files, not directories
843- const statResult = vfs . internalModuleStat ( normalized ) ;
861+ const statResult = vfsStat ( vfs , normalized ) ;
844862 if ( statResult !== 0 ) {
845863 return nextLoad ( url , context ) ;
846864 }
0 commit comments