From 0bbd9f042a8ad7c7be094bd7636ca767c6f7b231 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Wed, 8 Nov 2017 09:07:41 -0800 Subject: [PATCH] BREAKING: Bump metro-bundler to v0.21.0 Summary: `metro-bundler` v0.21 contains a rewritten bundling mechanism, with simplified logic and much faster rebuild times, called delta bundler. This release contains a couple of breaking changes: * Now, when using a custom transformer, the list of additional babel plugins to apply are passed to the `transform()` method. These are used in non-dev mode for optimization purposes (Check https://github.com/facebook/metro-bundler/commit/367a5f5db805a9445e6f07ba9551d4fba259d1c7#diff-40653f0c822ac59a5af13d5b4ab31d84 to see how to handle them from the transformer). * Now, when using a custom transformer outputting `rawMappings`, the transformer does not need to call the `compactMappings` method before returning (check https://github.com/facebook/metro-bundler/commit/d74685fd1d292cde18ee332e835921a99b0c0d66#diff-40653f0c822ac59a5af13d5b4ab31d84 for more info). * We've removed support for two config parameters: `postProcessModules` and `postProcessBundleSourcemap`. Reviewed By: davidaurelio Differential Revision: D6186035 fbshipit-source-id: 242c5c2a954c6b9b6f339d345f888eaa44704579 --- local-cli/bundle/buildBundle.js | 45 ++++++++----------- .../middleware/getDevToolsMiddleware.js | 7 +-- local-cli/server/runServer.js | 10 +++-- local-cli/server/util/debugger-ui/index.html | 4 -- package.json | 4 +- 5 files changed, 28 insertions(+), 42 deletions(-) diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index 0943ebd4b..1e9406837 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -48,16 +48,7 @@ const {ASSET_REGISTRY_PATH} = require('../core/Constants'); import type {RequestOptions, OutputOptions} from './types.flow'; import type {ConfigT} from 'metro-bundler'; -function saveBundle(output, bundle, args) { - return Promise.resolve( - /* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ - output.save(bundle, args, log) - ).then(() => bundle); -} - -function buildBundle( +async function buildBundle( args: OutputOptions & { assetsDest: mixed, entryFile: string, @@ -129,7 +120,6 @@ function buildBundle( sourceExts: defaultSourceExts.concat(sourceExts), transformCache: TransformCaching.useTempDir(), transformModulePath: transformModulePath, - useDeltaBundler: false, watch: false, workerPath: config.getWorkerPath && config.getWorkerPath(), }; @@ -138,26 +128,27 @@ function buildBundle( shouldClosePackager = true; } - const bundlePromise = output.build(packagerInstance, requestOpts) - .then(bundle => { - if (shouldClosePackager) { - packagerInstance.end(); - } - return saveBundle(output, bundle, args); - }); + const bundle = await output.build(packagerInstance, requestOpts); + + await output.save(bundle, args, log); // Save the assets of the bundle - const assets = bundlePromise - // TODO: Use the packager.getAssets() method to get the bundle assets. - // $FlowFixMe: This code is going away. - .then(bundle => bundle.getAssets && bundle.getAssets()) - .then(outputAssets => outputAssets && saveAssets( - outputAssets, - args.platform, - args.assetsDest, - )); + const outputAssets = await packagerInstance.getAssets({ + ...Server.DEFAULT_BUNDLE_OPTIONS, + ...requestOpts, + }); // When we're done saving bundle output and the assets, we're done. + const assets = await saveAssets( + outputAssets, + args.platform, + args.assetsDest, + ); + + if (shouldClosePackager) { + packagerInstance.end(); + } + return assets; } diff --git a/local-cli/server/middleware/getDevToolsMiddleware.js b/local-cli/server/middleware/getDevToolsMiddleware.js index f2ad3191e..4f90d2853 100644 --- a/local-cli/server/middleware/getDevToolsMiddleware.js +++ b/local-cli/server/middleware/getDevToolsMiddleware.js @@ -25,10 +25,7 @@ function escapePath(pathname) { return '"' + pathname + '"'; } -function launchDevTools( - {port, projectRoots, useDeltaBundler}, - isChromeConnected, -) { +function launchDevTools({port, projectRoots}, isChromeConnected) { // Explicit config always wins var customDebugger = process.env.REACT_DEBUGGER; if (customDebugger) { @@ -42,7 +39,7 @@ function launchDevTools( }); } else if (!isChromeConnected()) { // Dev tools are not yet open; we need to open a session - launchChromeDevTools(port, useDeltaBundler ? '#useDeltaBundler' : ''); + launchChromeDevTools(port); } } diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index fc93ca7da..05e743f43 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -17,12 +17,15 @@ require('../../setupBabel')(); * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ const ReactPackager = require('metro-bundler'); + +const HmrServer = require('metro-bundler/src/HmrServer'); + /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ const Terminal = require('metro-bundler/src/lib/Terminal'); -const attachHMRServer = require('./util/attachHMRServer'); +const attachWebsocketServer = require('./util/attachWebsocketServer'); /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ @@ -131,10 +134,10 @@ function runServer( : http.createServer(app); serverInstance.listen(args.port, args.host, 511, function() { - attachHMRServer({ + attachWebsocketServer({ httpServer: serverInstance, path: '/hot', - packagerServer, + websocketServer: new HmrServer(packagerServer, reporter), }); wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy'); @@ -200,7 +203,6 @@ function getPackagerServer(args, config, reporter) { sourceExts: defaultSourceExts.concat(args.sourceExts), transformModulePath: transformModulePath, transformCache: TransformCaching.useTempDir(), - useDeltaBundler: false, verbose: args.verbose, watch: !args.nonPersistent, workerPath: config.getWorkerPath(), diff --git a/local-cli/server/util/debugger-ui/index.html b/local-cli/server/util/debugger-ui/index.html index f8867f5bc..c21a21892 100644 --- a/local-cli/server/util/debugger-ui/index.html +++ b/local-cli/server/util/debugger-ui/index.html @@ -206,10 +206,6 @@ connectToDebuggerProxy(); async function getBlobUrl(url) { - if (window.location.hash.indexOf('useDeltaBundler') === -1) { - return url; - } - return await window.deltaUrlToBlobUrl(url.replace('.bundle', '.delta')); } })(); diff --git a/package.json b/package.json index 86c89af14..364ce0fa0 100644 --- a/package.json +++ b/package.json @@ -172,7 +172,7 @@ "graceful-fs": "^4.1.3", "inquirer": "^3.0.6", "lodash": "^4.16.6", - "metro-bundler": "^0.20.0", + "metro-bundler": "^0.21.0", "mime": "^1.3.4", "minimist": "^1.2.0", "mkdirp": "^0.5.1", @@ -216,4 +216,4 @@ "shelljs": "^0.7.8", "sinon": "^2.2.0" } -} \ No newline at end of file +}