Skip to content

Commit

Permalink
fix: Windows path
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 19, 2023
1 parent c318065 commit 2e69cb8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async function loadAndTransform(
// to resolve and display them in a meaningful way (rather than
// with absolute paths).
if (path.isAbsolute(sourcePath)) {
map.sourceRoot = path.dirname(mod.file) + path.sep
map.sourceRoot = path.dirname(mod.file)
map.sources[sourcesIndex] = path.relative(
path.dirname(mod.file),
sourcePath,
Expand Down
2 changes: 1 addition & 1 deletion playground/css-sourcemap/__tests__/css-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe.runIf(isServe)('serve', () => {
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
{
"mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ",
"sourceRoot": "/root/",
"sourceRoot": "/root",
"sources": [
"be-imported.css",
"linked-with-import.css",
Expand Down
2 changes: 1 addition & 1 deletion playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (!isBuild) {
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
{
"mappings": "AAAO,aAAM,MAAM;",
"sourceRoot": "/root/",
"sourceRoot": "/root",
"sources": [
"bar.ts",
],
Expand Down
7 changes: 6 additions & 1 deletion playground/ssr-html/__tests__/ssr-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { promisify } from 'node:util'
import path from 'node:path'
import fetch from 'node-fetch'
import { describe, expect, test } from 'vitest'
import { normalizePath } from 'vite'
import { port } from './serve'
import { editFile, isServe, page, untilUpdated } from '~utils'

Expand Down Expand Up @@ -83,10 +84,14 @@ describe.runIf(isServe)('stacktrace', () => {

const reg = new RegExp(
// TODO: ts without sourcemaps will resolve column to 8 which should be 9
path.resolve(__dirname, '../src') + '/error\\.' + ext + ':2:[89]',
normalizePath(
path.resolve(__dirname, '../src', `error.${ext}`),
).replace('.', '\\.') + ':2:[89]',
'i',
)

lines.forEach((line) => {
console.log(line.trim())
expect(line.trim()).toMatch(reg)
})
})
Expand Down
2 changes: 1 addition & 1 deletion playground/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const formatSourcemapForSnapshot = (map: any): any => {
delete m.names
m.sources = m.sources.map((source) => source.replace(root, '/root'))
if (m.sourceRoot) {
m.sourceRoot = m.sourceRoot.replace(root + path.sep, '/root/')
m.sourceRoot = m.sourceRoot.replace(root, '/root')
}
return m
}
Expand Down

0 comments on commit 2e69cb8

Please sign in to comment.