mirror of https://github.com/status-im/metro.git
Remove buildBundle() method from metro public API
Reviewed By: mjesun Differential Revision: D6208701 fbshipit-source-id: 9e2f20df778cdaad542466692256ca4740a7fb38
This commit is contained in:
parent
64645cbaab
commit
cdfe5b0f20
|
@ -23,7 +23,7 @@ Within the object returned, two main methods are given:
|
||||||
|
|
||||||
## Method `createServer(serverOptions)`
|
## 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
|
```js
|
||||||
|
@ -70,9 +70,9 @@ app.use(
|
||||||
app.listen(8081);
|
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
|
# Available options
|
||||||
|
|
||||||
|
|
|
@ -101,24 +101,23 @@ function assertPublicBundleOptions(bo: mixed): PublicBundleOptions {
|
||||||
return {entryFile, ...bo};
|
return {entryFile, ...bo};
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.buildBundle = function(
|
exports.build = async function(
|
||||||
options: Options,
|
options: Options,
|
||||||
bundleOptions: PublicBundleOptions,
|
bundleOptions: PublicBundleOptions,
|
||||||
) {
|
): Promise<{code: string, map: string}> {
|
||||||
var server = createNonPersistentServer(options);
|
var server = createNonPersistentServer(options);
|
||||||
const ServerClass = require('./Server');
|
const ServerClass = require('./Server');
|
||||||
return server
|
|
||||||
.buildBundle({
|
const result = await server.build({
|
||||||
...ServerClass.DEFAULT_BUNDLE_OPTIONS,
|
...ServerClass.DEFAULT_BUNDLE_OPTIONS,
|
||||||
...assertPublicBundleOptions(bundleOptions),
|
...assertPublicBundleOptions(bundleOptions),
|
||||||
})
|
});
|
||||||
.then(p => {
|
server.end();
|
||||||
server.end();
|
|
||||||
return p;
|
return result;
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getOrderedDependencyPaths = function(
|
exports.getOrderedDependencyPaths = async function(
|
||||||
options: Options,
|
options: Options,
|
||||||
depOptions: {
|
depOptions: {
|
||||||
+entryFile: string,
|
+entryFile: string,
|
||||||
|
@ -127,12 +126,13 @@ exports.getOrderedDependencyPaths = function(
|
||||||
+minify: boolean,
|
+minify: boolean,
|
||||||
+generateSourceMaps: boolean,
|
+generateSourceMaps: boolean,
|
||||||
},
|
},
|
||||||
) {
|
): Promise<Array<string>> {
|
||||||
var server = createNonPersistentServer(options);
|
var server = createNonPersistentServer(options);
|
||||||
return server.getOrderedDependencyPaths(depOptions).then(function(paths) {
|
|
||||||
server.end();
|
const paths = await server.getOrderedDependencyPaths(depOptions);
|
||||||
return paths;
|
server.end();
|
||||||
});
|
|
||||||
|
return paths;
|
||||||
};
|
};
|
||||||
|
|
||||||
function enableDebug() {
|
function enableDebug() {
|
||||||
|
|
|
@ -135,7 +135,7 @@ var Bar = require(5); // 5 = ./Bar
|
||||||
var Foo = require(6); // 6 = ./Foo
|
var Foo = require(6); // 6 = ./Foo
|
||||||
|
|
||||||
module.exports = { Foo: Foo, Bar: Bar };
|
module.exports = { Foo: Foo, Bar: Bar };
|
||||||
}, 0);
|
}, 4);
|
||||||
__d(/* /Bar.js */function(global, require, module, exports) {
|
__d(/* /Bar.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -158,7 +158,7 @@ __d(/* /AssetRegistry.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
}, 8);
|
}, 8);
|
||||||
;require(0);"
|
require(4);"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basic_bundle bundles package without polyfills 1`] = `
|
exports[`basic_bundle bundles package without polyfills 1`] = `
|
||||||
|
@ -280,7 +280,7 @@ var Bar = require(3); // 3 = ./Bar
|
||||||
var Foo = require(4); // 4 = ./Foo
|
var Foo = require(4); // 4 = ./Foo
|
||||||
|
|
||||||
module.exports = { Foo: Foo, Bar: Bar };
|
module.exports = { Foo: Foo, Bar: Bar };
|
||||||
}, 0);
|
}, 2);
|
||||||
__d(/* /Bar.js */function(global, require, module, exports) {
|
__d(/* /Bar.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -303,5 +303,5 @@ __d(/* /AssetRegistry.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
}, 6);
|
}, 6);
|
||||||
;require(0);"
|
require(2);"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -97,7 +97,7 @@ describe('basic_bundle', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('bundles package with polyfills', async () => {
|
it('bundles package with polyfills', async () => {
|
||||||
const bundleWithPolyfills = await Metro.buildBundle(
|
const bundleWithPolyfills = await Metro.build(
|
||||||
{
|
{
|
||||||
assetRegistryPath: ASSET_REGISTRY_PATH,
|
assetRegistryPath: ASSET_REGISTRY_PATH,
|
||||||
getPolyfills: () => [polyfill1, polyfill2],
|
getPolyfills: () => [polyfill1, polyfill2],
|
||||||
|
@ -112,11 +112,11 @@ describe('basic_bundle', () => {
|
||||||
platform: 'ios',
|
platform: 'ios',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
verifyResultCode(bundleWithPolyfills.getSource());
|
verifyResultCode(bundleWithPolyfills.code);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bundles package without polyfills', async () => {
|
it('bundles package without polyfills', async () => {
|
||||||
const bundleWithoutPolyfills = await Metro.buildBundle(
|
const bundleWithoutPolyfills = await Metro.build(
|
||||||
{
|
{
|
||||||
assetRegistryPath: ASSET_REGISTRY_PATH,
|
assetRegistryPath: ASSET_REGISTRY_PATH,
|
||||||
getPolyfills: () => [],
|
getPolyfills: () => [],
|
||||||
|
@ -131,6 +131,6 @@ describe('basic_bundle', () => {
|
||||||
platform: 'ios',
|
platform: 'ios',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
verifyResultCode(bundleWithoutPolyfills.getSource());
|
verifyResultCode(bundleWithoutPolyfills.code);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue