diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index 4d9bac42b..60fa76b9b 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -152,12 +152,12 @@ function getPackagerServer(args, config) { blacklistRE: config.getBlacklistRE(), cacheVersion: '3', extraNodeModules: config.extraNodeModules, + getPolyfills: config.getPolyfills, getTransformOptions: config.getTransformOptions, hasteImpl: config.hasteImpl, maxWorkers: args.maxWorkers, platforms: defaultPlatforms.concat(args.platforms), polyfillModuleNames: config.getPolyfillModuleNames(), - getPolyfills: config.getPolyfills, postMinifyProcess: config.postMinifyProcess, postProcessModules: config.postProcessModules, projectRoots: args.projectRoots, diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index 71d58e8cc..f9b16416a 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -13,6 +13,7 @@ const blacklist = require('metro-bundler/src/blacklist'); const findSymlinksPaths = require('./findSymlinksPaths'); const fs = require('fs'); +const getPolyfills = require('../../rn-get-polyfills'); const invariant = require('fbjs/lib/invariant'); const path = require('path'); @@ -94,7 +95,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... */ - getPolyfills: ({platform: string}) => Array, + getPolyfills: ({platform: ?string}) => $ReadOnlyArray, /** * An optional function that can modify the code and source map of bundle @@ -177,17 +178,7 @@ const Config = { getSourceExts: () => [], getTransformModulePath: () => require.resolve('metro-bundler/src/transformer.js'), getTransformOptions: async () => ({}), - getPolyfills: ({platform}) => [ - require.resolve('../../Libraries/polyfills/Object.es6.js'), - require.resolve('../../Libraries/polyfills/console.js'), - require.resolve('../../Libraries/polyfills/error-guard.js'), - require.resolve('../../Libraries/polyfills/Number.es6.js'), - require.resolve('../../Libraries/polyfills/String.prototype.es6.js'), - require.resolve('../../Libraries/polyfills/Array.prototype.es6.js'), - require.resolve('../../Libraries/polyfills/Array.es6.js'), - require.resolve('../../Libraries/polyfills/Object.es7.js'), - require.resolve('../../Libraries/polyfills/babelHelpers.js'), - ], + getPolyfills, postMinifyProcess: x => x, postProcessModules: modules => modules, postProcessModulesForBuck: modules => modules, diff --git a/package.json b/package.json index 251553ab2..c206eedc1 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "jest-preset.json", "jest", "lib", + "rn-get-polyfills.js", "setupBabel.js", "Libraries", "LICENSE", diff --git a/rn-cli.config.js b/rn-cli.config.js index a03254b8b..59ac25a14 100644 --- a/rn-cli.config.js +++ b/rn-cli.config.js @@ -8,6 +8,8 @@ */ 'use strict'; +const getPolyfills = require('./rn-get-polyfills'); + /** * This cli config is needed for development purposes, e.g. for running * integration tests during local development or on CI services. @@ -16,4 +18,5 @@ module.exports = { extraNodeModules: { 'react-native': __dirname, }, + getPolyfills, }; diff --git a/rn-get-polyfills.js b/rn-get-polyfills.js new file mode 100644 index 000000000..a228d6f1f --- /dev/null +++ b/rn-get-polyfills.js @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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. + * + */ + +'use strict'; + +module.exports = () => [ + require.resolve('./Libraries/polyfills/Object.es6.js'), + require.resolve('./Libraries/polyfills/console.js'), + require.resolve('./Libraries/polyfills/error-guard.js'), + require.resolve('./Libraries/polyfills/Number.es6.js'), + require.resolve('./Libraries/polyfills/String.prototype.es6.js'), + require.resolve('./Libraries/polyfills/Array.prototype.es6.js'), + require.resolve('./Libraries/polyfills/Array.es6.js'), + require.resolve('./Libraries/polyfills/Object.es7.js'), + require.resolve('./Libraries/polyfills/babelHelpers.js'), +];