Unverified Commit 907501e8 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[sourcemaps] Try VM for retrieving source maps first (#81869)

parent c8c9bef3
......@@ -21,8 +21,7 @@ import {
devirtualizeReactServerURL,
findApplicableSourceMapPayload,
} from '../lib/source-maps'
import { getSourceMapFromFile } from './get-source-map-from-file'
import { findSourceMap } from 'node:module'
import { findSourceMap, type SourceMap } from 'node:module'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { inspect } from 'node:util'
......@@ -419,19 +418,22 @@ export function getSourceMapMiddleware(project: Project) {
return middlewareResponse.badRequest(res)
}
// TODO(veil): Always try the native version first.
// Externals could also be files that aren't bundled via Webpack.
if (
filename.startsWith('webpack://') ||
filename.startsWith('webpack-internal:///')
) {
const sourceMap = findSourceMap(filename)
if (sourceMap) {
return middlewareResponse.json(res, sourceMap.payload)
}
let nativeSourceMap: SourceMap | undefined
try {
nativeSourceMap = findSourceMap(filename)
} catch (cause) {
return middlewareResponse.internalServerError(
res,
new Error(
`${filename}: Invalid source map. Only conformant source maps can be used to find the original code.`,
{ cause }
)
)
}
return middlewareResponse.noContent(res)
if (nativeSourceMap !== undefined) {
const sourceMapPayload = nativeSourceMap.payload
return middlewareResponse.json(res, sourceMapPayload)
}
try {
......@@ -451,14 +453,6 @@ export function getSourceMapMiddleware(project: Project) {
if (sourceMapString) {
return middlewareResponse.jsonString(res, sourceMapString)
}
if (filename.startsWith('file:')) {
const sourceMap = await getSourceMapFromFile(filename)
if (sourceMap) {
return middlewareResponse.json(res, sourceMap)
}
}
} catch (cause) {
return middlewareResponse.internalServerError(
res,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment