mirror of https://github.com/status-im/metro.git
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:
parent
2c5a2fec66
commit
81bfef0389
|
@ -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);
|
||||||
|
|
|
@ -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) =>
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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(),
|
||||||
|
|
Loading…
Reference in New Issue