@@ -266,8 +266,8 @@ class MemoryProvider extends VirtualProvider {
266266 for ( let i = 0 ; i < segments . length ; i ++ ) {
267267 const segment = segments [ i ] ;
268268
269- // Follow symlinks for intermediate path components
270- if ( current . isSymbolicLink ( ) && followSymlinks ) {
269+ // Always follow symlinks for intermediate path components
270+ if ( current . isSymbolicLink ( ) ) {
271271 if ( depth >= kMaxSymlinkDepth ) {
272272 return { entry : null , resolvedPath : null , eloop : true } ;
273273 }
@@ -380,6 +380,16 @@ class MemoryProvider extends VirtualProvider {
380380 current = entry ;
381381 }
382382
383+ // Follow symlinks on the final parent entry
384+ if ( current . isSymbolicLink ( ) ) {
385+ const targetPath = this . #resolveSymlinkTarget( parentPath , current . target ) ;
386+ const result = this . #lookupEntry( targetPath , true , 0 ) ;
387+ if ( ! result . entry ) {
388+ throw createENOENT ( syscall , path ) ;
389+ }
390+ current = result . entry ;
391+ }
392+
383393 if ( ! current . isDirectory ( ) ) {
384394 throw createENOTDIR ( syscall , path ) ;
385395 }
@@ -396,12 +406,13 @@ class MemoryProvider extends VirtualProvider {
396406 * @param {number } [size] Override size for files
397407 * @returns {Stats }
398408 */
399- #createStats( entry , size ) {
409+ #createStats( entry , size , bigint ) {
400410 const options = {
401411 mode : entry . mode ,
402412 mtimeMs : entry . mtime ,
403413 ctimeMs : entry . ctime ,
404414 birthtimeMs : entry . birthtime ,
415+ bigint,
405416 } ;
406417
407418 if ( entry . isFile ( ) ) {
@@ -510,7 +521,7 @@ class MemoryProvider extends VirtualProvider {
510521
511522 statSync ( path , options ) {
512523 const entry = this . #getEntry( path , 'stat' , true ) ;
513- return this . #createStats( entry ) ;
524+ return this . #createStats( entry , undefined , options ?. bigint ) ;
514525 }
515526
516527 async stat ( path , options ) {
@@ -519,7 +530,7 @@ class MemoryProvider extends VirtualProvider {
519530
520531 lstatSync ( path , options ) {
521532 const entry = this . #getEntry( path , 'lstat' , false ) ;
522- return this . #createStats( entry ) ;
533+ return this . #createStats( entry , undefined , options ?. bigint ) ;
523534 }
524535
525536 async lstat ( path , options ) {
@@ -632,6 +643,7 @@ class MemoryProvider extends VirtualProvider {
632643 const segments = this . #splitPath( normalized ) ;
633644 let current = this [ kRoot ] ;
634645 let currentPath = '/' ;
646+ let firstCreated ;
635647
636648 for ( const segment of segments ) {
637649 currentPath = pathPosix . join ( currentPath , segment ) ;
@@ -640,20 +652,23 @@ class MemoryProvider extends VirtualProvider {
640652 entry = new MemoryEntry ( TYPE_DIR , { mode : options ?. mode } ) ;
641653 entry . children = new SafeMap ( ) ;
642654 current . children . set ( segment , entry ) ;
655+ if ( firstCreated === undefined ) {
656+ firstCreated = currentPath ;
657+ }
643658 } else if ( ! entry . isDirectory ( ) ) {
644659 throw createENOTDIR ( 'mkdir' , path ) ;
645660 }
646661 current = entry ;
647662 }
648- } else {
649- const parent = this . #ensureParent( normalized , false , 'mkdir' ) ;
650- const name = pathPosix . basename ( normalized ) ;
651- const entry = new MemoryEntry ( TYPE_DIR , { mode : options ?. mode } ) ;
652- entry . children = new SafeMap ( ) ;
653- parent . children . set ( name , entry ) ;
663+ return firstCreated ;
654664 }
655665
656- return recursive ? normalized : undefined ;
666+ const parent = this . #ensureParent( normalized , false , 'mkdir' ) ;
667+ const name = pathPosix . basename ( normalized ) ;
668+ const entry = new MemoryEntry ( TYPE_DIR , { mode : options ?. mode } ) ;
669+ entry . children = new SafeMap ( ) ;
670+ parent . children . set ( name , entry ) ;
671+ return undefined ;
657672 }
658673
659674 async mkdir ( path , options ) {
@@ -805,7 +820,7 @@ class MemoryProvider extends VirtualProvider {
805820 throw createEEXIST ( 'symlink' , path ) ;
806821 }
807822
808- const parent = this . #ensureParent( normalized , true , 'symlink' ) ;
823+ const parent = this . #ensureParent( normalized , false , 'symlink' ) ;
809824 const name = pathPosix . basename ( normalized ) ;
810825 const entry = new MemoryEntry ( TYPE_SYMLINK ) ;
811826 entry . target = target ;
0 commit comments