Skip to content

Commit b997355

Browse files
authoredFeb 5, 2025··
fix(vite-node): remove fake first line mapping on Vite 6 (#7124)
1 parent 9542b69 commit b997355

File tree

5 files changed

+161
-373
lines changed

5 files changed

+161
-373
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"tinyglobby": "^0.2.10",
6363
"tsx": "^4.19.2",
6464
"typescript": "^5.7.3",
65-
"vite": "^5.4.0",
65+
"vite": "^6.0.11",
6666
"vitest": "workspace:*",
6767
"zx": "^8.3.0"
6868
},

‎packages/vite-node/src/server.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { performance } from 'node:perf_hooks'
1212
import { pathToFileURL } from 'node:url'
1313
import createDebug from 'debug'
1414
import { join, normalize, relative, resolve } from 'pathe'
15+
import { version as viteVersion } from 'vite'
1516
import { Debugger } from './debug'
1617
import { shouldExternalize } from './externalize'
1718
import { withInlineSourcemap } from './source-map'
@@ -392,6 +393,7 @@ export class ViteNodeServer {
392393
return withInlineSourcemap(result, {
393394
filepath: mod?.file || filepath,
394395
root: this.server.config.root,
396+
noFirstLineMapping: Number(viteVersion.split('.')[0]) >= 6,
395397
})
396398
}
397399

‎packages/vite-node/src/source-map.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function withInlineSourcemap(
2222
options: {
2323
root: string // project root path of this resource
2424
filepath: string
25+
noFirstLineMapping?: boolean
2526
},
2627
) {
2728
const map = result.map
@@ -63,7 +64,9 @@ export function withInlineSourcemap(
6364

6465
// If the first line is not present on source maps, add simple 1:1 mapping ([0,0,0,0], [1,0,0,0])
6566
// so that debuggers can be set to break on first line
66-
if (map.mappings.startsWith(';')) {
67+
// Since Vite 6, import statements at the top of the file are preserved correctly,
68+
// so we don't need to add this mapping anymore.
69+
if (!options.noFirstLineMapping && map.mappings.startsWith(';')) {
6770
map.mappings = `AAAA,CAAA${map.mappings}`
6871
}
6972

‎pnpm-lock.yaml

+148-365
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/coverage-test/test/vue.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ test('coverage results matches snapshot', async () => {
6767
expect({ lines, statements }).toMatchInlineSnapshot(`
6868
{
6969
"lines": {
70-
"covered": 36,
71-
"pct": 81.81,
70+
"covered": 35,
71+
"pct": 81.39,
7272
"skipped": 0,
73-
"total": 44,
73+
"total": 43,
7474
},
7575
"statements": {
76-
"covered": 36,
77-
"pct": 81.81,
76+
"covered": 35,
77+
"pct": 81.39,
7878
"skipped": 0,
79-
"total": 44,
79+
"total": 43,
8080
},
8181
}
8282
`)

0 commit comments

Comments
 (0)
Please sign in to comment.