Skip to content

Commit 610e0b1

Browse files
author
이종경
committed
fix: enhance toCleanPath for better Windows drive handling
1 parent 2cf6703 commit 610e0b1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/create/src/file-helpers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { basename, extname, resolve } from 'node:path'
44
import parseGitignore from 'parse-gitignore'
55
import ignore from 'ignore'
66

7+
import { hasDrive, stripDrive } from './utils'
78
import type { Environment } from './types'
89

910
const 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)

packages/create/src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ export function handleSpecialURL(url: string) {
4040
}
4141
return url
4242
}
43+
44+
export function hasDrive(path: string) {
45+
return /^[A-Za-z]:/.test(path)
46+
}
47+
48+
export function stripDrive(path: string) {
49+
return path.replace(/^[A-Za-z]:/, '')
50+
}

0 commit comments

Comments
 (0)