mirror of
https://github.com/status-im/metro.git
synced 2025-01-21 00:19:31 +00:00
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:
parent
7cafb53b7b
commit
62f7f7607e
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user