metro-bundler: allow different run-before-main-module depending on entry point

Reviewed By: davidaurelio

Differential Revision: D6248242

fbshipit-source-id: 9471820fce926e676170e3024bd48c9d7335c1a7
This commit is contained in:
Jean Lauliac 2017-11-07 07:31:39 -08:00 committed by Facebook Github Bot
parent 2c5a2fec66
commit 81bfef0389
4 changed files with 11 additions and 9 deletions

View File

@ -135,7 +135,7 @@ export type ConfigT = {
* An array of modules to be required before the entry point. It should
* contain the absolute path of each module.
*/
runBeforeMainModule: Array<string>,
getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
};
const DEFAULT = ({
@ -158,7 +158,7 @@ const DEFAULT = ({
postProcessModules: modules => modules,
postProcessModulesForBuck: modules => modules,
postProcessBundleSourcemap: ({code, map, outFileName}) => ({code, map}),
runBeforeMainModule: [],
getModulesRunBeforeMainModule: () => [],
transformVariants: () => ({default: {}}),
getWorkerPath: () => null,
}: ConfigT);

View File

@ -55,7 +55,7 @@ describe('processRequest', () => {
cacheVersion: null,
polyfillModuleNames: null,
reporter: require('../../lib/reporting').nullReporter,
runBeforeMainModule: ['InitializeCore'],
getModulesRunBeforeMainModule: () => ['InitializeCore'],
};
const makeRequest = (reqHandler, requrl, reqOptions) =>

View File

@ -93,7 +93,7 @@ export type Options = {|
providesModuleNodeModules?: Array<string>,
reporter?: Reporter,
resetCache?: boolean,
+runBeforeMainModule: Array<string>,
+getModulesRunBeforeMainModule: (entryPoint: string) => Array<string>,
silent?: boolean,
+sourceExts: ?Array<string>,
+transformCache: TransformCache,
@ -167,7 +167,7 @@ class Server {
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
resetCache: boolean,
+runBeforeMainModule: Array<string>,
+getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
silent: boolean,
+sourceExts: Array<string>,
+transformCache: TransformCache,
@ -207,6 +207,7 @@ class Server {
? options.enableBabelRCLookup
: true,
extraNodeModules: options.extraNodeModules || {},
getModulesRunBeforeMainModule: options.getModulesRunBeforeMainModule,
getPolyfills: options.getPolyfills,
getTransformOptions: options.getTransformOptions,
globalTransformCache: options.globalTransformCache,
@ -223,7 +224,6 @@ class Server {
providesModuleNodeModules: options.providesModuleNodeModules,
reporter,
resetCache: options.resetCache || false,
runBeforeMainModule: options.runBeforeMainModule,
silent: options.silent || false,
sourceExts: options.sourceExts || defaults.sourceExts,
transformCache: options.transformCache,
@ -325,7 +325,9 @@ class Server {
async buildBundle(options: BundleOptions): Promise<Bundle> {
const bundle = await this._bundler.bundle({
...options,
runBeforeMainModule: this._opts.runBeforeMainModule,
runBeforeMainModule: this._opts.getModulesRunBeforeMainModule(
options.entryFile,
),
});
const modules = bundle.getModules();
const nonVirtual = modules.filter(m => !m.virtual);
@ -1306,7 +1308,7 @@ class Server {
minify,
excludeSource,
hot: true,
runBeforeMainModule: this._opts.runBeforeMainModule,
runBeforeMainModule: this._opts.getModulesRunBeforeMainModule(entryFile),
runModule: this._getBoolOptionFromQuery(urlObj.query, 'runModule', true),
inlineSourceMap: this._getBoolOptionFromQuery(
urlObj.query,

View File

@ -178,6 +178,7 @@ function toServerOptions(options: Options): ServerOptions {
cacheVersion: options.cacheVersion,
enableBabelRCLookup: options.enableBabelRCLookup,
extraNodeModules: options.extraNodeModules,
getModulesRunBeforeMainModule: options.getModulesRunBeforeMainModule,
getPolyfills: options.getPolyfills,
getTransformOptions: options.getTransformOptions,
globalTransformCache: options.globalTransformCache,
@ -193,7 +194,6 @@ function toServerOptions(options: Options): ServerOptions {
providesModuleNodeModules: options.providesModuleNodeModules,
reporter: options.reporter,
resetCache: options.resetCache,
runBeforeMainModule: options.runBeforeMainModule,
silent: options.silent,
sourceExts: options.sourceExts,
transformCache: options.transformCache || TransformCaching.useTempDir(),