Skip to content

Commit 4c6028d

Browse files
committed
fix: fix module runner sourcemap
1 parent 0ac290f commit 4c6028d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/vite/src/node/server/environments/rolldown.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ class RolldownEnvironment extends DevEnvironment {
267267
if (this.name === 'client') {
268268
ctx.server.ws.send('rolldown:hmr', result)
269269
} else {
270-
this.getRunner().evaluate(result[1].toString())
270+
this.getRunner().evaluate(
271+
result[1].toString(),
272+
path.join(this.outDir, result[0]),
273+
)
271274
}
272275
console.timeEnd(`[rolldown:${this.name}:hmr]`)
273276
} else {
@@ -286,7 +289,7 @@ class RolldownEnvironment extends DevEnvironment {
286289
const filepath = path.join(this.outDir, output.fileName)
287290
this.runner = new RolldownModuleRunner()
288291
const code = fs.readFileSync(filepath, 'utf-8')
289-
this.runner.evaluate(code)
292+
this.runner.evaluate(code, filepath)
290293
}
291294
return this.runner
292295
}
@@ -323,13 +326,12 @@ class RolldownModuleRunner {
323326
return mod.exports
324327
}
325328

326-
evaluate(code: string) {
329+
evaluate(code: string, sourceURL: string) {
327330
const context = {
328331
self: this.context,
329332
...this.context,
330333
}
331-
// TODO: sourcemap not working?
332-
// extract sourcemap
334+
// extract sourcemap and move to the bottom
333335
const sourcemap = code.match(/^\/\/# sourceMappingURL=.*/m)?.[0] ?? ''
334336
if (sourcemap) {
335337
code = code.replace(sourcemap, '')
@@ -341,6 +343,7 @@ self.__toCommonJS = __toCommonJS;
341343
self.__export = __export;
342344
self.__toESM = __toESM;
343345
}}
346+
//# sourceURL=${sourceURL}
344347
//# sourceMappingSource=rolldown-module-runner
345348
${sourcemap}
346349
`

playground/rolldown-dev-ssr/src/entry-server.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const handler: Connect.SimpleHandleFunction = (req, res) => {
77
const url = new URL(req.url ?? '/', 'https://vite.dev')
88
console.log(`[SSR] ${req.method} ${url.pathname}`)
99
if (url.pathname === '/crash-ssr') {
10-
// TODO: source map and stacktrace
1110
throwError()
1211
}
1312
const ssrHtml = ReactDOMServer.renderToString(<App />)

0 commit comments

Comments
 (0)