22
33const {
44 StringPrototypeEndsWith,
5+ StringPrototypeLastIndexOf,
6+ StringPrototypeReplaceAll,
57 StringPrototypeSlice,
8+ StringPrototypeSplit,
69 StringPrototypeStartsWith,
710} = primordials ;
811
9- const path = require ( 'path' ) ;
12+ const { basename , resolve , sep } = require ( 'path' ) ;
1013
1114/**
1215 * Normalizes a path for VFS lookup.
1316 * - Resolves to absolute path
1417 * - Removes trailing slashes (except for root)
15- * - Normalizes separators to forward slashes
18+ * - Normalizes separators to forward slashes (VFS uses '/' internally)
1619 * @param {string } inputPath The path to normalize
1720 * @returns {string } The normalized path
1821 */
1922function normalizePath ( inputPath ) {
20- let normalized = path . resolve ( inputPath ) ;
23+ let normalized = resolve ( inputPath ) ;
2124
22- // On Windows, convert backslashes to forward slashes for consistent lookup
23- if ( path . sep === '\\' ) {
24- normalized = normalized . replace ( / \\ / g, '/' ) ;
25+ // On Windows, convert backslashes to forward slashes for consistent VFS lookup.
26+ // VFS uses forward slashes internally regardless of platform.
27+ if ( sep === '\\' ) {
28+ normalized = StringPrototypeReplaceAll ( normalized , '\\' , '/' ) ;
2529 }
2630
2731 // Remove trailing slash (except for root)
@@ -34,27 +38,29 @@ function normalizePath(inputPath) {
3438
3539/**
3640 * Splits a path into segments.
41+ * VFS paths are always normalized to use forward slashes.
3742 * @param {string } normalizedPath A normalized absolute path
3843 * @returns {string[] } Path segments
3944 */
4045function splitPath ( normalizedPath ) {
4146 if ( normalizedPath === '/' ) {
4247 return [ ] ;
4348 }
44- // Remove leading slash and split
45- return StringPrototypeSlice ( normalizedPath , 1 ) . split ( '/' ) ;
49+ // Remove leading slash and split by forward slash (VFS internal format)
50+ return StringPrototypeSplit ( StringPrototypeSlice ( normalizedPath , 1 ) , '/' ) ;
4651}
4752
4853/**
4954 * Gets the parent path of a normalized path.
55+ * VFS paths are always normalized to use forward slashes.
5056 * @param {string } normalizedPath A normalized absolute path
5157 * @returns {string|null } The parent path, or null if at root
5258 */
5359function getParentPath ( normalizedPath ) {
5460 if ( normalizedPath === '/' ) {
5561 return null ;
5662 }
57- const lastSlash = normalizedPath . lastIndexOf ( '/' ) ;
63+ const lastSlash = StringPrototypeLastIndexOf ( normalizedPath , '/' ) ;
5864 if ( lastSlash === 0 ) {
5965 return '/' ;
6066 }
@@ -67,12 +73,14 @@ function getParentPath(normalizedPath) {
6773 * @returns {string } The base name
6874 */
6975function getBaseName ( normalizedPath ) {
70- const lastSlash = normalizedPath . lastIndexOf ( '/' ) ;
71- return StringPrototypeSlice ( normalizedPath , lastSlash + 1 ) ;
76+ // Basename works correctly for VFS paths since they use forward slashes
77+ return basename ( normalizedPath ) ;
7278}
7379
7480/**
7581 * Checks if a path is under a mount point.
82+ * Note: We don't use path.relative here because VFS mount point semantics
83+ * require exact prefix matching with the forward-slash separator.
7684 * @param {string } normalizedPath A normalized absolute path
7785 * @param {string } mountPoint A normalized mount point path
7886 * @returns {boolean }
@@ -87,6 +95,8 @@ function isUnderMountPoint(normalizedPath, mountPoint) {
8795
8896/**
8997 * Gets the relative path from a mount point.
98+ * Note: We don't use path.relative here because we need the VFS-internal
99+ * path format (starting with /) for consistent lookup.
90100 * @param {string } normalizedPath A normalized absolute path
91101 * @param {string } mountPoint A normalized mount point path
92102 * @returns {string } The relative path (starting with /)
@@ -100,6 +110,8 @@ function getRelativePath(normalizedPath, mountPoint) {
100110
101111/**
102112 * Joins a mount point with a relative path.
113+ * Note: We don't use path.join here because VFS relative paths start with /
114+ * and path.join would treat them as absolute paths.
103115 * @param {string } mountPoint A normalized mount point path
104116 * @param {string } relativePath A relative path (starting with /)
105117 * @returns {string } The joined absolute path
0 commit comments