mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Resolve source map URL/path relative to the script
This commit is contained in:
@@ -41,24 +41,11 @@ describe('parseHookNames', () => {
|
|||||||
// has a recursion breaker which falls back to the default behavior.
|
// has a recursion breaker which falls back to the default behavior.
|
||||||
Error.prepareStackTrace = (error, trace) => {
|
Error.prepareStackTrace = (error, trace) => {
|
||||||
return error.stack;
|
return error.stack;
|
||||||
}
|
};
|
||||||
|
|
||||||
fetchMock.mockIf(/.+$/, request => {
|
fetchMock.mockIf(/.+$/, request => {
|
||||||
const {resolve} = require('path');
|
const {resolve} = require('path');
|
||||||
const url = request.url;
|
return Promise.resolve(requireText(request.url, 'utf8'));
|
||||||
if (url.endsWith('js.map')) {
|
|
||||||
// Source maps are relative URLs (e.g. "path/to/Exmaple.js" specifies "Exmaple.js.map").
|
|
||||||
const sourceMapURL = resolve(
|
|
||||||
__dirname,
|
|
||||||
'__source__',
|
|
||||||
'__compiled__',
|
|
||||||
'external',
|
|
||||||
url,
|
|
||||||
);
|
|
||||||
return Promise.resolve(requireText(sourceMapURL, 'utf8'));
|
|
||||||
} else {
|
|
||||||
return Promise.resolve(requireText(url, 'utf8'));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mock out portion of browser API used by parseHookNames to initialize "source-map".
|
// Mock out portion of browser API used by parseHookNames to initialize "source-map".
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ function extractAndLoadSourceMaps(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let i = 0; i < sourceMappingURLs.length; i++) {
|
for (let i = 0; i < sourceMappingURLs.length; i++) {
|
||||||
|
const fileName = ((hookSourceData.hookSource.fileName: any): string);
|
||||||
const sourceMappingURL = sourceMappingURLs[i];
|
const sourceMappingURL = sourceMappingURLs[i];
|
||||||
const index = sourceMappingURL.indexOf('base64,');
|
const index = sourceMappingURL.indexOf('base64,');
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
@@ -211,7 +212,6 @@ function extractAndLoadSourceMaps(
|
|||||||
|
|
||||||
// Hook source might be a URL like "https://4syus.csb.app/src/App.js"
|
// Hook source might be a URL like "https://4syus.csb.app/src/App.js"
|
||||||
// Parsed source map might be a partial path like "src/App.js"
|
// Parsed source map might be a partial path like "src/App.js"
|
||||||
const fileName = ((hookSourceData.hookSource.fileName: any): string);
|
|
||||||
const match = parsed.sources.find(
|
const match = parsed.sources.find(
|
||||||
source =>
|
source =>
|
||||||
source === 'Inline Babel script' || fileName.includes(source),
|
source === 'Inline Babel script' || fileName.includes(source),
|
||||||
@@ -235,6 +235,13 @@ function extractAndLoadSourceMaps(
|
|||||||
if (!isValidUrl(url)) {
|
if (!isValidUrl(url)) {
|
||||||
throw new Error(`Invalid source map URL "${url}"`);
|
throw new Error(`Invalid source map URL "${url}"`);
|
||||||
}
|
}
|
||||||
|
} else if (!url.startsWith('/')) {
|
||||||
|
// Resolve paths relative to the location of the file name
|
||||||
|
const lastSlashIdx = fileName.lastIndexOf('/');
|
||||||
|
if (lastSlashIdx !== -1) {
|
||||||
|
const baseURL = fileName.slice(0, fileName.lastIndexOf('/'));
|
||||||
|
url = `${baseURL}/${url}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hookSourceData.sourceMapURL = url;
|
hookSourceData.sourceMapURL = url;
|
||||||
|
|||||||
Reference in New Issue
Block a user