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';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
|
|
||||||
function relativizeSourceMapInternal(
|
function relativizeSourceMapInline(
|
||||||
sourceMap: MetroSourceMap,
|
sourceMap: MetroSourceMap,
|
||||||
sourcesRoot: string,
|
sourcesRoot: string,
|
||||||
) {
|
) {
|
||||||
if (sourceMap.mappings === undefined) {
|
if (sourceMap.mappings === undefined) {
|
||||||
for (let i = 0; i < sourceMap.sections.length; i++) {
|
for (let i = 0; i < sourceMap.sections.length; i++) {
|
||||||
relativizeSourceMapInternal(sourceMap.sections[i].map, sourcesRoot);
|
relativizeSourceMapInline(sourceMap.sections[i].map, sourcesRoot);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let i = 0; i < sourceMap.sources.length; i++) {
|
for (let i = 0; i < sourceMap.sources.length; i++) {
|
||||||
|
@ -31,15 +31,4 @@ function relativizeSourceMapInternal(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativizeSourceMap(
|
module.exports = relativizeSourceMapInline;
|
||||||
sourceMap: MetroSourceMap,
|
|
||||||
sourcesRoot?: string,
|
|
||||||
): MetroSourceMap {
|
|
||||||
if (!sourcesRoot) {
|
|
||||||
return sourceMap;
|
|
||||||
}
|
|
||||||
relativizeSourceMapInternal(sourceMap, sourcesRoot);
|
|
||||||
return sourceMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = relativizeSourceMap;
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
const Server = require('../../Server');
|
const Server = require('../../Server');
|
||||||
|
|
||||||
const meta = require('./meta');
|
const meta = require('./meta');
|
||||||
const relativizeSourceMap = require('../../lib/relativizeSourceMap');
|
const relativizeSourceMapInline = require('../../lib/relativizeSourceMap');
|
||||||
const writeFile = require('./writeFile');
|
const writeFile = require('./writeFile');
|
||||||
|
|
||||||
import type {OutputOptions, RequestOptions} from '../types.flow';
|
import type {OutputOptions, RequestOptions} from '../types.flow';
|
||||||
|
@ -33,11 +33,12 @@ function buildBundle(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCodeWithMap(map: string, sourceMapSourcesRoot: string): string {
|
function relativateSerializedMap(
|
||||||
const sourceMap = relativizeSourceMap(
|
map: string,
|
||||||
(JSON.parse(map): MetroSourceMap),
|
sourceMapSourcesRoot: string,
|
||||||
sourceMapSourcesRoot,
|
): string {
|
||||||
);
|
const sourceMap = (JSON.parse(map): MetroSourceMap);
|
||||||
|
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
||||||
return JSON.stringify(sourceMap);
|
return JSON.stringify(sourceMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ function saveBundleAndMap(
|
||||||
let {map} = bundle;
|
let {map} = bundle;
|
||||||
if (sourcemapSourcesRoot !== undefined) {
|
if (sourcemapSourcesRoot !== undefined) {
|
||||||
log('start relativating source map');
|
log('start relativating source map');
|
||||||
map = createCodeWithMap(map, sourcemapSourcesRoot);
|
map = relativateSerializedMap(map, sourcemapSourcesRoot);
|
||||||
log('finished relativating');
|
log('finished relativating');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ const MAGIC_UNBUNDLE_NUMBER = require('./magic-number');
|
||||||
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
||||||
const mkdirp = require('mkdirp');
|
const mkdirp = require('mkdirp');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const relativizeSourceMap = require('../../../lib/relativizeSourceMap');
|
const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
|
||||||
const writeFile = require('../writeFile');
|
const writeFile = require('../writeFile');
|
||||||
const writeSourceMap = require('./write-sourcemap');
|
const writeSourceMap = require('./write-sourcemap');
|
||||||
|
|
||||||
|
@ -66,15 +66,15 @@ function saveAsAssets(
|
||||||
);
|
);
|
||||||
writeUnbundle.then(() => log('Done writing unbundle output'));
|
writeUnbundle.then(() => log('Done writing unbundle output'));
|
||||||
|
|
||||||
const sourceMap = relativizeSourceMap(
|
const sourceMap = buildSourceMapWithMetaData({
|
||||||
buildSourceMapWithMetaData({
|
fixWrapperOffset: true,
|
||||||
fixWrapperOffset: true,
|
lazyModules: lazyModules.concat(),
|
||||||
lazyModules: lazyModules.concat(),
|
moduleGroups: null,
|
||||||
moduleGroups: null,
|
startupModules: startupModules.concat(),
|
||||||
startupModules: startupModules.concat(),
|
});
|
||||||
}),
|
if (sourcemapSourcesRoot !== undefined) {
|
||||||
sourcemapSourcesRoot,
|
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
|
||||||
);
|
}
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
writeUnbundle,
|
writeUnbundle,
|
||||||
|
|
|
@ -15,7 +15,7 @@ const MAGIC_UNBUNDLE_FILE_HEADER = require('./magic-number');
|
||||||
|
|
||||||
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const relativizeSourceMap = require('../../../lib/relativizeSourceMap');
|
const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
|
||||||
const writeSourceMap = require('./write-sourcemap');
|
const writeSourceMap = require('./write-sourcemap');
|
||||||
|
|
||||||
const {joinModules} = require('./util');
|
const {joinModules} = require('./util');
|
||||||
|
@ -62,15 +62,15 @@ function saveAsIndexedFile(
|
||||||
).then(() => log('Done writing unbundle output'));
|
).then(() => log('Done writing unbundle output'));
|
||||||
|
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
const sourceMap = relativizeSourceMap(
|
const sourceMap = buildSourceMapWithMetaData({
|
||||||
buildSourceMapWithMetaData({
|
startupModules: startupModules.concat(),
|
||||||
startupModules: startupModules.concat(),
|
lazyModules: lazyModules.concat(),
|
||||||
lazyModules: lazyModules.concat(),
|
moduleGroups,
|
||||||
moduleGroups,
|
fixWrapperOffset: true,
|
||||||
fixWrapperOffset: true,
|
});
|
||||||
}),
|
if (sourcemapSourcesRoot !== undefined) {
|
||||||
sourcemapSourcesRoot,
|
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
|
||||||
);
|
}
|
||||||
|
|
||||||
const wroteSourceMap = writeSourceMap(
|
const wroteSourceMap = writeSourceMap(
|
||||||
sourcemapOutput,
|
sourcemapOutput,
|
||||||
|
|
Loading…
Reference in New Issue