Add prependPolyfills option param to getDependencies()

Reviewed By: jeanlauliac

Differential Revision: D5755548

fbshipit-source-id: 599d3fb6d9acb34f5970ad83947daeb5f28f86d3
This commit is contained in:
Rafael Oleza 2017-09-04 13:42:32 -07:00 committed by Facebook Github Bot
parent 9c251076cf
commit ebb14a56c6
5 changed files with 48 additions and 24 deletions

View File

@ -169,12 +169,22 @@ describe('Bundler', function() {
it('gets the list of dependencies from the resolver', function() {
const entryFile = '/root/foo.js';
return bundler
.getDependencies({entryFile, rootEntryFile: entryFile, recursive: true})
.getDependencies({
entryFile,
rootEntryFile: entryFile,
recursive: true,
prependPolyfills: true,
})
.then(() =>
// jest calledWith does not support jasmine.any
expect(getDependencies.mock.calls[0].slice(0, -2)).toEqual([
'/root/foo.js',
{dev: true, platform: undefined, recursive: true},
{
dev: true,
platform: undefined,
recursive: true,
prependPolyfills: true,
},
{
preloadedModules: undefined,
ramGroups: undefined,

View File

@ -489,6 +489,7 @@ class Bundler {
minify,
isolateModuleIDs,
generateSourceMaps: unbundle || minify || generateSourceMaps,
prependPolyfills: true,
});
}
@ -591,6 +592,7 @@ class Bundler {
hot,
minify,
platform,
prependPolyfills: false,
projectRoots: this._projectRoots,
});
}
@ -618,6 +620,7 @@ class Bundler {
generateSourceMaps = false,
isolateModuleIDs = false,
rootEntryFile,
prependPolyfills,
onProgress,
}: {
entryFile: string,
@ -629,6 +632,7 @@ class Bundler {
generateSourceMaps?: boolean,
isolateModuleIDs?: boolean,
+rootEntryFile: string,
+prependPolyfills: boolean,
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
}): Promise<ResolutionResponse<Module, BundlingOptions>> {
const bundlingOptions: BundlingOptions = await this.getTransformOptions(
@ -641,13 +645,14 @@ class Bundler {
generateSourceMaps,
minify,
projectRoots: this._projectRoots,
prependPolyfills,
},
);
const resolver = await this._resolverPromise;
const response = await resolver.getDependencies(
entryFile,
{dev, platform, recursive},
{dev, platform, recursive, prependPolyfills},
bundlingOptions,
onProgress,
isolateModuleIDs ? createModuleIdFactory() : this._getModuleId,
@ -675,6 +680,7 @@ class Bundler {
platform,
minify,
generateSourceMaps,
prependPolyfills: true,
}).then(({dependencies}) => {
const ret = [];
const promises = [];
@ -873,6 +879,7 @@ class Bundler {
minify: boolean,
platform: ?string,
projectRoots: $ReadOnlyArray<string>,
+prependPolyfills: boolean,
|},
): Promise<BundlingOptions> {
const getDependencies = (entryFile: string) =>

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+javascript_tools
* @format
*/
@ -129,7 +130,7 @@ describe('Resolver', function() {
});
});
it('should pass in more polyfills', function() {
it('should pass in more polyfills when prependPolyfills is true', function() {
expect.assertions(3);
var module = createModule('index');
@ -153,7 +154,7 @@ describe('Resolver', function() {
.then(r =>
r.getDependencies(
'/root/index.js',
{dev: false},
{dev: false, prependPolyfills: true},
undefined,
undefined,
createGetModuleId(),

View File

@ -117,31 +117,36 @@ class Resolver {
return this._depGraph.getModuleForPath(entryFile);
}
getDependencies<T: ContainsTransformerOptions>(
async getDependencies<T: ContainsTransformerOptions>(
entryPath: string,
options: {platform: ?string, recursive?: boolean},
options: {
platform: ?string,
recursive?: boolean,
prependPolyfills: boolean,
},
bundlingOptions: T,
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
getModuleId: mixed,
): Promise<ResolutionResponse<Module, T>> {
const {platform, recursive = true} = options;
return this._depGraph
.getDependencies({
entryPath,
platform,
options: bundlingOptions,
recursive,
onProgress,
})
.then(resolutionResponse => {
this._getPolyfillDependencies(platform)
.reverse()
.forEach(polyfill => resolutionResponse.prependDependency(polyfill));
const {platform, recursive = true, prependPolyfills} = options;
/* $FlowFixMe: monkey patching */
resolutionResponse.getModuleId = getModuleId;
return resolutionResponse.finalize();
});
const resolutionResponse = await this._depGraph.getDependencies({
entryPath,
platform,
options: bundlingOptions,
recursive,
onProgress,
});
if (prependPolyfills) {
this._getPolyfillDependencies(platform)
.reverse()
.forEach(polyfill => resolutionResponse.prependDependency(polyfill));
}
/* $FlowFixMe: monkey patching */
resolutionResponse.getModuleId = getModuleId;
return resolutionResponse.finalize();
}
getModuleSystemDependencies({dev = true}: {dev?: boolean}): Array<Module> {

View File

@ -386,6 +386,7 @@ class Server {
hot,
generateSourceMaps: false,
rootEntryFile,
prependPolyfills: true,
});
});
}