Remove buildBundle() method from metro public API

Reviewed By: mjesun

Differential Revision: D6208701

fbshipit-source-id: 9e2f20df778cdaad542466692256ca4740a7fb38
This commit is contained in:
Rafael Oleza 2017-11-01 14:49:05 -07:00 committed by Facebook Github Bot
parent 64645cbaab
commit cdfe5b0f20
4 changed files with 28 additions and 28 deletions

View File

@ -23,7 +23,7 @@ Within the object returned, two main methods are given:
## Method `createServer(serverOptions)`
Given a set of options (same ones as the `buildBundle`, a `metro-server` will be returned. You can then hook this into a proper HTTP(S) server by using its `processRequest` method:
Given a set of options (same ones as the `build` method), a `metro-server` will be returned. You can then hook this into a proper HTTP(S) server by using its `processRequest` method:
```js
@ -70,9 +70,9 @@ app.use(
app.listen(8081);
```
## Method `buildBundle(serverOptions, bundleOptions)`
## Method `build(serverOptions, bundleOptions)`
Given a set of options that you would typically pass to a server, plus a set of options specific to the bundle itself, a bundle will be built. This is useful at build time.
Given a set of options that you would typically pass to a server, plus a set of options specific to the bundle itself, a bundle will be built. The return value is a Promise that resolves to an object with two properties, `code` and `map`. This is useful at build time.
# Available options

View File

@ -101,24 +101,23 @@ function assertPublicBundleOptions(bo: mixed): PublicBundleOptions {
return {entryFile, ...bo};
}
exports.buildBundle = function(
exports.build = async function(
options: Options,
bundleOptions: PublicBundleOptions,
) {
): Promise<{code: string, map: string}> {
var server = createNonPersistentServer(options);
const ServerClass = require('./Server');
return server
.buildBundle({
...ServerClass.DEFAULT_BUNDLE_OPTIONS,
...assertPublicBundleOptions(bundleOptions),
})
.then(p => {
server.end();
return p;
});
const result = await server.build({
...ServerClass.DEFAULT_BUNDLE_OPTIONS,
...assertPublicBundleOptions(bundleOptions),
});
server.end();
return result;
};
exports.getOrderedDependencyPaths = function(
exports.getOrderedDependencyPaths = async function(
options: Options,
depOptions: {
+entryFile: string,
@ -127,12 +126,13 @@ exports.getOrderedDependencyPaths = function(
+minify: boolean,
+generateSourceMaps: boolean,
},
) {
): Promise<Array<string>> {
var server = createNonPersistentServer(options);
return server.getOrderedDependencyPaths(depOptions).then(function(paths) {
server.end();
return paths;
});
const paths = await server.getOrderedDependencyPaths(depOptions);
server.end();
return paths;
};
function enableDebug() {

View File

@ -135,7 +135,7 @@ var Bar = require(5); // 5 = ./Bar
var Foo = require(6); // 6 = ./Foo
module.exports = { Foo: Foo, Bar: Bar };
}, 0);
}, 4);
__d(/* /Bar.js */function(global, require, module, exports) {
'use strict';
@ -158,7 +158,7 @@ __d(/* /AssetRegistry.js */function(global, require, module, exports) {
'use strict';
}, 8);
;require(0);"
require(4);"
`;
exports[`basic_bundle bundles package without polyfills 1`] = `
@ -280,7 +280,7 @@ var Bar = require(3); // 3 = ./Bar
var Foo = require(4); // 4 = ./Foo
module.exports = { Foo: Foo, Bar: Bar };
}, 0);
}, 2);
__d(/* /Bar.js */function(global, require, module, exports) {
'use strict';
@ -303,5 +303,5 @@ __d(/* /AssetRegistry.js */function(global, require, module, exports) {
'use strict';
}, 6);
;require(0);"
require(2);"
`;

View File

@ -97,7 +97,7 @@ describe('basic_bundle', () => {
}
it('bundles package with polyfills', async () => {
const bundleWithPolyfills = await Metro.buildBundle(
const bundleWithPolyfills = await Metro.build(
{
assetRegistryPath: ASSET_REGISTRY_PATH,
getPolyfills: () => [polyfill1, polyfill2],
@ -112,11 +112,11 @@ describe('basic_bundle', () => {
platform: 'ios',
},
);
verifyResultCode(bundleWithPolyfills.getSource());
verifyResultCode(bundleWithPolyfills.code);
});
it('bundles package without polyfills', async () => {
const bundleWithoutPolyfills = await Metro.buildBundle(
const bundleWithoutPolyfills = await Metro.build(
{
assetRegistryPath: ASSET_REGISTRY_PATH,
getPolyfills: () => [],
@ -131,6 +131,6 @@ describe('basic_bundle', () => {
platform: 'ios',
},
);
verifyResultCode(bundleWithoutPolyfills.getSource());
verifyResultCode(bundleWithoutPolyfills.code);
});
});