Skip to content

Commit 09d11c1

Browse files
authored
fix: correct the return value of parseReadablePath on Windows (#75)
1 parent 3ab1277 commit 09d11c1

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

packages/devtools-vite/src/app/utils/filepath.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,27 @@ export function isBuiltInModule(name: string | undefined) {
3434
}
3535

3636
export const parseReadablePath = makeCachedFunction((path: string, root: string) => {
37-
path = path
37+
const parsedPath = path
3838
.replace(/%2F/g, '/')
3939
.replace(/\\/g, '/')
40-
if (isPackageName(path)) {
40+
if (isPackageName(parsedPath)) {
4141
return {
42-
moduleName: path,
43-
path,
42+
moduleName: parsedPath,
43+
path: parsedPath,
4444
}
4545
}
4646

47-
if (path.match(/^\w+:/)) {
47+
if (parsedPath.match(/^\w+:/)
48+
&& !(path.match(/^[a-z]:\\/i)) // in order to check if it is Windows' path
49+
) {
4850
return {
49-
moduleName: path,
50-
path,
51+
moduleName: parsedPath,
52+
path: parsedPath,
5153
}
5254
}
5355

54-
const moduleName = getModuleNameFromPath(path)
55-
const subpath = getModuleSubpathFromPath(path)
56+
const moduleName = getModuleNameFromPath(parsedPath)
57+
const subpath = getModuleSubpathFromPath(parsedPath)
5658
if (moduleName && subpath) {
5759
return {
5860
moduleName,
@@ -61,14 +63,14 @@ export const parseReadablePath = makeCachedFunction((path: string, root: string)
6163
}
6264
// Workaround https://github.com/unjs/pathe/issues/113
6365
try {
64-
let result = relative(root, path)
66+
let result = relative(root, parsedPath)
6567
if (!result.startsWith('./') && !result.startsWith('../'))
6668
result = `./${result}`
6769
if (result.startsWith('./.nuxt/'))
6870
result = `#build${result.slice(7)}`
6971
return { path: result }
7072
}
7173
catch {
72-
return { path }
74+
return { path: parsedPath }
7375
}
7476
})

0 commit comments

Comments
 (0)