Skip to content

Commit

Permalink
feat: resolved ids rollup compat for win32 (#1693)
Browse files Browse the repository at this point in the history
fix #1522
  • Loading branch information
patak-dev committed Jan 25, 2021
1 parent b0b0b23 commit e2137b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -13,6 +13,7 @@ import {
isObject,
normalizePath,
fsPathFromId,
ensureVolumeInPath,
resolveFrom,
isDataUrl,
cleanUrl,
Expand Down Expand Up @@ -262,7 +263,7 @@ function tryResolveFile(
if (index) return normalizePath(index) + query
}
} else {
return normalizePath(file) + query
return normalizePath(ensureVolumeInPath(file)) + query
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/vite/src/node/utils.ts
Expand Up @@ -60,15 +60,18 @@ const isWindows = os.platform() === 'win32'
const VOLUME_RE = /^[A-Z]:/i

export function normalizePath(id: string): string {
if (isWindows) {
return path.posix.normalize(slash(id.replace(VOLUME_RE, '')))
}
return path.posix.normalize(id)
return path.posix.normalize(isWindows ? slash(id) : id)
}

export function fsPathFromId(id: string): string {
const fsPath = normalizePath(id.slice(FS_PREFIX.length))
return fsPath.startsWith('/') ? fsPath : `/${fsPath}`
return fsPath.startsWith('/') || fsPath.match(VOLUME_RE)
? fsPath
: `/${fsPath}`
}

export function ensureVolumeInPath(file: string): string {
return isWindows ? path.resolve(file) : file
}

export const queryRE = /\?.*$/
Expand Down

0 comments on commit e2137b7

Please sign in to comment.