Skip to content

Commit 0bbd9f0

Browse files
rafecafacebook-github-bot
authored andcommitted
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 facebook/metro@367a5f5#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 facebook/metro@d74685f#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
1 parent 963c61d commit 0bbd9f0

File tree

5 files changed

+28
-42
lines changed

5 files changed

+28
-42
lines changed

local-cli/bundle/buildBundle.js

+18-27
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,7 @@ const {ASSET_REGISTRY_PATH} = require('../core/Constants');
4848
import type {RequestOptions, OutputOptions} from './types.flow';
4949
import type {ConfigT} from 'metro-bundler';
5050

51-
function saveBundle(output, bundle, args) {
52-
return Promise.resolve(
53-
/* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an
54-
* error found when Flow v0.56 was deployed. To see the error delete this
55-
* comment and run Flow. */
56-
output.save(bundle, args, log)
57-
).then(() => bundle);
58-
}
59-
60-
function buildBundle(
51+
async function buildBundle(
6152
args: OutputOptions & {
6253
assetsDest: mixed,
6354
entryFile: string,
@@ -129,7 +120,6 @@ function buildBundle(
129120
sourceExts: defaultSourceExts.concat(sourceExts),
130121
transformCache: TransformCaching.useTempDir(),
131122
transformModulePath: transformModulePath,
132-
useDeltaBundler: false,
133123
watch: false,
134124
workerPath: config.getWorkerPath && config.getWorkerPath(),
135125
};
@@ -138,26 +128,27 @@ function buildBundle(
138128
shouldClosePackager = true;
139129
}
140130

141-
const bundlePromise = output.build(packagerInstance, requestOpts)
142-
.then(bundle => {
143-
if (shouldClosePackager) {
144-
packagerInstance.end();
145-
}
146-
return saveBundle(output, bundle, args);
147-
});
131+
const bundle = await output.build(packagerInstance, requestOpts);
132+
133+
await output.save(bundle, args, log);
148134

149135
// Save the assets of the bundle
150-
const assets = bundlePromise
151-
// TODO: Use the packager.getAssets() method to get the bundle assets.
152-
// $FlowFixMe: This code is going away.
153-
.then(bundle => bundle.getAssets && bundle.getAssets())
154-
.then(outputAssets => outputAssets && saveAssets(
155-
outputAssets,
156-
args.platform,
157-
args.assetsDest,
158-
));
136+
const outputAssets = await packagerInstance.getAssets({
137+
...Server.DEFAULT_BUNDLE_OPTIONS,
138+
...requestOpts,
139+
});
159140

160141
// When we're done saving bundle output and the assets, we're done.
142+
const assets = await saveAssets(
143+
outputAssets,
144+
args.platform,
145+
args.assetsDest,
146+
);
147+
148+
if (shouldClosePackager) {
149+
packagerInstance.end();
150+
}
151+
161152
return assets;
162153
}
163154

local-cli/server/middleware/getDevToolsMiddleware.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ function escapePath(pathname) {
2525
return '"' + pathname + '"';
2626
}
2727

28-
function launchDevTools(
29-
{port, projectRoots, useDeltaBundler},
30-
isChromeConnected,
31-
) {
28+
function launchDevTools({port, projectRoots}, isChromeConnected) {
3229
// Explicit config always wins
3330
var customDebugger = process.env.REACT_DEBUGGER;
3431
if (customDebugger) {
@@ -42,7 +39,7 @@ function launchDevTools(
4239
});
4340
} else if (!isChromeConnected()) {
4441
// Dev tools are not yet open; we need to open a session
45-
launchChromeDevTools(port, useDeltaBundler ? '#useDeltaBundler' : '');
42+
launchChromeDevTools(port);
4643
}
4744
}
4845

local-cli/server/runServer.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ require('../../setupBabel')();
1717
* found when Flow v0.54 was deployed. To see the error delete this comment and
1818
* run Flow. */
1919
const ReactPackager = require('metro-bundler');
20+
21+
const HmrServer = require('metro-bundler/src/HmrServer');
22+
2023
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
2124
* found when Flow v0.54 was deployed. To see the error delete this comment and
2225
* run Flow. */
2326
const Terminal = require('metro-bundler/src/lib/Terminal');
2427

25-
const attachHMRServer = require('./util/attachHMRServer');
28+
const attachWebsocketServer = require('./util/attachWebsocketServer');
2629
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
2730
* found when Flow v0.54 was deployed. To see the error delete this comment and
2831
* run Flow. */
@@ -131,10 +134,10 @@ function runServer(
131134
: http.createServer(app);
132135

133136
serverInstance.listen(args.port, args.host, 511, function() {
134-
attachHMRServer({
137+
attachWebsocketServer({
135138
httpServer: serverInstance,
136139
path: '/hot',
137-
packagerServer,
140+
websocketServer: new HmrServer(packagerServer, reporter),
138141
});
139142

140143
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
@@ -200,7 +203,6 @@ function getPackagerServer(args, config, reporter) {
200203
sourceExts: defaultSourceExts.concat(args.sourceExts),
201204
transformModulePath: transformModulePath,
202205
transformCache: TransformCaching.useTempDir(),
203-
useDeltaBundler: false,
204206
verbose: args.verbose,
205207
watch: !args.nonPersistent,
206208
workerPath: config.getWorkerPath(),

local-cli/server/util/debugger-ui/index.html

-4
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@
206206
connectToDebuggerProxy();
207207

208208
async function getBlobUrl(url) {
209-
if (window.location.hash.indexOf('useDeltaBundler') === -1) {
210-
return url;
211-
}
212-
213209
return await window.deltaUrlToBlobUrl(url.replace('.bundle', '.delta'));
214210
}
215211
})();

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
"graceful-fs": "^4.1.3",
173173
"inquirer": "^3.0.6",
174174
"lodash": "^4.16.6",
175-
"metro-bundler": "^0.20.0",
175+
"metro-bundler": "^0.21.0",
176176
"mime": "^1.3.4",
177177
"minimist": "^1.2.0",
178178
"mkdirp": "^0.5.1",
@@ -216,4 +216,4 @@
216216
"shelljs": "^0.7.8",
217217
"sinon": "^2.2.0"
218218
}
219-
}
219+
}

0 commit comments

Comments
 (0)