diff --git a/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js b/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js index 9b29505d..3c00b69c 100644 --- a/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js +++ b/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js @@ -17,6 +17,7 @@ const seq = require('async/seq'); const virtualModule = require('./module').virtual; import type { + BuildResult, Callback, GraphFn, GraphResult, @@ -27,7 +28,7 @@ import type { type BuildFn = ( entryPoints: Iterable, options: BuildOptions, - callback: Callback, + callback: Callback, ) => void; type BuildOptions = {| @@ -86,9 +87,12 @@ exports.createBuildSetup = ( polyfills, } = nullthrows(result); + const preludeScript = prelude(optimize); + const prependedScripts = [preludeScript, ...moduleSystem, ...polyfills]; callback(null, { entryModules, - modules: concat([prelude(optimize)], moduleSystem, polyfills, modules), + modules: concat(prependedScripts, modules), + prependedScripts, }); }); }; diff --git a/packages/metro-bundler/src/ModuleGraph/types.flow.js b/packages/metro-bundler/src/ModuleGraph/types.flow.js index 4f66d303..b75b6655 100644 --- a/packages/metro-bundler/src/ModuleGraph/types.flow.js +++ b/packages/metro-bundler/src/ModuleGraph/types.flow.js @@ -15,6 +15,11 @@ import type {Ast} from 'babel-core'; import type {Console} from 'console'; export type {Transformer} from '../JSTransformer/worker/worker.js'; +export type BuildResult = {| + ...GraphResult, + prependedScripts: $ReadOnlyArray, +|}; + export type Callback = (Error => void) & ((null | void, A, B) => void);