Files
react-native-devtools-frontend/node_modules/rollup-plugin-sourcemaps/dist/index.cjs
T
Simon Zünd 1bd98ee250 [deps] Add 'rollup-plugin-sourcemaps' intended for release builds
We plan to enable source maps for release builds behind a GN flag. For
this to work rollup needs to consume the source maps already generated
by tsc and merge it with its own source map. Rollup can't do this
natively so this CL adds a plugin that can.

R=jacktfranklin@chromium.org

Bug: 1430396
Change-Id: Ibb38c7892326907431e54b7c7dbd7b912b59ccb9
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4397707
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
2023-04-04 13:31:33 +00:00

61 lines
2.1 KiB
JavaScript

'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var fs = _interopDefault(require('fs'));
var util = _interopDefault(require('util'));
var pluginutils = require('@rollup/pluginutils');
var sourceMapResolve = require('source-map-resolve');
const promisifiedResolveSourceMap = util.promisify(sourceMapResolve.resolveSourceMap);
const promisifiedResolveSources = util.promisify(sourceMapResolve.resolveSources);
function sourcemaps({ include, exclude, readFile = fs.readFile, } = {}) {
const filter = pluginutils.createFilter(include, exclude);
const promisifiedReadFile = util.promisify(readFile);
return {
name: 'sourcemaps',
async load(id) {
if (!filter(id)) {
return null;
}
let code;
try {
code = (await promisifiedReadFile(id)).toString();
}
catch (_a) {
// Failed reading file, let the next plugin deal with it
return null;
}
let map;
try {
const result = await promisifiedResolveSourceMap(code, id, readFile);
// The code contained no sourceMappingURL,
if (result === null) {
return code;
}
map = result.map;
}
catch (_b) {
// Failed resolving source map, just return the source
return code;
}
// Resolve sources if they're not included
if (map.sourcesContent === undefined) {
try {
const { sourcesContent } = await promisifiedResolveSources(map, id, readFile);
if (sourcesContent.every(util.isString)) {
map.sourcesContent = sourcesContent;
}
}
catch (_c) {
// Ignore
}
}
return { code, map };
},
};
}
module.exports = sourcemaps;
//# sourceMappingURL=index.cjs.map