mirror of https://github.com/status-im/metro.git
remove `getRamOptions` from `DeltaTransformer` and `Bundler`
Summary: Removes `getRamOptions` from `DeltaTransformer` and `Bundler` for better separation of concerns, and ultimately, porting delta functionality to `ModuleGraph` Reviewed By: rafeca Differential Revision: D7084487 fbshipit-source-id: e8a7ea4addbad9057e7d55627f77ebd01e64786b
This commit is contained in:
parent
2393f849e3
commit
356d896c01
|
@ -41,12 +41,6 @@ import type {
|
|||
MetroSourceMap,
|
||||
} from 'metro-source-map';
|
||||
|
||||
export type BundlingOptions = {|
|
||||
+preloadedModules: ?{[string]: true} | false,
|
||||
+ramGroups: ?Array<string>,
|
||||
+transformer: JSTransformerOptions,
|
||||
|};
|
||||
|
||||
type TransformOptions = {|
|
||||
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
|
||||
|};
|
||||
|
@ -211,36 +205,6 @@ class Bundler {
|
|||
return transform || {inlineRequires: false};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options needed to create a RAM bundle.
|
||||
*/
|
||||
async getRamOptions(
|
||||
entryFile: string,
|
||||
options: {dev: boolean, platform: ?string},
|
||||
getDependencies: string => Promise<Array<string>>,
|
||||
): Promise<{|
|
||||
+preloadedModules: {[string]: true},
|
||||
+ramGroups: Array<string>,
|
||||
|}> {
|
||||
if (!this._getTransformOptions) {
|
||||
return {
|
||||
preloadedModules: {},
|
||||
ramGroups: [],
|
||||
};
|
||||
}
|
||||
|
||||
const {preloadedModules, ramGroups} = await this._getTransformOptions(
|
||||
[entryFile],
|
||||
{dev: options.dev, hot: true, platform: options.platform},
|
||||
getDependencies,
|
||||
);
|
||||
|
||||
return {
|
||||
preloadedModules: preloadedModules || {},
|
||||
ramGroups: ramGroups || [],
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper method to return the global transform options that are kept in the
|
||||
* Bundler.
|
||||
|
|
|
@ -153,7 +153,7 @@ class DeltaTransformer extends EventEmitter {
|
|||
* Returns a function that can be used to calculate synchronously the
|
||||
* transitive dependencies of any given file within the dependency graph.
|
||||
**/
|
||||
async getDependenciesFn() {
|
||||
async getDependenciesFn(): Promise<(string) => Set<string>> {
|
||||
if (!this._deltaCalculator.getDependencyEdges().size) {
|
||||
// If by any means the dependency graph has not been initialized, call
|
||||
// getDelta() to initialize it.
|
||||
|
@ -187,22 +187,6 @@ class DeltaTransformer extends EventEmitter {
|
|||
return output;
|
||||
}
|
||||
|
||||
async getRamOptions(
|
||||
entryFile: string,
|
||||
options: {dev: boolean, platform: ?string},
|
||||
): Promise<{|
|
||||
+preloadedModules: {[string]: true},
|
||||
+ramGroups: $ReadOnlyArray<string>,
|
||||
|}> {
|
||||
const getDependenciesFn = await this.getDependenciesFn();
|
||||
|
||||
return await this._bundler.getRamOptions(
|
||||
entryFile,
|
||||
options,
|
||||
async (path: string) => Array.from(getDependenciesFn(path)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method to calculate the bundle delta. It returns a DeltaResult,
|
||||
* which contain the source code of the modified and added modules and the
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {GetTransformOptions} from '../../Bundler';
|
||||
|
||||
/**
|
||||
* Returns the options needed to create a RAM bundle.
|
||||
*/
|
||||
async function getRamOptions(
|
||||
entryFile: string,
|
||||
options: {dev: boolean, platform: ?string},
|
||||
getDependencies: string => Iterable<string>,
|
||||
getTransformOptions: ?GetTransformOptions,
|
||||
): Promise<{|
|
||||
+preloadedModules: {[string]: true},
|
||||
+ramGroups: Array<string>,
|
||||
|}> {
|
||||
if (getTransformOptions == null) {
|
||||
return {
|
||||
preloadedModules: {},
|
||||
ramGroups: [],
|
||||
};
|
||||
}
|
||||
|
||||
const {preloadedModules, ramGroups} = await getTransformOptions(
|
||||
[entryFile],
|
||||
{dev: options.dev, hot: true, platform: options.platform},
|
||||
async x => Array.from(getDependencies),
|
||||
);
|
||||
|
||||
return {
|
||||
preloadedModules: preloadedModules || {},
|
||||
ramGroups: ramGroups || [],
|
||||
};
|
||||
}
|
||||
|
||||
exports.getRamOptions = getRamOptions;
|
|
@ -10,22 +10,24 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const DeltaPatcher = require('./DeltaPatcher');
|
||||
const DeltaPatcher = require('../DeltaPatcher');
|
||||
const RamBundle = require('./RamBundle');
|
||||
|
||||
const stableHash = require('metro-cache/src/stableHash');
|
||||
const toLocalPath = require('../node-haste/lib/toLocalPath');
|
||||
const toLocalPath = require('../../node-haste/lib/toLocalPath');
|
||||
|
||||
const {getAssetData} = require('../Assets');
|
||||
const {createRamBundleGroups} = require('../Bundler/util');
|
||||
const {getAssetData} = require('../../Assets');
|
||||
const {createRamBundleGroups} = require('../../Bundler/util');
|
||||
const {fromRawMappings} = require('metro-source-map');
|
||||
|
||||
import type {AssetData} from '../Assets';
|
||||
import type {BundleOptions, ModuleTransportLike} from '../shared/types.flow';
|
||||
import type DeltaBundler from './';
|
||||
import type {AssetData} from '../../Assets';
|
||||
import type {GetTransformOptions} from '../../Bundler';
|
||||
import type {BundleOptions, ModuleTransportLike} from '../../shared/types.flow';
|
||||
import type DeltaBundler from '../';
|
||||
import type DeltaTransformer, {
|
||||
DeltaEntry,
|
||||
DeltaTransformResponse,
|
||||
} from './DeltaTransformer';
|
||||
} from '../DeltaTransformer';
|
||||
import type {BabelSourceMap} from '@babel/core';
|
||||
|
||||
export type DeltaOptions = BundleOptions & {
|
||||
|
@ -166,6 +168,7 @@ async function _getAllModules(
|
|||
async function getRamBundleInfo(
|
||||
deltaBundler: DeltaBundler,
|
||||
options: BundleOptions,
|
||||
getTransformOptions: ?GetTransformOptions,
|
||||
): Promise<RamBundleInfo> {
|
||||
const {modules, deltaTransformer} = await _getAllModules(
|
||||
deltaBundler,
|
||||
|
@ -184,12 +187,14 @@ async function getRamBundleInfo(
|
|||
type: module.type,
|
||||
}));
|
||||
|
||||
const {preloadedModules, ramGroups} = await deltaTransformer.getRamOptions(
|
||||
const {preloadedModules, ramGroups} = await RamBundle.getRamOptions(
|
||||
options.entryFile,
|
||||
{
|
||||
dev: options.dev,
|
||||
platform: options.platform,
|
||||
},
|
||||
await deltaTransformer.getDependenciesFn(),
|
||||
getTransformOptions,
|
||||
);
|
||||
|
||||
const startupModules = [];
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
jest.mock('../../node-haste/lib/toLocalPath');
|
||||
jest.mock('../../Assets');
|
||||
jest.mock('../Serializers/RamBundle');
|
||||
|
||||
const {getAssetData} = require('../../Assets');
|
||||
const toLocalPath = require('../../node-haste/lib/toLocalPath');
|
||||
|
@ -22,10 +23,10 @@ describe('Serializers', () => {
|
|||
const OriginalDate = global.Date;
|
||||
const getDelta = jest.fn();
|
||||
const getDependenciesFn = jest.fn();
|
||||
const getRamOptions = jest.fn();
|
||||
const postProcessModules = jest.fn();
|
||||
let deltaBundler;
|
||||
let Serializers;
|
||||
let RamBundle;
|
||||
|
||||
const deltaResponse = {
|
||||
id: '1234',
|
||||
|
@ -44,11 +45,12 @@ describe('Serializers', () => {
|
|||
}
|
||||
|
||||
beforeEach(() => {
|
||||
Serializers = require('../Serializers');
|
||||
Serializers = require('../Serializers/Serializers');
|
||||
RamBundle = require('../Serializers/RamBundle');
|
||||
|
||||
getDelta.mockReturnValueOnce(Promise.resolve(deltaResponse));
|
||||
getDependenciesFn.mockReturnValue(Promise.resolve(() => new Set()));
|
||||
getRamOptions.mockReturnValue(
|
||||
RamBundle.getRamOptions.mockReturnValue(
|
||||
Promise.resolve({
|
||||
preloadedModules: {},
|
||||
ramGroups: [],
|
||||
|
@ -61,7 +63,6 @@ describe('Serializers', () => {
|
|||
return {
|
||||
getDelta,
|
||||
getDependenciesFn,
|
||||
getRamOptions,
|
||||
};
|
||||
},
|
||||
getPostProcessModulesFn() {
|
||||
|
@ -215,7 +216,7 @@ describe('Serializers', () => {
|
|||
}),
|
||||
);
|
||||
|
||||
getRamOptions.mockReturnValue(
|
||||
RamBundle.getRamOptions.mockReturnValue(
|
||||
Promise.resolve({
|
||||
preloadedModules: {'/foo/3.js': true},
|
||||
ramGroups: ['/foo/5.js'],
|
||||
|
|
|
@ -22,7 +22,7 @@ jest
|
|||
.mock('../../node-haste/DependencyGraph')
|
||||
.mock('metro-core/src/Logger')
|
||||
.mock('../../lib/GlobalTransformCache')
|
||||
.mock('../../DeltaBundler/Serializers');
|
||||
.mock('../../DeltaBundler/Serializers/Serializers');
|
||||
|
||||
describe('processRequest', () => {
|
||||
let Bundler;
|
||||
|
@ -40,7 +40,7 @@ describe('processRequest', () => {
|
|||
Server = require('../');
|
||||
getAsset = require('../../Assets').getAsset;
|
||||
symbolicate = require('../symbolicate');
|
||||
Serializers = require('../../DeltaBundler/Serializers');
|
||||
Serializers = require('../../DeltaBundler/Serializers/Serializers');
|
||||
DeltaBundler = require('../../DeltaBundler');
|
||||
});
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
const Bundler = require('../Bundler');
|
||||
const DeltaBundler = require('../DeltaBundler');
|
||||
const MultipartResponse = require('./MultipartResponse');
|
||||
const Serializers = require('../DeltaBundler/Serializers');
|
||||
const Serializers = require('../DeltaBundler/Serializers/Serializers');
|
||||
const debug = require('debug')('Metro:Server');
|
||||
const defaults = require('../defaults');
|
||||
const formatBundlingError = require('../lib/formatBundlingError');
|
||||
|
@ -33,7 +33,10 @@ const resolveSync: ResolveSync = require('resolve').sync;
|
|||
import type {CustomError} from '../lib/formatBundlingError';
|
||||
import type {IncomingMessage, ServerResponse} from 'http';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {DeltaOptions} from '../DeltaBundler/Serializers';
|
||||
import type {
|
||||
DeltaOptions,
|
||||
RamBundleInfo,
|
||||
} from '../DeltaBundler/Serializers/Serializers';
|
||||
import type {BundleOptions, Options} from '../shared/types.flow';
|
||||
import type {
|
||||
GetTransformOptions,
|
||||
|
@ -45,7 +48,6 @@ import type {MetroSourceMap} from 'metro-source-map';
|
|||
import type {TransformCache} from '../lib/TransformCaching';
|
||||
import type {Symbolicate} from './symbolicate';
|
||||
import type {AssetData} from '../Assets';
|
||||
import type {RamBundleInfo} from '../DeltaBundler/Serializers';
|
||||
import type {PostProcessModules} from '../DeltaBundler';
|
||||
import type {TransformedCode} from '../JSTransformer/worker';
|
||||
const {
|
||||
|
@ -251,7 +253,11 @@ class Server {
|
|||
}
|
||||
|
||||
async getRamBundleInfo(options: BundleOptions): Promise<RamBundleInfo> {
|
||||
return await Serializers.getRamBundleInfo(this._deltaBundler, options);
|
||||
return await Serializers.getRamBundleInfo(
|
||||
this._deltaBundler,
|
||||
options,
|
||||
this._opts.getTransformOptions,
|
||||
);
|
||||
}
|
||||
|
||||
async getAssets(options: BundleOptions): Promise<$ReadOnlyArray<AssetData>> {
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
jest.mock('../../DeltaBundler/Serializers');
|
||||
jest.mock('../../DeltaBundler/Serializers/Serializers');
|
||||
jest.mock('../../Assets');
|
||||
|
||||
const getOrderedDependencyPaths = require('../getOrderedDependencyPaths');
|
||||
const Serializers = require('../../DeltaBundler/Serializers');
|
||||
const Serializers = require('../../DeltaBundler/Serializers/Serializers');
|
||||
|
||||
const {getAssetFiles} = require('../../Assets');
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const Serializers = require('../DeltaBundler/Serializers');
|
||||
const Serializers = require('../DeltaBundler/Serializers/Serializers');
|
||||
|
||||
const {getAssetFiles} = require('../Assets');
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ const writeSourceMap = require('./write-sourcemap');
|
|||
|
||||
const {joinModules} = require('./util');
|
||||
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/Serializers';
|
||||
import type {OutputOptions} from '../../types.flow';
|
||||
|
||||
// must not start with a dot, as that won't go into the apk
|
||||
|
|
|
@ -18,7 +18,7 @@ const writeSourceMap = require('./write-sourcemap');
|
|||
|
||||
const {joinModules} = require('./util');
|
||||
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/Serializers';
|
||||
import type {
|
||||
ModuleGroups,
|
||||
ModuleTransportLike,
|
||||
|
|
|
@ -15,7 +15,7 @@ const {
|
|||
joinModules,
|
||||
} = require('./util');
|
||||
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers/Serializers';
|
||||
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
||||
|
||||
type Params = {|
|
||||
|
|
|
@ -16,7 +16,7 @@ const asAssets = require('./as-assets');
|
|||
const asIndexedFile = require('./as-indexed-file').save;
|
||||
|
||||
import type {OutputOptions, RequestOptions} from '../../types.flow';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers';
|
||||
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/Serializers';
|
||||
|
||||
async function buildBundle(
|
||||
packagerClient: Server,
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers/Serializers';
|
||||
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
||||
import type {BabelSourceMap} from '@babel/core';
|
||||
import type {FBIndexMap, IndexMap, MetroSourceMap} from 'metro-source-map';
|
||||
|
|
Loading…
Reference in New Issue