File tree 2 files changed +10
-16
lines changed
packages/react-devtools-extensions/src
2 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -41,24 +41,11 @@ describe('parseHookNames', () => {
41
41
// has a recursion breaker which falls back to the default behavior.
42
42
Error . prepareStackTrace = ( error , trace ) => {
43
43
return error . stack ;
44
- }
44
+ } ;
45
45
46
46
fetchMock . mockIf ( / .+ $ / , request => {
47
47
const { resolve} = require ( 'path' ) ;
48
- const url = request . url ;
49
- if ( url . endsWith ( 'js.map' ) ) {
50
- // Source maps are relative URLs (e.g. "path/to/Exmaple.js" specifies "Exmaple.js.map").
51
- const sourceMapURL = resolve (
52
- __dirname ,
53
- '__source__' ,
54
- '__compiled__' ,
55
- 'external' ,
56
- url ,
57
- ) ;
58
- return Promise . resolve ( requireText ( sourceMapURL , 'utf8' ) ) ;
59
- } else {
60
- return Promise . resolve ( requireText ( url , 'utf8' ) ) ;
61
- }
48
+ return Promise . resolve ( requireText ( request . url , 'utf8' ) ) ;
62
49
} ) ;
63
50
64
51
// Mock out portion of browser API used by parseHookNames to initialize "source-map".
Original file line number Diff line number Diff line change @@ -189,6 +189,7 @@ function extractAndLoadSourceMaps(
189
189
}
190
190
} else {
191
191
for ( let i = 0 ; i < sourceMappingURLs . length ; i ++ ) {
192
+ const fileName = ( ( hookSourceData . hookSource . fileName : any ) : string ) ;
192
193
const sourceMappingURL = sourceMappingURLs [ i ] ;
193
194
const index = sourceMappingURL . indexOf ( 'base64,' ) ;
194
195
if ( index >= 0 ) {
@@ -211,7 +212,6 @@ function extractAndLoadSourceMaps(
211
212
212
213
// Hook source might be a URL like "https://4syus.csb.app/src/App.js"
213
214
// Parsed source map might be a partial path like "src/App.js"
214
- const fileName = ( ( hookSourceData . hookSource . fileName : any ) : string ) ;
215
215
const match = parsed . sources . find (
216
216
source =>
217
217
source === 'Inline Babel script' || fileName . includes ( source ) ,
@@ -235,6 +235,13 @@ function extractAndLoadSourceMaps(
235
235
if ( ! isValidUrl ( url ) ) {
236
236
throw new Error ( `Invalid source map URL "${ url } "` ) ;
237
237
}
238
+ } else if ( ! url . startsWith ( '/' ) ) {
239
+ // Resolve paths relative to the location of the file name
240
+ const lastSlashIdx = fileName . lastIndexOf ( '/' ) ;
241
+ if ( lastSlashIdx !== - 1 ) {
242
+ const baseURL = fileName . slice ( 0 , fileName . lastIndexOf ( '/' ) ) ;
243
+ url = `${ baseURL } /${ url } ` ;
244
+ }
238
245
}
239
246
240
247
hookSourceData . sourceMapURL = url ;
You can’t perform that action at this time.
0 commit comments