Skip to content

Commit

Permalink
fix: fix path normalization for windows paths w/ non ascii chars
Browse files Browse the repository at this point in the history
fix #1384
  • Loading branch information
yyx990803 committed Feb 9, 2021
1 parent 1953807 commit 03b323d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"rollup-plugin-license": "^2.2.0",
"selfsigned": "^1.10.8",
"sirv": "^1.0.10",
"slash": "^3.0.0",
"source-map": "^0.6.1",
"source-map-support": "^0.5.19",
"strip-ansi": "^6.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check
import fs from 'fs'
import path from 'path'
import slash from 'slash'
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
Expand Down Expand Up @@ -188,7 +187,7 @@ function shimDepsPlugin(deps) {
name: 'shim-deps',
transform(code, id) {
for (const file in deps) {
if (slash(id).endsWith(file)) {
if (id.replace(/\\/g, '/').endsWith(file)) {
const { src, replacement, pattern } = deps[file]

const magicString = new MagicString(code)
Expand Down
9 changes: 7 additions & 2 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import path from 'path'
import { Plugin } from '../plugin'
import { ViteDevServer } from '../server'
import { OutputAsset, OutputBundle, OutputChunk } from 'rollup'
import { cleanUrl, isExternalUrl, isDataUrl, generateCodeFrame } from '../utils'
import {
slash,
cleanUrl,
isExternalUrl,
isDataUrl,
generateCodeFrame
} from '../utils'
import { ResolvedConfig } from '../config'
import slash from 'slash'
import MagicString from 'magic-string'
import {
checkPublicFile,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
ensureVolumeInPath,
resolveFrom,
isDataUrl,
cleanUrl
cleanUrl,
slash
} from '../utils'
import { ViteDevServer } from '..'
import slash from 'slash'
import { createFilter } from '@rollup/pluginutils'
import { PartialResolvedId } from 'rollup'
import { resolve as _resolveExports } from 'resolve.exports'
Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import { createServer, ViteDevServer } from '..'
import { createDebugger, normalizePath } from '../utils'
import { ModuleNode } from './moduleGraph'
import chalk from 'chalk'
import slash from 'slash'
import { Update } from 'types/hmrPayload'
import { CLIENT_DIR } from '../constants'
import { RollupError } from 'rollup'
Expand Down Expand Up @@ -96,7 +95,7 @@ export async function handleHMRUpdate(
type: 'full-reload',
path: config.server.middlewareMode
? '*'
: '/' + slash(path.relative(config.root, file))
: '/' + normalizePath(path.relative(config.root, file))
})
} else {
// loaded but not in the module graph, probably not js
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import fs from 'fs'
import os from 'os'
import path from 'path'
import { parse as parseUrl } from 'url'
import slash from 'slash'
import { FS_PREFIX, SUPPORTED_EXTS } from './constants'
import resolve from 'resolve'
import builtins from 'builtin-modules'
import { FSWatcher } from 'chokidar'

export function slash(p: string): string {
return p.replace(/\\/g, '/')
}

export const flattenId = (id: string) => id.replace(/[\/\.]/g, '_')

export function isBuiltin(id: string): boolean {
Expand Down

0 comments on commit 03b323d

Please sign in to comment.