Update shared/output modules to accept the output from the Delta Bundler

Reviewed By: davidaurelio

Differential Revision: D6186386

fbshipit-source-id: 6160f5a02891dbfb56c6350239703ace91e53690
This commit is contained in:
Rafael Oleza 2017-10-31 10:17:38 -07:00 committed by Facebook Github Bot
parent ff7ec2e6bf
commit cd67cd4794
7 changed files with 43 additions and 40 deletions

View File

@ -275,7 +275,7 @@ class DeltaTransformer extends EventEmitter {
.filter(module => dependencyEdges.has(module.path)) .filter(module => dependencyEdges.has(module.path))
.map(this._getModuleId) .map(this._getModuleId)
.map(moduleId => { .map(moduleId => {
const code = `;require(${JSON.stringify(moduleId)})`; const code = `require(${JSON.stringify(moduleId)});`;
const name = 'require-' + String(moduleId); const name = 'require-' + String(moduleId);
const path = name + '.js'; const path = name + '.js';
@ -388,7 +388,7 @@ class DeltaTransformer extends EventEmitter {
return [ return [
id, id,
{ {
code: ';' + code, code,
id, id,
map, map,
name, name,

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant * 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. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @format
* @flow * @flow
* @format * @format
*/ */
@ -18,12 +19,14 @@ const meta = require('./meta');
const relativizeSourceMap = require('../../lib/relativizeSourceMap'); const relativizeSourceMap = require('../../lib/relativizeSourceMap');
const writeFile = require('./writeFile'); const writeFile = require('./writeFile');
import type Bundle from '../../Bundler/Bundle';
import type {SourceMap} from '../../lib/SourceMap'; import type {SourceMap} from '../../lib/SourceMap';
import type {OutputOptions, RequestOptions} from '../types.flow'; import type {OutputOptions, RequestOptions} from '../types.flow';
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) { function buildBundle(
return packagerClient.buildBundle({ packagerClient: Server,
requestOptions: RequestOptions,
): Promise<{code: string, map: string}> {
return packagerClient.build({
...Server.DEFAULT_BUNDLE_OPTIONS, ...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions, ...requestOptions,
isolateModuleIDs: true, isolateModuleIDs: true,
@ -31,29 +34,26 @@ function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {
} }
function createCodeWithMap( function createCodeWithMap(
bundle: Bundle, bundle: {code: string, map: string},
dev: boolean, dev: boolean,
sourceMapSourcesRoot?: string, sourceMapSourcesRoot?: string,
): {code: string, map: SourceMap} { ): {code: string, map: SourceMap} {
const map = bundle.getSourceMap({dev}); const map = bundle.map;
const sourceMap = relativizeSourceMap( const sourceMap = relativizeSourceMap(
typeof map === 'string' ? (JSON.parse(map): SourceMap) : map, (JSON.parse(map): SourceMap),
sourceMapSourcesRoot, sourceMapSourcesRoot,
); );
return { return {
code: bundle.getSource({dev}), code: bundle.code,
map: sourceMap, map: sourceMap,
}; };
} }
function saveBundleAndMap( function saveBundleAndMap(
bundle: Bundle, bundle: {code: string, map: string},
options: OutputOptions, options: OutputOptions,
log: (...args: Array<string>) => {}, log: (...args: Array<string>) => {},
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error ): Promise<mixed> {
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
): Promise<> {
const { const {
bundleOutput, bundleOutput,
bundleEncoding: encoding, bundleEncoding: encoding,
@ -63,15 +63,7 @@ function saveBundleAndMap(
} = options; } = options;
log('start'); log('start');
const origCodeWithMap = createCodeWithMap( const codeWithMap = createCodeWithMap(bundle, !!dev, sourcemapSourcesRoot);
bundle,
!!dev,
sourcemapSourcesRoot,
);
const codeWithMap = bundle.postProcessBundleSourcemap({
...origCodeWithMap,
outFileName: bundleOutput,
});
log('finish'); log('finish');
log('Writing bundle output to:', bundleOutput); log('Writing bundle output to:', bundleOutput);

View File

@ -22,7 +22,7 @@ const writeSourceMap = require('./write-sourcemap');
const {joinModules} = require('./util'); const {joinModules} = require('./util');
import type Bundle from '../../../Bundler/Bundle'; import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
import type {OutputOptions} from '../../types.flow'; import type {OutputOptions} from '../../types.flow';
// must not start with a dot, as that won't go into the apk // must not start with a dot, as that won't go into the apk
@ -37,7 +37,7 @@ const MODULES_DIR = 'js-modules';
* directory as the startup file. * directory as the startup file.
*/ */
function saveAsAssets( function saveAsAssets(
bundle: Bundle, bundle: RamBundleInfo,
options: OutputOptions, options: OutputOptions,
log: (...args: Array<string>) => void, log: (...args: Array<string>) => void,
): Promise<mixed> { ): Promise<mixed> {
@ -49,7 +49,7 @@ function saveAsAssets(
} = options; } = options;
log('start'); log('start');
const {startupModules, lazyModules} = bundle.getUnbundle(); const {startupModules, lazyModules} = bundle;
log('finish'); log('finish');
const startupCode = joinModules(startupModules); const startupCode = joinModules(startupModules);

View File

@ -20,7 +20,7 @@ const writeSourceMap = require('./write-sourcemap');
const {joinModules} = require('./util'); const {joinModules} = require('./util');
import type Bundle from '../../../Bundler/Bundle'; import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
import type { import type {
ModuleGroups, ModuleGroups,
ModuleTransportLike, ModuleTransportLike,
@ -37,7 +37,7 @@ const SIZEOF_UINT32 = 4;
* empty string. * empty string.
*/ */
function saveAsIndexedFile( function saveAsIndexedFile(
bundle: Bundle, bundle: RamBundleInfo,
options: OutputOptions, options: OutputOptions,
log: (...args: Array<string>) => void, log: (...args: Array<string>) => void,
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error
@ -52,7 +52,7 @@ function saveAsIndexedFile(
} = options; } = options;
log('start'); log('start');
const {startupModules, lazyModules, groups} = bundle.getUnbundle(); const {startupModules, lazyModules, groups} = bundle;
log('finish'); log('finish');
const moduleGroups = createModuleGroups(groups, lazyModules); const moduleGroups = createModuleGroups(groups, lazyModules);

View File

@ -17,13 +17,14 @@ const {
joinModules, joinModules,
} = require('./util'); } = require('./util');
import type {RamModule} from '../../../DeltaBundler/Serializers';
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow'; import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
type Params = {| type Params = {|
fixWrapperOffset: boolean, fixWrapperOffset: boolean,
lazyModules: $ReadOnlyArray<ModuleTransportLike>, lazyModules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
moduleGroups: ?ModuleGroups, moduleGroups: ?ModuleGroups,
startupModules: $ReadOnlyArray<ModuleTransportLike>, startupModules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
|}; |};
module.exports = ({ module.exports = ({

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant * 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. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @format
* @flow * @flow
* @format * @format
*/ */
@ -17,20 +18,23 @@ const Server = require('../../../Server');
const asAssets = require('./as-assets'); const asAssets = require('./as-assets');
const asIndexedFile = require('./as-indexed-file').save; const asIndexedFile = require('./as-indexed-file').save;
import type Bundle from '../../../Bundler/Bundle';
import type {OutputOptions, RequestOptions} from '../../types.flow'; import type {OutputOptions, RequestOptions} from '../../types.flow';
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) { async function buildBundle(
return packagerClient.buildBundle({ packagerClient: Server,
requestOptions: RequestOptions,
): Promise<RamBundleInfo> {
const options = {
...Server.DEFAULT_BUNDLE_OPTIONS, ...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions, ...requestOptions,
unbundle: true,
isolateModuleIDs: true, isolateModuleIDs: true,
}); };
return await packagerClient.getRamBundleInfo(options);
} }
function saveUnbundle( function saveUnbundle(
bundle: Bundle, bundle: RamBundleInfo,
options: OutputOptions, options: OutputOptions,
log: (x: string) => void, log: (x: string) => void,
): Promise<mixed> { ): Promise<mixed> {

View File

@ -13,6 +13,7 @@
const invariant = require('fbjs/lib/invariant'); const invariant = require('fbjs/lib/invariant');
import type {RamModule} from '../../../DeltaBundler/Serializers';
import type { import type {
FBIndexMap, FBIndexMap,
IndexMap, IndexMap,
@ -55,7 +56,7 @@ const Section = (line: number, column: number, map: SourceMap) => ({
type CombineOptions = {fixWrapperOffset: boolean}; type CombineOptions = {fixWrapperOffset: boolean};
function combineSourceMaps( function combineSourceMaps(
modules: $ReadOnlyArray<ModuleTransportLike>, modules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
moduleGroups?: ModuleGroups, moduleGroups?: ModuleGroups,
options?: ?CombineOptions, options?: ?CombineOptions,
): IndexMap { ): IndexMap {
@ -64,7 +65,7 @@ function combineSourceMaps(
} }
function combineSourceMapsAddingOffsets( function combineSourceMapsAddingOffsets(
modules: $ReadOnlyArray<ModuleTransportLike>, modules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
moduleGroups?: ?ModuleGroups, moduleGroups?: ?ModuleGroups,
options?: ?CombineOptions, options?: ?CombineOptions,
): FBIndexMap { ): FBIndexMap {
@ -78,7 +79,12 @@ function combineSourceMapsAddingOffsets(
return {sections, version: 3, x_facebook_offsets}; return {sections, version: 3, x_facebook_offsets};
} }
function combineMaps(modules, offsets: ?Array<number>, moduleGroups, options) { function combineMaps(
modules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
offsets: ?Array<number>,
moduleGroups,
options,
) {
const sections = []; const sections = [];
let line = 0; let line = 0;