Skip to content

Commit

Permalink
Move Array<string> to $ReadOnlyArray<string>. Separate polyfill list …
Browse files Browse the repository at this point in the history
…into a file.

Summary: Move the returned type of `getPolyfills` from a standard `Array` to a read-only one, so that we make sure the array is not modified once created. Also, refactor the list of polyfills included by default to a generic, central file, then require it both from the CLI utils as well as the development server.

Reviewed By: jeanlauliac

Differential Revision: D5406553

fbshipit-source-id: ab980288bb1c625338de469da77dd6fc70bcedbc
  • Loading branch information
Miguel Jimenez Esun authored and facebook-github-bot committed Jul 13, 2017
1 parent cad2d9b commit 6dd9d16
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion local-cli/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 3 additions & 12 deletions local-cli/util/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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<string>,
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,

/**
* An optional function that can modify the code and source map of bundle
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"jest-preset.json",
"jest",
"lib",
"rn-get-polyfills.js",
"setupBabel.js",
"Libraries",
"LICENSE",
Expand Down
3 changes: 3 additions & 0 deletions rn-cli.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -16,4 +18,5 @@ module.exports = {
extraNodeModules: {
'react-native': __dirname,
},
getPolyfills,
};
23 changes: 23 additions & 0 deletions rn-get-polyfills.js
Original file line number Diff line number Diff line change
@@ -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'),
];

0 comments on commit 6dd9d16

Please sign in to comment.