Skip to content

Commit b997355

Browse files
authored
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy