@@ -195,26 +195,6 @@ class MemoryProvider extends VirtualProvider {
195195 return path . slice ( 1 ) . split ( '/' ) ;
196196 }
197197
198- /**
199- * Gets the parent path.
200- * @param {string } path Normalized path
201- * @returns {string|null } Parent path or null for root
202- */
203- #getParentPath( path ) {
204- if ( path === '/' ) {
205- return null ;
206- }
207- return pathPosix . dirname ( path ) ;
208- }
209-
210- /**
211- * Gets the base name.
212- * @param {string } path Normalized path
213- * @returns {string } Base name
214- */
215- #getBaseName( path ) {
216- return pathPosix . basename ( path ) ;
217- }
218198
219199 /**
220200 * Resolves a symlink target to an absolute path.
@@ -227,7 +207,7 @@ class MemoryProvider extends VirtualProvider {
227207 return this . #normalizePath( target ) ;
228208 }
229209 // Relative target: resolve against symlink's parent directory
230- const parentPath = this . #getParentPath ( symlinkPath ) || '/' ;
210+ const parentPath = pathPosix . dirname ( symlinkPath ) ;
231211 return this . #normalizePath( pathPosix . join ( parentPath , target ) ) ;
232212 }
233213
@@ -323,10 +303,10 @@ class MemoryProvider extends VirtualProvider {
323303 * @returns {MemoryEntry } The parent directory entry
324304 */
325305 #ensureParent( path , create , syscall ) {
326- const parentPath = this . #getParentPath( path ) ;
327- if ( parentPath === null ) {
306+ if ( path === '/' ) {
328307 return this [ kRoot ] ;
329308 }
309+ const parentPath = pathPosix . dirname ( path ) ;
330310
331311 const segments = this . #splitPath( parentPath ) ;
332312 let current = this [ kRoot ] ;
@@ -458,7 +438,7 @@ class MemoryProvider extends VirtualProvider {
458438 if ( err . code !== 'ENOENT' || ! isCreate ) throw err ;
459439 // Create the file
460440 const parent = this . #ensureParent( normalized , true , 'open' ) ;
461- const name = this . #getBaseName ( normalized ) ;
441+ const name = pathPosix . basename ( normalized ) ;
462442 entry = new MemoryEntry ( TYPE_FILE , { mode } ) ;
463443 entry . content = Buffer . alloc ( 0 ) ;
464444 parent . children . set ( name , entry ) ;
@@ -570,7 +550,7 @@ class MemoryProvider extends VirtualProvider {
570550 }
571551 } else {
572552 const parent = this . #ensureParent( normalized , false , 'mkdir' ) ;
573- const name = this . #getBaseName ( normalized ) ;
553+ const name = pathPosix . basename ( normalized ) ;
574554 const entry = new MemoryEntry ( TYPE_DIR , { mode : options ?. mode } ) ;
575555 entry . children = new SafeMap ( ) ;
576556 parent . children . set ( name , entry ) ;
@@ -600,7 +580,7 @@ class MemoryProvider extends VirtualProvider {
600580 }
601581
602582 const parent = this . #ensureParent( normalized , false , 'rmdir' ) ;
603- const name = this . #getBaseName ( normalized ) ;
583+ const name = pathPosix . basename ( normalized ) ;
604584 parent . children . delete ( name ) ;
605585 }
606586
@@ -621,7 +601,7 @@ class MemoryProvider extends VirtualProvider {
621601 }
622602
623603 const parent = this . #ensureParent( normalized , false , 'unlink' ) ;
624- const name = this . #getBaseName ( normalized ) ;
604+ const name = pathPosix . basename ( normalized ) ;
625605 parent . children . delete ( name ) ;
626606 }
627607
@@ -642,12 +622,12 @@ class MemoryProvider extends VirtualProvider {
642622
643623 // Remove from old location
644624 const oldParent = this . #ensureParent( normalizedOld , false , 'rename' ) ;
645- const oldName = this . #getBaseName ( normalizedOld ) ;
625+ const oldName = pathPosix . basename ( normalizedOld ) ;
646626 oldParent . children . delete ( oldName ) ;
647627
648628 // Add to new location
649629 const newParent = this . #ensureParent( normalizedNew , true , 'rename' ) ;
650- const newName = this . #getBaseName ( normalizedNew ) ;
630+ const newName = pathPosix . basename ( normalizedNew ) ;
651631 newParent . children . set ( newName , entry ) ;
652632 }
653633
@@ -684,7 +664,7 @@ class MemoryProvider extends VirtualProvider {
684664 }
685665
686666 const parent = this . #ensureParent( normalized , true , 'symlink' ) ;
687- const name = this . #getBaseName ( normalized ) ;
667+ const name = pathPosix . basename ( normalized ) ;
688668 const entry = new MemoryEntry ( TYPE_SYMLINK ) ;
689669 entry . target = target ;
690670 parent . children . set ( name , entry ) ;
0 commit comments