diff --git a/packages/metro-bundler/src/HmrServer/getBundlingOptionsForHmr.js b/packages/metro-bundler/src/HmrServer/getBundlingOptionsForHmr.js index 32962bcc..14d34a6b 100644 --- a/packages/metro-bundler/src/HmrServer/getBundlingOptionsForHmr.js +++ b/packages/metro-bundler/src/HmrServer/getBundlingOptionsForHmr.js @@ -35,6 +35,7 @@ module.exports = function getBundlingOptionsForHmr( return { ...mainOptions, assetPlugins: [], + bundleType: 'hmr', dev: true, entryModuleOnly: false, excludeSource: false, diff --git a/packages/metro-bundler/src/Server/__tests__/Server-test.js b/packages/metro-bundler/src/Server/__tests__/Server-test.js index 28c152e8..689c70cd 100644 --- a/packages/metro-bundler/src/Server/__tests__/Server-test.js +++ b/packages/metro-bundler/src/Server/__tests__/Server-test.js @@ -189,6 +189,7 @@ describe('processRequest', () => { expect(response.body).toEqual('this is the source'); expect(Serializers.fullBundle).toBeCalledWith(expect.any(DeltaBundler), { assetPlugins: [], + bundleType: 'bundle', deltaBundleId: expect.any(String), dev: true, entryFile: 'index.ios.js', @@ -218,6 +219,7 @@ describe('processRequest', () => { expect(response.body).toEqual('this is the source'); expect(Serializers.fullBundle).toBeCalledWith(expect.any(DeltaBundler), { assetPlugins: [], + bundleType: 'bundle', deltaBundleId: expect.any(String), dev: true, entryFile: 'index.js', @@ -247,6 +249,7 @@ describe('processRequest', () => { expect(response.body).toEqual('this is the source'); expect(Serializers.fullBundle).toBeCalledWith(expect.any(DeltaBundler), { assetPlugins: ['assetPlugin1', 'assetPlugin2'], + bundleType: 'bundle', deltaBundleId: expect.any(String), dev: true, entryFile: 'index.js', diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 76b2796d..ebfdd76d 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -258,6 +258,7 @@ class Server { const bundleOptions = { ...Server.DEFAULT_BUNDLE_OPTIONS, ...options, + bundleType: 'delta', deltaBundleId: null, }; @@ -754,6 +755,8 @@ class Server { /* $FlowFixMe: `pathname` could be empty for an invalid URL */ const pathname = decodeURIComponent(urlObj.pathname); + let isMap = false; + // Backwards compatibility. Options used to be as added as '.' to the // entry module name. We can safely remove these options. const entryFile = @@ -761,11 +764,14 @@ class Server { .replace(/^\//, '') .split('.') .filter(part => { + if (part === 'map') { + isMap = true; + return false; + } if ( part === 'includeRequire' || part === 'runModule' || part === 'bundle' || - part === 'map' || part === 'delta' || part === 'assets' ) { @@ -797,12 +803,18 @@ class Server { 'excludeSource', false, ); + const includeSource = this._getBoolOptionFromQuery( + urlObj.query, + 'inlineSourceMap', + false, + ); return { sourceMapUrl: url.format({ ...urlObj, pathname: pathname.replace(/\.(bundle|delta)$/, '.map'), }), + bundleType: isMap ? 'map' : deltaBundleId ? 'delta' : 'bundle', entryFile, deltaBundleId, dev, @@ -811,11 +823,7 @@ class Server { hot: true, runBeforeMainModule: this._opts.getModulesRunBeforeMainModule(entryFile), runModule: this._getBoolOptionFromQuery(urlObj.query, 'runModule', true), - inlineSourceMap: this._getBoolOptionFromQuery( - urlObj.query, - 'inlineSourceMap', - false, - ), + inlineSourceMap: includeSource, isolateModuleIDs: false, platform, resolutionResponse: null, diff --git a/packages/metro-bundler/src/legacy.js b/packages/metro-bundler/src/legacy.js index 0d88234c..4d4ac533 100644 --- a/packages/metro-bundler/src/legacy.js +++ b/packages/metro-bundler/src/legacy.js @@ -112,6 +112,7 @@ exports.build = async function( const result = await server.build({ ...ServerClass.DEFAULT_BUNDLE_OPTIONS, ...assertPublicBundleOptions(bundleOptions), + bundleType: 'todo', }); server.end(); diff --git a/packages/metro-bundler/src/lib/TerminalReporter.js b/packages/metro-bundler/src/lib/TerminalReporter.js index 59a16a49..9b6b3772 100644 --- a/packages/metro-bundler/src/lib/TerminalReporter.js +++ b/packages/metro-bundler/src/lib/TerminalReporter.js @@ -113,7 +113,7 @@ class TerminalReporter { const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH); return ( - chalk.inverse.green.bold(' BUNDLE ') + + chalk.inverse.green.bold(` ${bundleOptions.bundleType.toUpperCase()} `) + chalk.dim(` [${platform}${devOrProd}${min}] ${dirName}/`) + chalk.bold(fileName) + ' ' + diff --git a/packages/metro-bundler/src/shared/output/bundle.js b/packages/metro-bundler/src/shared/output/bundle.js index c758a746..71e5679b 100644 --- a/packages/metro-bundler/src/shared/output/bundle.js +++ b/packages/metro-bundler/src/shared/output/bundle.js @@ -29,6 +29,7 @@ function buildBundle( return packagerClient.build({ ...Server.DEFAULT_BUNDLE_OPTIONS, ...requestOptions, + bundleType: 'bundle', isolateModuleIDs: true, }); } diff --git a/packages/metro-bundler/src/shared/output/unbundle/index.js b/packages/metro-bundler/src/shared/output/unbundle/index.js index f7304dfb..86d333f0 100644 --- a/packages/metro-bundler/src/shared/output/unbundle/index.js +++ b/packages/metro-bundler/src/shared/output/unbundle/index.js @@ -28,6 +28,7 @@ async function buildBundle( const options = { ...Server.DEFAULT_BUNDLE_OPTIONS, ...requestOptions, + bundleType: 'ram', isolateModuleIDs: true, }; return await packagerClient.getRamBundleInfo(options); diff --git a/packages/metro-bundler/src/shared/types.flow.js b/packages/metro-bundler/src/shared/types.flow.js index dab4e529..91fe2c57 100644 --- a/packages/metro-bundler/src/shared/types.flow.js +++ b/packages/metro-bundler/src/shared/types.flow.js @@ -24,10 +24,12 @@ import type {TransformCache} from '../lib/TransformCaching'; import type {Reporter} from '../lib/reporting'; import type {HasteImpl} from '../node-haste/Module'; +type BundleType = 'bundle' | 'delta' | 'map' | 'ram' | 'cli' | 'hmr' | 'todo'; type SourceMapOrMappings = SourceMap | Array; export type BundleOptions = { +assetPlugins: Array, + bundleType: BundleType, dev: boolean, entryFile: string, +entryModuleOnly: boolean,