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 { ...@@ -21,8 +21,7 @@ import {
devirtualizeReactServerURL, devirtualizeReactServerURL,
findApplicableSourceMapPayload, findApplicableSourceMapPayload,
} from '../lib/source-maps' } from '../lib/source-maps'
import { getSourceMapFromFile } from './get-source-map-from-file' import { findSourceMap, type SourceMap } from 'node:module'
import { findSourceMap } from 'node:module'
import { fileURLToPath, pathToFileURL } from 'node:url' import { fileURLToPath, pathToFileURL } from 'node:url'
import { inspect } from 'node:util' import { inspect } from 'node:util'
...@@ -419,19 +418,22 @@ export function getSourceMapMiddleware(project: Project) { ...@@ -419,19 +418,22 @@ export function getSourceMapMiddleware(project: Project) {
return middlewareResponse.badRequest(res) return middlewareResponse.badRequest(res)
} }
// TODO(veil): Always try the native version first. let nativeSourceMap: SourceMap | undefined
// Externals could also be files that aren't bundled via Webpack. try {
if ( nativeSourceMap = findSourceMap(filename)
filename.startsWith('webpack://') || } catch (cause) {
filename.startsWith('webpack-internal:///') return middlewareResponse.internalServerError(
) { res,
const sourceMap = findSourceMap(filename) new Error(
`${filename}: Invalid source map. Only conformant source maps can be used to find the original code.`,
if (sourceMap) { { cause }
return middlewareResponse.json(res, sourceMap.payload) )
)
} }
return middlewareResponse.noContent(res) if (nativeSourceMap !== undefined) {
const sourceMapPayload = nativeSourceMap.payload
return middlewareResponse.json(res, sourceMapPayload)
} }
try { try {
...@@ -451,14 +453,6 @@ export function getSourceMapMiddleware(project: Project) { ...@@ -451,14 +453,6 @@ export function getSourceMapMiddleware(project: Project) {
if (sourceMapString) { if (sourceMapString) {
return middlewareResponse.jsonString(res, sourceMapString) return middlewareResponse.jsonString(res, sourceMapString)
} }
if (filename.startsWith('file:')) {
const sourceMap = await getSourceMapFromFile(filename)
if (sourceMap) {
return middlewareResponse.json(res, sourceMap)
}
}
} catch (cause) { } catch (cause) {
return middlewareResponse.internalServerError( return middlewareResponse.internalServerError(
res, 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