@@ -4,6 +4,7 @@ import { basename, extname, resolve } from 'node:path'
44import parseGitignore from 'parse-gitignore'
55import ignore from 'ignore'
66
7+ import { hasDrive , stripDrive } from './utils'
78import type { Environment } from './types'
89
910const BINARY_EXTENSIONS = [ '.png' , '.jpg' , '.jpeg' , '.gif' , '.svg' , '.ico' ]
@@ -43,7 +44,17 @@ export function toCleanPath(absolutePath: string, baseDir: string): string {
4344 // Normalize both paths to use forward slashes for consistent comparison
4445 const normalizedPath = absolutePath . replace ( / \\ / g, '/' )
4546 const normalizedBase = baseDir . replace ( / \\ / g, '/' )
46- let cleanPath = normalizedPath . replace ( normalizedBase , '' )
47+ let cleanPath = normalizedPath
48+ if ( normalizedPath . startsWith ( normalizedBase ) ) {
49+ cleanPath = normalizedPath . slice ( normalizedBase . length )
50+ } else if ( hasDrive ( normalizedPath ) !== hasDrive ( normalizedBase ) ) {
51+ // Handle paths that are missing the Windows drive letter (e.g. memfs on Windows)
52+ const pathNoDrive = stripDrive ( normalizedPath )
53+ const baseNoDrive = stripDrive ( normalizedBase )
54+ if ( pathNoDrive . startsWith ( baseNoDrive ) ) {
55+ cleanPath = pathNoDrive . slice ( baseNoDrive . length )
56+ }
57+ }
4758 // Handle leading path separator
4859 if ( cleanPath . startsWith ( '/' ) ) {
4960 cleanPath = cleanPath . slice ( 1 )
0 commit comments