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

View File

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

View File

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

View File

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