Skip to content

Commit

Permalink
fix(vite-node): remove fake first line mapping on Vite 6 (#7124)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 5, 2025
1 parent 9542b69 commit b997355
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 373 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"tinyglobby": "^0.2.10",
"tsx": "^4.19.2",
"typescript": "^5.7.3",
"vite": "^5.4.0",
"vite": "^6.0.11",
"vitest": "workspace:*",
"zx": "^8.3.0"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/vite-node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { performance } from 'node:perf_hooks'
import { pathToFileURL } from 'node:url'
import createDebug from 'debug'
import { join, normalize, relative, resolve } from 'pathe'
import { version as viteVersion } from 'vite'
import { Debugger } from './debug'
import { shouldExternalize } from './externalize'
import { withInlineSourcemap } from './source-map'
Expand Down Expand Up @@ -392,6 +393,7 @@ export class ViteNodeServer {
return withInlineSourcemap(result, {
filepath: mod?.file || filepath,
root: this.server.config.root,
noFirstLineMapping: Number(viteVersion.split('.')[0]) >= 6,
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/vite-node/src/source-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function withInlineSourcemap(
options: {
root: string // project root path of this resource
filepath: string
noFirstLineMapping?: boolean
},
) {
const map = result.map
Expand Down Expand Up @@ -63,7 +64,9 @@ export function withInlineSourcemap(

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

Expand Down
Loading

0 comments on commit b997355

Please sign in to comment.