-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ssr sourcemap + stacktrace fix
- Loading branch information
Showing
5 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { SourceMapConsumer, RawSourceMap } from 'source-map' | ||
import { ModuleGraph } from './moduleGraph' | ||
|
||
export function ssrRewriteStacktrace(stack: string, moduleGraph: ModuleGraph) { | ||
return stack | ||
.split('\n') | ||
.map((line) => { | ||
return line.replace( | ||
/^ {4}at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?)\)?/, | ||
(input, varName, url, line, column) => { | ||
if (!url) return input | ||
|
||
const mod = moduleGraph.urlToModuleMap.get(url) | ||
const rawSourceMap = mod?.ssrTransformResult?.map | ||
|
||
if (!rawSourceMap) { | ||
return input | ||
} | ||
|
||
const consumer = new SourceMapConsumer( | ||
(rawSourceMap as any) as RawSourceMap | ||
) | ||
|
||
const pos = consumer.originalPositionFor({ | ||
// source map lines generated via new Function() in Node.js is always | ||
// incremented by 2 - no idea why | ||
line: Number(line) - 2, | ||
column: Number(column), | ||
bias: SourceMapConsumer.LEAST_UPPER_BOUND | ||
}) | ||
|
||
if (!pos.source) { | ||
return input | ||
} | ||
|
||
const source = `${pos.source}:${pos.line || 0}:${pos.column || 0}` | ||
if (!varName || varName === 'eval') { | ||
return ` at ${source}` | ||
} else { | ||
return ` at ${varName} (${source})` | ||
} | ||
} | ||
) | ||
}) | ||
.join('\n') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters