Skip to content

Commit

Permalink
fix: fix module runner sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 21, 2024
1 parent 0ac290f commit 4c6028d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ class RolldownEnvironment extends DevEnvironment {
if (this.name === 'client') {
ctx.server.ws.send('rolldown:hmr', result)
} else {
this.getRunner().evaluate(result[1].toString())
this.getRunner().evaluate(
result[1].toString(),
path.join(this.outDir, result[0]),
)
}
console.timeEnd(`[rolldown:${this.name}:hmr]`)
} else {
Expand All @@ -286,7 +289,7 @@ class RolldownEnvironment extends DevEnvironment {
const filepath = path.join(this.outDir, output.fileName)
this.runner = new RolldownModuleRunner()
const code = fs.readFileSync(filepath, 'utf-8')
this.runner.evaluate(code)
this.runner.evaluate(code, filepath)
}
return this.runner
}
Expand Down Expand Up @@ -323,13 +326,12 @@ class RolldownModuleRunner {
return mod.exports
}

evaluate(code: string) {
evaluate(code: string, sourceURL: string) {
const context = {
self: this.context,
...this.context,
}
// TODO: sourcemap not working?
// extract sourcemap
// extract sourcemap and move to the bottom
const sourcemap = code.match(/^\/\/# sourceMappingURL=.*/m)?.[0] ?? ''
if (sourcemap) {
code = code.replace(sourcemap, '')
Expand All @@ -341,6 +343,7 @@ self.__toCommonJS = __toCommonJS;
self.__export = __export;
self.__toESM = __toESM;
}}
//# sourceURL=${sourceURL}
//# sourceMappingSource=rolldown-module-runner
${sourcemap}
`
Expand Down
1 change: 0 additions & 1 deletion playground/rolldown-dev-ssr/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const handler: Connect.SimpleHandleFunction = (req, res) => {
const url = new URL(req.url ?? '/', 'https://vite.dev')
console.log(`[SSR] ${req.method} ${url.pathname}`)
if (url.pathname === '/crash-ssr') {
// TODO: source map and stacktrace
throwError()
}
const ssrHtml = ReactDOMServer.renderToString(<App />)
Expand Down

0 comments on commit 4c6028d

Please sign in to comment.