Permalink
Browse files

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
  • Loading branch information...
davidaurelio authored and facebook-github-bot committed May 19, 2017
1 parent 8d60605 commit 3f176008e82edbe51b40854b87064ae313a393cb
Showing with 47 additions and 33 deletions.
  1. +42 −29 packager/src/ModuleGraph/output/as-plain-bundle.js
  2. +5 −4 packager/src/ModuleGraph/types.flow.js
@@ -17,41 +17,54 @@ const {addModuleIdsToModuleWrapper} = require('./util');
import type {OutputFn} from '../types.flow';
module.exports = (
(modules, filename, idForPath, sourceMapPath) => {
let code = '';
let line = 0;
const sections = [];
for (const module of modules) {
const {file} = module;
const moduleCode = file.type === 'module'
? addModuleIdsToModuleWrapper(module, idForPath)
: file.code;
code += moduleCode + '\n';
if (file.map) {
sections.push({
map: file.map,
offset: {column: 0, line},
});
}
line += countLines(moduleCode);
}
function asPlainBundle({
filename,
idForPath,
modules,
requireCalls,
sourceMapPath,
}) {
let code = '';
let line = 0;
const sections = [];
for (const module of concat(modules, requireCalls)) {
const {file} = module;
const moduleCode = file.type === 'module'
? addModuleIdsToModuleWrapper(module, idForPath)
: file.code;
if (sourceMapPath) {
code += `/*# sourceMappingURL=${sourceMapPath}*/`;
code += moduleCode + '\n';
if (file.map) {
sections.push({
map: file.map,
offset: {column: 0, line},
});
}
line += countLines(moduleCode);
}
return {
code,
extraFiles: [[`${filename}.meta`, meta(code)]],
map: createIndexMap({file: filename, sections}),
};
}: OutputFn);
if (sourceMapPath) {
code += `/*# sourceMappingURL=${sourceMapPath}*/`;
}
return {
code,
extraFiles: [[`${filename}.meta`, meta(code)]],
map: createIndexMap({file: filename, sections}),
};
}
module.exports = (asPlainBundle: OutputFn);
const reLine = /^/gm;
function countLines(string: string): number {
//$FlowFixMe This regular expression always matches
return string.match(reLine).length;
}
function* concat<T>(...iterables: Array<Iterable<T>>): Iterable<T> {
for (const it of iterables) {
yield* it;
}
}
@@ -70,16 +70,17 @@ export type Module = {|
file: File,
|};
export type OutputFn = (
modules: Iterable<Module>,
export type OutputFn = ({|
filename: string,
idForPath: IdForPathFn,
modules: Iterable<Module>,
requireCalls: Iterable<Module>,
sourceMapPath?: string,
) => OutputResult;
|}) => OutputResult;
type OutputResult = {|
code: string | Buffer,
extraFiles: Iterable<[string, string | Buffer]>,
extraFiles?: Iterable<[string, string | Buffer]>,
map: SourceMap,
|};

0 comments on commit 3f17600

Please sign in to comment.