mirror of https://github.com/status-im/metro.git
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:
parent
ff7ec2e6bf
commit
cd67cd4794
|
@ -275,7 +275,7 @@ class DeltaTransformer extends EventEmitter {
|
|||
.filter(module => dependencyEdges.has(module.path))
|
||||
.map(this._getModuleId)
|
||||
.map(moduleId => {
|
||||
const code = `;require(${JSON.stringify(moduleId)})`;
|
||||
const code = `require(${JSON.stringify(moduleId)});`;
|
||||
const name = 'require-' + String(moduleId);
|
||||
const path = name + '.js';
|
||||
|
||||
|
@ -388,7 +388,7 @@ class DeltaTransformer extends EventEmitter {
|
|||
return [
|
||||
id,
|
||||
{
|
||||
code: ';' + code,
|
||||
code,
|
||||
id,
|
||||
map,
|
||||
name,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* 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.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
@ -18,12 +19,14 @@ const meta = require('./meta');
|
|||
const relativizeSourceMap = require('../../lib/relativizeSourceMap');
|
||||
const writeFile = require('./writeFile');
|
||||
|
||||
import type Bundle from '../../Bundler/Bundle';
|
||||
import type {SourceMap} from '../../lib/SourceMap';
|
||||
import type {OutputOptions, RequestOptions} from '../types.flow';
|
||||
|
||||
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {
|
||||
return packagerClient.buildBundle({
|
||||
function buildBundle(
|
||||
packagerClient: Server,
|
||||
requestOptions: RequestOptions,
|
||||
): Promise<{code: string, map: string}> {
|
||||
return packagerClient.build({
|
||||
...Server.DEFAULT_BUNDLE_OPTIONS,
|
||||
...requestOptions,
|
||||
isolateModuleIDs: true,
|
||||
|
@ -31,29 +34,26 @@ function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {
|
|||
}
|
||||
|
||||
function createCodeWithMap(
|
||||
bundle: Bundle,
|
||||
bundle: {code: string, map: string},
|
||||
dev: boolean,
|
||||
sourceMapSourcesRoot?: string,
|
||||
): {code: string, map: SourceMap} {
|
||||
const map = bundle.getSourceMap({dev});
|
||||
const map = bundle.map;
|
||||
const sourceMap = relativizeSourceMap(
|
||||
typeof map === 'string' ? (JSON.parse(map): SourceMap) : map,
|
||||
(JSON.parse(map): SourceMap),
|
||||
sourceMapSourcesRoot,
|
||||
);
|
||||
return {
|
||||
code: bundle.getSource({dev}),
|
||||
code: bundle.code,
|
||||
map: sourceMap,
|
||||
};
|
||||
}
|
||||
|
||||
function saveBundleAndMap(
|
||||
bundle: Bundle,
|
||||
bundle: {code: string, map: string},
|
||||
options: OutputOptions,
|
||||
log: (...args: Array<string>) => {},
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error
|
||||
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
||||
* run Flow. */
|
||||
): Promise<> {
|
||||
): Promise<mixed> {
|
||||
const {
|
||||
bundleOutput,
|
||||
bundleEncoding: encoding,
|
||||
|
@ -63,15 +63,7 @@ function saveBundleAndMap(
|
|||
} = options;
|
||||
|
||||
log('start');
|
||||
const origCodeWithMap = createCodeWithMap(
|
||||
bundle,
|
||||
!!dev,
|
||||
sourcemapSourcesRoot,
|
||||
);
|
||||
const codeWithMap = bundle.postProcessBundleSourcemap({
|
||||
...origCodeWithMap,
|
||||
outFileName: bundleOutput,
|
||||
});
|
||||
const codeWithMap = createCodeWithMap(bundle, !!dev, sourcemapSourcesRoot);
|
||||
log('finish');
|
||||
|
||||
log('Writing bundle output to:', bundleOutput);
|
||||
|
|
|
@ -22,7 +22,7 @@ const writeSourceMap = require('./write-sourcemap');
|
|||
|
||||
const {joinModules} = require('./util');
|
||||
|
||||
import type Bundle from '../../../Bundler/Bundle';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
|
||||
import type {OutputOptions} from '../../types.flow';
|
||||
|
||||
// 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.
|
||||
*/
|
||||
function saveAsAssets(
|
||||
bundle: Bundle,
|
||||
bundle: RamBundleInfo,
|
||||
options: OutputOptions,
|
||||
log: (...args: Array<string>) => void,
|
||||
): Promise<mixed> {
|
||||
|
@ -49,7 +49,7 @@ function saveAsAssets(
|
|||
} = options;
|
||||
|
||||
log('start');
|
||||
const {startupModules, lazyModules} = bundle.getUnbundle();
|
||||
const {startupModules, lazyModules} = bundle;
|
||||
log('finish');
|
||||
const startupCode = joinModules(startupModules);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ const writeSourceMap = require('./write-sourcemap');
|
|||
|
||||
const {joinModules} = require('./util');
|
||||
|
||||
import type Bundle from '../../../Bundler/Bundle';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
|
||||
import type {
|
||||
ModuleGroups,
|
||||
ModuleTransportLike,
|
||||
|
@ -37,7 +37,7 @@ const SIZEOF_UINT32 = 4;
|
|||
* empty string.
|
||||
*/
|
||||
function saveAsIndexedFile(
|
||||
bundle: Bundle,
|
||||
bundle: RamBundleInfo,
|
||||
options: OutputOptions,
|
||||
log: (...args: Array<string>) => void,
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error
|
||||
|
@ -52,7 +52,7 @@ function saveAsIndexedFile(
|
|||
} = options;
|
||||
|
||||
log('start');
|
||||
const {startupModules, lazyModules, groups} = bundle.getUnbundle();
|
||||
const {startupModules, lazyModules, groups} = bundle;
|
||||
log('finish');
|
||||
|
||||
const moduleGroups = createModuleGroups(groups, lazyModules);
|
||||
|
|
|
@ -17,13 +17,14 @@ const {
|
|||
joinModules,
|
||||
} = require('./util');
|
||||
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
||||
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
||||
|
||||
type Params = {|
|
||||
fixWrapperOffset: boolean,
|
||||
lazyModules: $ReadOnlyArray<ModuleTransportLike>,
|
||||
lazyModules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
|
||||
moduleGroups: ?ModuleGroups,
|
||||
startupModules: $ReadOnlyArray<ModuleTransportLike>,
|
||||
startupModules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
|
||||
|};
|
||||
|
||||
module.exports = ({
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* 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.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
@ -17,20 +18,23 @@ const Server = require('../../../Server');
|
|||
const asAssets = require('./as-assets');
|
||||
const asIndexedFile = require('./as-indexed-file').save;
|
||||
|
||||
import type Bundle from '../../../Bundler/Bundle';
|
||||
import type {OutputOptions, RequestOptions} from '../../types.flow';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
|
||||
|
||||
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {
|
||||
return packagerClient.buildBundle({
|
||||
async function buildBundle(
|
||||
packagerClient: Server,
|
||||
requestOptions: RequestOptions,
|
||||
): Promise<RamBundleInfo> {
|
||||
const options = {
|
||||
...Server.DEFAULT_BUNDLE_OPTIONS,
|
||||
...requestOptions,
|
||||
unbundle: true,
|
||||
isolateModuleIDs: true,
|
||||
});
|
||||
};
|
||||
return await packagerClient.getRamBundleInfo(options);
|
||||
}
|
||||
|
||||
function saveUnbundle(
|
||||
bundle: Bundle,
|
||||
bundle: RamBundleInfo,
|
||||
options: OutputOptions,
|
||||
log: (x: string) => void,
|
||||
): Promise<mixed> {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
||||
import type {
|
||||
FBIndexMap,
|
||||
IndexMap,
|
||||
|
@ -55,7 +56,7 @@ const Section = (line: number, column: number, map: SourceMap) => ({
|
|||
type CombineOptions = {fixWrapperOffset: boolean};
|
||||
|
||||
function combineSourceMaps(
|
||||
modules: $ReadOnlyArray<ModuleTransportLike>,
|
||||
modules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
|
||||
moduleGroups?: ModuleGroups,
|
||||
options?: ?CombineOptions,
|
||||
): IndexMap {
|
||||
|
@ -64,7 +65,7 @@ function combineSourceMaps(
|
|||
}
|
||||
|
||||
function combineSourceMapsAddingOffsets(
|
||||
modules: $ReadOnlyArray<ModuleTransportLike>,
|
||||
modules: $ReadOnlyArray<ModuleTransportLike | RamModule>,
|
||||
moduleGroups?: ?ModuleGroups,
|
||||
options?: ?CombineOptions,
|
||||
): FBIndexMap {
|
||||
|
@ -78,7 +79,12 @@ function combineSourceMapsAddingOffsets(
|
|||
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 = [];
|
||||
|
||||
let line = 0;
|
||||
|
|
Loading…
Reference in New Issue