Separate build modules from require calls when bundling

Summary: separates modules of the dependency graph from the generated require calls to kick of the app. This is required to make RAM bundle generation work properly'

Reviewed By: jeanlauliac

Differential Revision: D5094635

fbshipit-source-id: fca69a3e2d9b030cdc4d4405c2b5e795b0d55f87
This commit is contained in:
David Aurelio 2017-05-19 07:52:22 -07:00 committed by Facebook Github Bot
parent 7cafb53b7b
commit 62f7f7607e
2 changed files with 45 additions and 31 deletions

View File

@ -17,13 +17,18 @@ const {addModuleIdsToModuleWrapper} = require('./util');
import type {OutputFn} from '../types.flow'; import type {OutputFn} from '../types.flow';
module.exports = ( function asPlainBundle({
(modules, filename, idForPath, sourceMapPath) => { filename,
idForPath,
modules,
requireCalls,
sourceMapPath,
}) {
let code = ''; let code = '';
let line = 0; let line = 0;
const sections = []; const sections = [];
for (const module of modules) { for (const module of concat(modules, requireCalls)) {
const {file} = module; const {file} = module;
const moduleCode = file.type === 'module' const moduleCode = file.type === 'module'
? addModuleIdsToModuleWrapper(module, idForPath) ? addModuleIdsToModuleWrapper(module, idForPath)
@ -48,10 +53,18 @@ module.exports = (
extraFiles: [[`${filename}.meta`, meta(code)]], extraFiles: [[`${filename}.meta`, meta(code)]],
map: createIndexMap({file: filename, sections}), map: createIndexMap({file: filename, sections}),
}; };
}: OutputFn); }
module.exports = (asPlainBundle: OutputFn);
const reLine = /^/gm; const reLine = /^/gm;
function countLines(string: string): number { function countLines(string: string): number {
//$FlowFixMe This regular expression always matches //$FlowFixMe This regular expression always matches
return string.match(reLine).length; return string.match(reLine).length;
} }
function* concat<T>(...iterables: Array<Iterable<T>>): Iterable<T> {
for (const it of iterables) {
yield* it;
}
}

View File

@ -70,16 +70,17 @@ export type Module = {|
file: File, file: File,
|}; |};
export type OutputFn = ( export type OutputFn = ({|
modules: Iterable<Module>,
filename: string, filename: string,
idForPath: IdForPathFn, idForPath: IdForPathFn,
modules: Iterable<Module>,
requireCalls: Iterable<Module>,
sourceMapPath?: string, sourceMapPath?: string,
) => OutputResult; |}) => OutputResult;
type OutputResult = {| type OutputResult = {|
code: string | Buffer, code: string | Buffer,
extraFiles: Iterable<[string, string | Buffer]>, extraFiles?: Iterable<[string, string | Buffer]>,
map: SourceMap, map: SourceMap,
|}; |};