Skip to content

Commit

Permalink
Change polyfills to getPolyfills function for more configurability
Browse files Browse the repository at this point in the history
Summary:
Changing the `polyfills` option to `getPolyfills({platform})` will let us return a different set of polyfills for each platform. See facebook/metro#25 for the motivation.
Closes #14943

Differential Revision: D5405878

Pulled By: mjesun

fbshipit-source-id: 908e49a286841f97655603d92d0fdfb000547510
  • Loading branch information
ide authored and facebook-github-bot committed Jul 12, 2017
1 parent 999851a commit 9f87728
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion local-cli/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function getPackagerServer(args, config) {
maxWorkers: args.maxWorkers,
platforms: defaultPlatforms.concat(args.platforms),
polyfillModuleNames: config.getPolyfillModuleNames(),
polyfills: config.polyfills,
getPolyfills: config.getPolyfills,
postMinifyProcess: config.postMinifyProcess,
postProcessModules: config.postProcessModules,
projectRoots: args.projectRoots,
Expand Down
5 changes: 3 additions & 2 deletions local-cli/util/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type ConfigT = {
* An optional list of polyfills to include in the bundle. The list defaults
* to a set of common polyfills for Number, String, Array, Object...
*/
polyfills: Array<string>,
getPolyfills: ({platform: string}) => Array<string>,

/**
* An optional function that can modify the code and source map of bundle
Expand Down Expand Up @@ -177,7 +177,7 @@ const Config = {
getSourceExts: () => [],
getTransformModulePath: () => require.resolve('metro-bundler/src/transformer.js'),
getTransformOptions: async () => ({}),
polyfills: [
getPolyfills: ({platform}) => [
require.resolve('../../Libraries/polyfills/Object.es6.js'),
require.resolve('../../Libraries/polyfills/console.js'),
require.resolve('../../Libraries/polyfills/error-guard.js'),
Expand Down Expand Up @@ -239,6 +239,7 @@ const Config = {
},

loadFileCustom<TConfig: {}>(pathToConfig: string, defaults: TConfig): TConfig {
// $FlowFixMe: necessary dynamic require
const config: {} = require(pathToConfig);
return {...defaults, ...config};
},
Expand Down

0 comments on commit 9f87728

Please sign in to comment.