Skip to content

Commit e2137b7

Browse files
authored
feat: resolved ids rollup compat for win32 (#1693)
fix #1522
1 parent b0b0b23 commit e2137b7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/vite/src/node/plugins/resolve.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isObject,
1414
normalizePath,
1515
fsPathFromId,
16+
ensureVolumeInPath,
1617
resolveFrom,
1718
isDataUrl,
1819
cleanUrl,
@@ -262,7 +263,7 @@ function tryResolveFile(
262263
if (index) return normalizePath(index) + query
263264
}
264265
} else {
265-
return normalizePath(file) + query
266+
return normalizePath(ensureVolumeInPath(file)) + query
266267
}
267268
}
268269
}

packages/vite/src/node/utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ const isWindows = os.platform() === 'win32'
6060
const VOLUME_RE = /^[A-Z]:/i
6161

6262
export function normalizePath(id: string): string {
63-
if (isWindows) {
64-
return path.posix.normalize(slash(id.replace(VOLUME_RE, '')))
65-
}
66-
return path.posix.normalize(id)
63+
return path.posix.normalize(isWindows ? slash(id) : id)
6764
}
6865

6966
export function fsPathFromId(id: string): string {
7067
const fsPath = normalizePath(id.slice(FS_PREFIX.length))
71-
return fsPath.startsWith('/') ? fsPath : `/${fsPath}`
68+
return fsPath.startsWith('/') || fsPath.match(VOLUME_RE)
69+
? fsPath
70+
: `/${fsPath}`
71+
}
72+
73+
export function ensureVolumeInPath(file: string): string {
74+
return isWindows ? path.resolve(file) : file
7275
}
7376

7477
export const queryRE = /\?.*$/

0 commit comments

Comments
 (0)