Skip to content

Commit

Permalink
refactor: use ssr environment module graph in ssrFixStacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 28, 2024
1 parent 96e825a commit 5477972
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@ export async function _createServer(
)
},
ssrFixStacktrace(e) {
ssrFixStacktrace(e, server.moduleGraph)
ssrFixStacktrace(e, server.environments.ssr.moduleGraph)
},
ssrRewriteStacktrace(stack: string) {
return ssrRewriteStacktrace(stack, server.moduleGraph)
return ssrRewriteStacktrace(stack, server.environments.ssr.moduleGraph)
},
async reloadModule(module) {
if (serverConfig.hmr !== false && module.file) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async function instantiateModule(
const errorData = importErrors.get(e)

if (e.stack && fixStacktrace) {
ssrFixStacktrace(e, server.moduleGraph)
ssrFixStacktrace(e, moduleGraph)
}

server.config.logger.error(
Expand Down
11 changes: 7 additions & 4 deletions packages/vite/src/node/ssr/ssrStacktrace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping'
import type { ModuleGraph } from '../server/mixedModuleGraph'
import type { EnvironmentModuleGraph } from '..'

let offset: number

Expand All @@ -22,7 +22,7 @@ function calculateOffsetOnce() {

export function ssrRewriteStacktrace(
stack: string,
moduleGraph: ModuleGraph,
moduleGraph: EnvironmentModuleGraph,
): string {
calculateOffsetOnce()
return stack
Expand All @@ -34,7 +34,7 @@ export function ssrRewriteStacktrace(
if (!id) return input

const mod = moduleGraph.getModuleById(id)
const rawSourceMap = mod?.ssrTransformResult?.map
const rawSourceMap = mod?.transformResult?.map

if (!rawSourceMap) {
return input
Expand Down Expand Up @@ -86,7 +86,10 @@ export function rebindErrorStacktrace(e: Error, stacktrace: string): void {

const rewroteStacktraces = new WeakSet()

export function ssrFixStacktrace(e: Error, moduleGraph: ModuleGraph): void {
export function ssrFixStacktrace(
e: Error,
moduleGraph: EnvironmentModuleGraph,
): void {
if (!e.stack) return
// stacktrace shouldn't be rewritten more than once
if (rewroteStacktraces.has(e)) return
Expand Down

0 comments on commit 5477972

Please sign in to comment.