mirror of https://github.com/status-im/metro.git
This function was working inline, reflect this clearly
Summary: This function was working on a source map object inline and then returning the same reference. For clarity it's better if it either clones the whole thing (that would be a waste) or not return the reference at all. Also renamed the function (but not the file) for clarity. Dropped the unused check and updated callsites instead. Reviewed By: mjesun Differential Revision: D6884241 fbshipit-source-id: 33aa7a1ad7096510903bbb74dd6b9c675b81aff5
This commit is contained in:
parent
63e8aebf79
commit
5e505980ec
|
@ -16,13 +16,13 @@ const path = require('path');
|
|||
|
||||
import type {MetroSourceMap} from 'metro-source-map';
|
||||
|
||||
function relativizeSourceMapInternal(
|
||||
function relativizeSourceMapInline(
|
||||
sourceMap: MetroSourceMap,
|
||||
sourcesRoot: string,
|
||||
) {
|
||||
if (sourceMap.mappings === undefined) {
|
||||
for (let i = 0; i < sourceMap.sections.length; i++) {
|
||||
relativizeSourceMapInternal(sourceMap.sections[i].map, sourcesRoot);
|
||||
relativizeSourceMapInline(sourceMap.sections[i].map, sourcesRoot);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < sourceMap.sources.length; i++) {
|
||||
|
@ -31,15 +31,4 @@ function relativizeSourceMapInternal(
|
|||
}
|
||||
}
|
||||
|
||||
function relativizeSourceMap(
|
||||
sourceMap: MetroSourceMap,
|
||||
sourcesRoot?: string,
|
||||
): MetroSourceMap {
|
||||
if (!sourcesRoot) {
|
||||
return sourceMap;
|
||||
}
|
||||
relativizeSourceMapInternal(sourceMap, sourcesRoot);
|
||||
return sourceMap;
|
||||
}
|
||||
|
||||
module.exports = relativizeSourceMap;
|
||||
module.exports = relativizeSourceMapInline;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
const Server = require('../../Server');
|
||||
|
||||
const meta = require('./meta');
|
||||
const relativizeSourceMap = require('../../lib/relativizeSourceMap');
|
||||
const relativizeSourceMapInline = require('../../lib/relativizeSourceMap');
|
||||
const writeFile = require('./writeFile');
|
||||
|
||||
import type {OutputOptions, RequestOptions} from '../types.flow';
|
||||
|
@ -33,11 +33,12 @@ function buildBundle(
|
|||
});
|
||||
}
|
||||
|
||||
function createCodeWithMap(map: string, sourceMapSourcesRoot: string): string {
|
||||
const sourceMap = relativizeSourceMap(
|
||||
(JSON.parse(map): MetroSourceMap),
|
||||
sourceMapSourcesRoot,
|
||||
);
|
||||
function relativateSerializedMap(
|
||||
map: string,
|
||||
sourceMapSourcesRoot: string,
|
||||
): string {
|
||||
const sourceMap = (JSON.parse(map): MetroSourceMap);
|
||||
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
||||
return JSON.stringify(sourceMap);
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ function saveBundleAndMap(
|
|||
let {map} = bundle;
|
||||
if (sourcemapSourcesRoot !== undefined) {
|
||||
log('start relativating source map');
|
||||
map = createCodeWithMap(map, sourcemapSourcesRoot);
|
||||
map = relativateSerializedMap(map, sourcemapSourcesRoot);
|
||||
log('finished relativating');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ const MAGIC_UNBUNDLE_NUMBER = require('./magic-number');
|
|||
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
||||
const mkdirp = require('mkdirp');
|
||||
const path = require('path');
|
||||
const relativizeSourceMap = require('../../../lib/relativizeSourceMap');
|
||||
const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
|
||||
const writeFile = require('../writeFile');
|
||||
const writeSourceMap = require('./write-sourcemap');
|
||||
|
||||
|
@ -66,15 +66,15 @@ function saveAsAssets(
|
|||
);
|
||||
writeUnbundle.then(() => log('Done writing unbundle output'));
|
||||
|
||||
const sourceMap = relativizeSourceMap(
|
||||
buildSourceMapWithMetaData({
|
||||
fixWrapperOffset: true,
|
||||
lazyModules: lazyModules.concat(),
|
||||
moduleGroups: null,
|
||||
startupModules: startupModules.concat(),
|
||||
}),
|
||||
sourcemapSourcesRoot,
|
||||
);
|
||||
const sourceMap = buildSourceMapWithMetaData({
|
||||
fixWrapperOffset: true,
|
||||
lazyModules: lazyModules.concat(),
|
||||
moduleGroups: null,
|
||||
startupModules: startupModules.concat(),
|
||||
});
|
||||
if (sourcemapSourcesRoot !== undefined) {
|
||||
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
writeUnbundle,
|
||||
|
|
|
@ -15,7 +15,7 @@ const MAGIC_UNBUNDLE_FILE_HEADER = require('./magic-number');
|
|||
|
||||
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
||||
const fs = require('fs');
|
||||
const relativizeSourceMap = require('../../../lib/relativizeSourceMap');
|
||||
const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
|
||||
const writeSourceMap = require('./write-sourcemap');
|
||||
|
||||
const {joinModules} = require('./util');
|
||||
|
@ -62,15 +62,15 @@ function saveAsIndexedFile(
|
|||
).then(() => log('Done writing unbundle output'));
|
||||
|
||||
if (sourcemapOutput) {
|
||||
const sourceMap = relativizeSourceMap(
|
||||
buildSourceMapWithMetaData({
|
||||
startupModules: startupModules.concat(),
|
||||
lazyModules: lazyModules.concat(),
|
||||
moduleGroups,
|
||||
fixWrapperOffset: true,
|
||||
}),
|
||||
sourcemapSourcesRoot,
|
||||
);
|
||||
const sourceMap = buildSourceMapWithMetaData({
|
||||
startupModules: startupModules.concat(),
|
||||
lazyModules: lazyModules.concat(),
|
||||
moduleGroups,
|
||||
fixWrapperOffset: true,
|
||||
});
|
||||
if (sourcemapSourcesRoot !== undefined) {
|
||||
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
|
||||
}
|
||||
|
||||
const wroteSourceMap = writeSourceMap(
|
||||
sourcemapOutput,
|
||||
|
|
Loading…
Reference in New Issue