Skip to content

Commit

Permalink
fix: @fs paths resolving for win32 (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jan 4, 2021
1 parent 2b82e84 commit 0a94c88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -12,6 +12,7 @@ import {
isExternalUrl,
isObject,
normalizePath,
fsPathFromId,
resolveFrom
} from '../utils'
import { ViteDevServer } from '..'
Expand Down Expand Up @@ -60,8 +61,7 @@ export function resolvePlugin({

// explicit fs paths that starts with /@fs/*
if (asSrc && id.startsWith(FS_PREFIX)) {
let fsPath = id.slice(FS_PREFIX.length - 1)
if (fsPath.startsWith('//')) fsPath = fsPath.slice(1)
const fsPath = fsPathFromId(id)
res = tryFsResolve(fsPath, false)
isDebug && debug(`[@fs] ${chalk.cyan(id)} -> ${chalk.dim(res)}`)
// always return here even if res doesn't exist since /@fs/ is explicit
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/utils.ts
Expand Up @@ -59,6 +59,11 @@ export function normalizePath(id: string): string {
return path.posix.normalize(id)
}

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

export const queryRE = /\?.*$/
export const hashRE = /#.*$/

Expand Down

0 comments on commit 0a94c88

Please sign in to comment.