88 StringPrototypeStartsWith,
99} = primordials ;
1010
11- const { dirname, extname, isAbsolute, normalize, resolve } = require ( 'path' ) ;
11+ const path = require ( 'path' ) ;
12+ const { dirname, extname, isAbsolute, resolve } = path ;
13+ const pathPosix = path . posix ;
1214const { extensionFormatMap } = require ( 'internal/modules/esm/formats' ) ;
15+
16+ /**
17+ * Normalizes a VFS path. Uses POSIX normalization for Unix-style paths (starting with /)
18+ * and platform normalization for Windows drive letter paths.
19+ * @param {string } inputPath The path to normalize
20+ * @returns {string } The normalized path
21+ */
22+ function normalizeVFSPath ( inputPath ) {
23+ // If path starts with / (Unix-style), use posix normalization to preserve forward slashes
24+ if ( inputPath . startsWith ( '/' ) ) {
25+ return pathPosix . normalize ( inputPath ) ;
26+ }
27+ // Otherwise use platform normalization (for Windows drive letters like C:\)
28+ return path . normalize ( inputPath ) ;
29+ }
1330const { isURL, pathToFileURL, fileURLToPath, toPathIfFileURL, URL } = require ( 'internal/url' ) ;
1431const { kEmptyObject } = require ( 'internal/util' ) ;
1532const { validateObject } = require ( 'internal/validators' ) ;
@@ -79,7 +96,7 @@ function unregisterVFS(vfs) {
7996 * @returns {{ vfs: VirtualFileSystem, result: number }|null }
8097 */
8198function findVFSForStat ( filename ) {
82- const normalized = normalize ( filename ) ;
99+ const normalized = normalizeVFSPath ( filename ) ;
83100 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
84101 const vfs = activeVFSList [ i ] ;
85102 if ( vfs . shouldHandle ( normalized ) ) {
@@ -101,7 +118,7 @@ function findVFSForStat(filename) {
101118 * @returns {{ vfs: VirtualFileSystem, content: Buffer|string }|null }
102119 */
103120function findVFSForRead ( filename , options ) {
104- const normalized = normalize ( filename ) ;
121+ const normalized = normalizeVFSPath ( filename ) ;
105122 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
106123 const vfs = activeVFSList [ i ] ;
107124 if ( vfs . shouldHandle ( normalized ) ) {
@@ -140,7 +157,7 @@ function findVFSForRead(filename, options) {
140157 * @returns {{ vfs: VirtualFileSystem, exists: boolean }|null }
141158 */
142159function findVFSForExists ( filename ) {
143- const normalized = normalize ( filename ) ;
160+ const normalized = normalizeVFSPath ( filename ) ;
144161 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
145162 const vfs = activeVFSList [ i ] ;
146163 if ( vfs . shouldHandle ( normalized ) ) {
@@ -161,7 +178,7 @@ function findVFSForExists(filename) {
161178 * @returns {{ vfs: VirtualFileSystem, realpath: string }|null }
162179 */
163180function findVFSForRealpath ( filename ) {
164- const normalized = normalize ( filename ) ;
181+ const normalized = normalizeVFSPath ( filename ) ;
165182 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
166183 const vfs = activeVFSList [ i ] ;
167184 if ( vfs . shouldHandle ( normalized ) ) {
@@ -188,7 +205,7 @@ function findVFSForRealpath(filename) {
188205 * @returns {{ vfs: VirtualFileSystem, stats: Stats }|null }
189206 */
190207function findVFSForFsStat ( filename ) {
191- const normalized = normalize ( filename ) ;
208+ const normalized = normalizeVFSPath ( filename ) ;
192209 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
193210 const vfs = activeVFSList [ i ] ;
194211 if ( vfs . shouldHandle ( normalized ) ) {
@@ -216,7 +233,7 @@ function findVFSForFsStat(filename) {
216233 * @returns {{ vfs: VirtualFileSystem, entries: string[]|Dirent[] }|null }
217234 */
218235function findVFSForReaddir ( dirname , options ) {
219- const normalized = normalize ( dirname ) ;
236+ const normalized = normalizeVFSPath ( dirname ) ;
220237 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
221238 const vfs = activeVFSList [ i ] ;
222239 if ( vfs . shouldHandle ( normalized ) ) {
@@ -244,7 +261,7 @@ function findVFSForReaddir(dirname, options) {
244261 * @returns {Promise<{ vfs: VirtualFileSystem, entries: string[]|Dirent[] }|null> }
245262 */
246263async function findVFSForReaddirAsync ( dirname , options ) {
247- const normalized = normalize ( dirname ) ;
264+ const normalized = normalizeVFSPath ( dirname ) ;
248265 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
249266 const vfs = activeVFSList [ i ] ;
250267 if ( vfs . shouldHandle ( normalized ) ) {
@@ -271,7 +288,7 @@ async function findVFSForReaddirAsync(dirname, options) {
271288 * @returns {Promise<{ vfs: VirtualFileSystem, stats: Stats }|null> }
272289 */
273290async function findVFSForLstatAsync ( filename ) {
274- const normalized = normalize ( filename ) ;
291+ const normalized = normalizeVFSPath ( filename ) ;
275292 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
276293 const vfs = activeVFSList [ i ] ;
277294 if ( vfs . shouldHandle ( normalized ) ) {
@@ -299,7 +316,7 @@ async function findVFSForLstatAsync(filename) {
299316 * @returns {{ vfs: VirtualFileSystem }|null }
300317 */
301318function findVFSForWatch ( filename ) {
302- const normalized = normalize ( filename ) ;
319+ const normalized = normalizeVFSPath ( filename ) ;
303320 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
304321 const vfs = activeVFSList [ i ] ;
305322 if ( vfs . shouldHandle ( normalized ) ) {
@@ -382,7 +399,7 @@ function vfsResolveHook(specifier, context, nextResolve) {
382399 }
383400
384401 // Check if any VFS handles this path
385- const normalized = normalize ( checkPath ) ;
402+ const normalized = normalizeVFSPath ( checkPath ) ;
386403 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
387404 const vfs = activeVFSList [ i ] ;
388405 if ( vfs . shouldHandle ( normalized ) && vfs . existsSync ( normalized ) ) {
@@ -426,7 +443,7 @@ function vfsLoadHook(url, context, nextLoad) {
426443 }
427444
428445 const filePath = fileURLToPath ( url ) ;
429- const normalized = normalize ( filePath ) ;
446+ const normalized = normalizeVFSPath ( filePath ) ;
430447
431448 // Check if any VFS handles this path
432449 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
0 commit comments