packager: Server: make buildBundle() async

Summary: Also remove the unnecessary await of the resolver, because `_bundler.bundle()` already does that.

Reviewed By: davidaurelio

Differential Revision: D4689448

fbshipit-source-id: 3b4fd73b1368f8b00c6eb7483e751387d9856ce9
This commit is contained in:
Jean Lauliac 2017-03-13 06:14:34 -07:00 committed by Facebook Github Bot
parent bdacb9595b
commit 915ab18d53
1 changed files with 21 additions and 30 deletions

View File

@ -302,26 +302,18 @@ class Server {
} }
} }
buildBundle(options: { async buildBundle(options: {entryFile: string, platform?: string}): Promise<Bundle> {
entryFile: string,
platform?: string,
}): Promise<Bundle> {
return this._bundler.getResolver().then(() => {
if (!options.platform) { if (!options.platform) {
options.platform = getPlatformExtension(options.entryFile); options.platform = getPlatformExtension(options.entryFile);
} }
const opts = bundleOpts(options); const opts = bundleOpts(options);
return this._bundler.bundle(opts); const bundle = await this._bundler.bundle(opts);
}).then(bundle => {
const modules = bundle.getModules(); const modules = bundle.getModules();
const nonVirtual = modules.filter(m => !m.virtual); const nonVirtual = modules.filter(m => !m.virtual);
bundleDeps.set(bundle, { bundleDeps.set(bundle, {
files: new Map( files: new Map(nonVirtual.map(({sourcePath, meta}) =>
nonVirtual [sourcePath, meta != null ? meta.dependencies : []],
.map(({sourcePath, meta}) => )),
[sourcePath, meta != null ? meta.dependencies : []])
),
idToIndex: new Map(modules.map(({id}, i) => [id, i])), idToIndex: new Map(modules.map(({id}, i) => [id, i])),
dependencyPairs: new Map( dependencyPairs: new Map(
nonVirtual nonVirtual
@ -332,7 +324,6 @@ class Server {
outdated: new Set(), outdated: new Set(),
}); });
return bundle; return bundle;
});
} }
buildBundleFromUrl(reqUrl: string): Promise<mixed> { buildBundleFromUrl(reqUrl: string): Promise<mixed> {