pass polyfillModuleNames into packager

Summary:
After examining how React Native sets up `process.env.NODE_ENV` using `global.__DEV__` from `prelude_dev.js` or `prelude.js` by treating them like polyfills I decided to use the same approach for environment variables. I setup my own rn-project.config.js file like so:

```
const blacklist = require('react-native/packager/blacklist');
const pathJoin = require('path').join;

module.exports = {
  getBlacklistRE: function() {
    return blacklist([/build\/.*/, /app\/assets\/webpack.*/]);
  },
  polyfillModuleNames: [pathJoin(__dirname, 'globals.js')]
};
```

I ran the packaging server using:
`react-native start --config=config/react-native/rn-project.config.js --reset-cache`

I expected my polyfillModuleNames to be passed into the Packager properly and be handled the same way the built-in polyfills worked. Unfortunately I noticed the Packager wasn't actually getting `opt.polyfillModuleNames`. Digging into the code a bit, it seems the local-cli wasn't passing the polyfillModuleNames from the config.

There are no specs for runServer.js but this change can be tested by using a config that contains polyfillModuleNames. Sample config and run command provided above simple `global.js` provided below:

```
global.process = global.process ? global.process : {};
global.process.env = global.process.env ? global.process.env : {};
global.process.env['PROJECT_ENV'] = 'staging';
```
Closes https://github.com/facebook/react-native/pull/13725

Differential Revision: D5077615

Pulled By: jeanlauliac

fbshipit-source-id: f66a8a8bda2702cd9a4e5b92f5335f43ab2f9089
This commit is contained in:
eacaps 2017-05-17 04:56:03 -07:00 committed by Facebook Github Bot
parent c0e8d67e01
commit e53046b9ec
2 changed files with 8 additions and 0 deletions

View File

@ -145,6 +145,7 @@ function getPackagerServer(args, config) {
getTransformOptions: config.getTransformOptions,
hasteImpl: config.hasteImpl,
platforms: defaultPlatforms.concat(args.platforms),
polyfillModuleNames: config.getPolyfillModuleNames(),
postProcessModules: config.postProcessModules,
postMinifyProcess: config.postMinifyProcess,
projectRoots: args.projectRoots,

View File

@ -41,6 +41,12 @@ export type ConfigT = {
*/
getBlacklistRE(): RegExp,
/**
* Specify any additional polyfill modules that should be processed
* before regular module loading.
*/
getPolyfillModuleNames: () => Array<string>,
/**
* Specify any additional platforms to be used by the packager.
* For example, if you want to add a "custom" platform, and use modules
@ -98,6 +104,7 @@ const defaultConfig: ConfigT = {
getAssetExts: () => [],
getBlacklistRE: () => blacklist(),
getPlatforms: () => [],
getPolyfillModuleNames: () => [],
getProjectRoots: () => [process.cwd()],
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
getSourceExts: () => [],