Add --sourcemap-sources-root to RN packager
Reviewed By: davidaurelio Differential Revision: D4357122 fbshipit-source-id: dc19474aa54ea4684a6b1c586a9d1e5da0980327
This commit is contained in:
parent
482c73de86
commit
da59258372
|
@ -34,6 +34,9 @@ module.exports = [
|
|||
}, {
|
||||
command: '--sourcemap-output [string]',
|
||||
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
|
||||
}, {
|
||||
command: '--sourcemap-sources-root [string]',
|
||||
description: 'Path to make sourcemap\'s sources entries relative to, ex. /root/dir',
|
||||
}, {
|
||||
command: '--assets-dest [string]',
|
||||
description: 'Directory name where to store assets referenced in the bundle',
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
'use strict';
|
||||
|
||||
const meta = require('./meta');
|
||||
const relativizeSourceMap = require('../../../packager/react-packager/src/lib/relativizeSourceMap');
|
||||
const writeFile = require('./writeFile');
|
||||
|
||||
import type Bundle from '../../../packager/react-packager/src/Bundler/Bundle';
|
||||
|
@ -24,10 +25,11 @@ function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {
|
|||
});
|
||||
}
|
||||
|
||||
function createCodeWithMap(bundle: Bundle, dev: boolean): * {
|
||||
function createCodeWithMap(bundle: Bundle, dev: boolean, sourceMapSourcesRoot?: string): * {
|
||||
const sourceMap = relativizeSourceMap(bundle.getSourceMap({dev}), sourceMapSourcesRoot);
|
||||
return {
|
||||
code: bundle.getSource({dev}),
|
||||
map: JSON.stringify(bundle.getSourceMap({dev})),
|
||||
map: JSON.stringify(sourceMap),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -40,11 +42,12 @@ function saveBundleAndMap(
|
|||
bundleOutput,
|
||||
bundleEncoding: encoding,
|
||||
dev,
|
||||
sourcemapOutput
|
||||
sourcemapOutput,
|
||||
sourcemapSourcesRoot
|
||||
} = options;
|
||||
|
||||
log('start');
|
||||
const codeWithMap = createCodeWithMap(bundle, !!dev);
|
||||
const codeWithMap = createCodeWithMap(bundle, !!dev, sourcemapSourcesRoot);
|
||||
log('finish');
|
||||
|
||||
log('Writing bundle output to:', bundleOutput);
|
||||
|
|
|
@ -15,6 +15,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('../../../../packager/react-packager/src/lib/relativizeSourceMap');
|
||||
const writeFile = require('../writeFile');
|
||||
const writeSourceMap = require('./write-sourcemap');
|
||||
|
||||
|
@ -42,7 +43,8 @@ function saveAsAssets(
|
|||
const {
|
||||
bundleOutput,
|
||||
bundleEncoding: encoding,
|
||||
sourcemapOutput
|
||||
sourcemapOutput,
|
||||
sourcemapSourcesRoot,
|
||||
} = options;
|
||||
|
||||
log('start');
|
||||
|
@ -63,10 +65,14 @@ function saveAsAssets(
|
|||
writeUnbundle.then(() => log('Done writing unbundle output'));
|
||||
|
||||
const sourceMap =
|
||||
buildSourceMapWithMetaData({
|
||||
startupModules: startupModules.concat(),
|
||||
lazyModules: lazyModules.concat(),
|
||||
});
|
||||
relativizeSourceMap(
|
||||
buildSourceMapWithMetaData({
|
||||
startupModules: startupModules.concat(),
|
||||
lazyModules: lazyModules.concat(),
|
||||
}),
|
||||
sourcemapSourcesRoot
|
||||
);
|
||||
|
||||
|
||||
return Promise.all([
|
||||
writeUnbundle,
|
||||
|
|
|
@ -14,6 +14,7 @@ const MAGIC_UNBUNDLE_FILE_HEADER = require('./magic-number');
|
|||
|
||||
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
|
||||
const fs = require('fs');
|
||||
const relativizeSourceMap = require('../../../../packager/react-packager/src/lib/relativizeSourceMap');
|
||||
const writeSourceMap = require('./write-sourcemap');
|
||||
|
||||
const {joinModules} = require('./util');
|
||||
|
@ -39,6 +40,7 @@ function saveAsIndexedFile(
|
|||
bundleOutput,
|
||||
bundleEncoding: encoding,
|
||||
sourcemapOutput,
|
||||
sourcemapSourcesRoot,
|
||||
} = options;
|
||||
|
||||
log('start');
|
||||
|
@ -55,11 +57,14 @@ function saveAsIndexedFile(
|
|||
).then(() => log('Done writing unbundle output'));
|
||||
|
||||
const sourceMap =
|
||||
buildSourceMapWithMetaData({
|
||||
startupModules: startupModules.concat(),
|
||||
lazyModules: lazyModules.concat(),
|
||||
moduleGroups,
|
||||
});
|
||||
relativizeSourceMap(
|
||||
buildSourceMapWithMetaData({
|
||||
startupModules: startupModules.concat(),
|
||||
lazyModules: lazyModules.concat(),
|
||||
moduleGroups,
|
||||
}),
|
||||
sourcemapSourcesRoot
|
||||
);
|
||||
|
||||
return Promise.all([
|
||||
writeUnbundle,
|
||||
|
|
|
@ -36,6 +36,7 @@ export type OutputOptions = {
|
|||
dev?: boolean,
|
||||
platform: string,
|
||||
sourcemapOutput?: string,
|
||||
sourcemapSourcesRoot?: string,
|
||||
};
|
||||
|
||||
export type RequestOptions = {|
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
import type { MixedSourceMap } from './SourceMap';
|
||||
|
||||
function relativizeSourceMapInternal(sourceMap: any, sourcesRoot: string) {
|
||||
if (sourceMap.sections) {
|
||||
for (var i = 0; i < sourceMap.sections.length; i++) {
|
||||
relativizeSourceMapInternal(sourceMap.sections[i].map, sourcesRoot);
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < sourceMap.sources.length; i++) {
|
||||
sourceMap.sources[i] = path.relative(sourcesRoot, sourceMap.sources[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function relativizeSourceMap(sourceMap: MixedSourceMap, sourcesRoot?: string): MixedSourceMap {
|
||||
if (!sourcesRoot) {
|
||||
return sourceMap;
|
||||
}
|
||||
relativizeSourceMapInternal(sourceMap, sourcesRoot);
|
||||
return sourceMap;
|
||||
}
|
||||
|
||||
module.exports = relativizeSourceMap;
|
Loading…
Reference in New Issue