mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 21:24:26 +08:00
Since we have the major version jump, we needed to update quite
a few things to make this work:
1. rollup4 ships with native binaries. We can't check them into
our node_modules for all platforms. Luckily they also ship a
a wasm version. This requires us to adjust the 'binary' path
to `node_modules/@rollup/wasm-node/dist/bin/rollup` instead.
2. rollup4 is more strict when it comes to ES modules vs
CommonJS. We adjust this by renaming the rollup config files.
3. Some plugins got deprecated so we had to replace them with
the newer versions (source maps and terser).
Bug: None
Change-Id: If13d590c8185db6ad85b3992d0a869111909dc8c
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5999255
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
import * as urlLib from 'node:url';
|
|
import decodeUriComponent from './decode-uri-component.js';
|
|
|
|
function resolveUrl(...args) {
|
|
return args.reduce((resolved, nextUrl)=>urlLib.resolve(resolved, nextUrl), '');
|
|
}
|
|
function customDecodeUriComponent(encodedURI) {
|
|
return decodeUriComponent(encodedURI.replace(/\+/g, '%2B'));
|
|
}
|
|
function parseMapToJSON(string) {
|
|
return JSON.parse(string.replace(/^\)\]\}'/, ''));
|
|
}
|
|
const sourceMappingURLRegex = /(?:\/\*(?:\s*\r?\n(?:\/\/)?)?(?:[#@] sourceMappingURL=([^\s'"]*))\s*\*\/|\/\/(?:[#@] sourceMappingURL=([^\s'"]*)))\s*/;
|
|
function getSourceMappingUrl(code) {
|
|
const match = sourceMappingURLRegex.exec(code);
|
|
return match ? match[1] || match[2] || '' : null;
|
|
}
|
|
async function resolveSourceMap(code, codeUrl, read) {
|
|
const sourceMappingURL = getSourceMappingUrl(code);
|
|
if (!sourceMappingURL) {
|
|
return null;
|
|
}
|
|
const dataUri = /^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/.exec(sourceMappingURL);
|
|
if (dataUri) {
|
|
const mimeType = dataUri[1] || 'text/plain';
|
|
if (!/^(?:application|text)\/json$/.test(mimeType)) {
|
|
throw new Error(`Unuseful data uri mime type: ${mimeType}`);
|
|
}
|
|
const map = parseMapToJSON((dataUri[2] === ';base64' ? atob : decodeURIComponent)(dataUri[3] || ''));
|
|
return {
|
|
sourceMappingURL,
|
|
url: null,
|
|
sourcesRelativeTo: codeUrl,
|
|
map
|
|
};
|
|
}
|
|
const url = resolveUrl(codeUrl, sourceMappingURL);
|
|
const map = parseMapToJSON(String(await read(customDecodeUriComponent(url))));
|
|
return {
|
|
sourceMappingURL,
|
|
url,
|
|
sourcesRelativeTo: url,
|
|
map
|
|
};
|
|
}
|
|
async function resolveSources(map, mapUrl, read) {
|
|
const sourcesResolved = [];
|
|
const sourcesContent = [];
|
|
for(let index = 0, len = map.sources.length; index < len; index++){
|
|
const sourceRoot = map.sourceRoot;
|
|
const sourceContent = (map.sourcesContent || [])[index];
|
|
const resolvePaths = [
|
|
mapUrl,
|
|
map.sources[index]
|
|
];
|
|
if (sourceRoot !== undefined && sourceRoot !== '') {
|
|
resolvePaths.splice(1, 0, sourceRoot.replace(/\/?$/, '/'));
|
|
}
|
|
sourcesResolved[index] = resolveUrl(...resolvePaths);
|
|
if (typeof sourceContent === 'string') {
|
|
sourcesContent[index] = sourceContent;
|
|
continue;
|
|
}
|
|
try {
|
|
const source = await read(customDecodeUriComponent(sourcesResolved[index]));
|
|
sourcesContent[index] = String(source);
|
|
} catch (error) {
|
|
sourcesContent[index] = error;
|
|
}
|
|
}
|
|
return {
|
|
sourcesResolved,
|
|
sourcesContent
|
|
};
|
|
}
|
|
|
|
export { resolveSourceMap, resolveSources };
|
|
//# sourceMappingURL=source-map-resolve.js.map
|