Summary: Tries to adress https://github.com/facebook/metro/issues/65. We need a reasonnable workaround to support modules like `moment.js` that do dynamic requires but only in some cases. By replacing the call by a function that throws, we move the exception at runtime instead of happening at compile time. We don't want to do that for non-node_modules file because they are fixable directly, while `node_modules` are not fixable by people and they get completely blocked by the error at compile time.
Reviewed By: rafeca
Differential Revision: D6736989
fbshipit-source-id: a6e1fd9b56fa83907400884efd8f8594018b7c37
Summary:
`metro-bundler` v0.21 contains a rewritten bundling mechanism, with simplified logic and much faster rebuild times, called delta bundler. This release contains a couple of breaking changes:
* Now, when using a custom transformer, the list of additional babel plugins to apply are passed to the `transform()` method. These are used in non-dev mode for optimization purposes (Check 367a5f5db8 (diff-40653f0c822ac59a5af13d5b4ab31d84) to see how to handle them from the transformer).
* Now, when using a custom transformer outputting `rawMappings`, the transformer does not need to call the `compactMappings` method before returning (check d74685fd1d (diff-40653f0c822ac59a5af13d5b4ab31d84) for more info).
* We've removed support for two config parameters: `postProcessModules` and `postProcessBundleSourcemap`.
Reviewed By: davidaurelio
Differential Revision: D6186035
fbshipit-source-id: 242c5c2a954c6b9b6f339d345f888eaa44704579
Summary: makes flow typing for the entry point more sound and fixes two issues
Reviewed By: BYK
Differential Revision: D5507650
fbshipit-source-id: 6b03f7de792ffcece4d0d61950e136a61ea7db2e
Summary:
This adds support to RN's configuration file to let people turn off Babel's behavior of looking up .babelrc files. Most of the support for this feature is in Metro (https://github.com/facebook/metro-bundler/pull/31).
Closes https://github.com/facebook/react-native/pull/15136
Differential Revision: D5483241
Pulled By: jeanlauliac
fbshipit-source-id: c78096c1574c9f844c9f34aff73e6f97cb0b5e45
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
Summary:
React Native bundler (aka Metro Bundler) was splitted from the main codebase some time ago (now it lives [[https://github.com/facebook/metro-bundler|here]]). To make it more agnostic, polyfills will be moved out from it, so people who doesn't need them does not include them. However, RN will still need them, so the first step is to copy them back to RN so that we can provide them to Metro Bundler later.
We also include a way of passing the list of polyfills to include, as an `Array<string>`. The field is called `polyfills`, and defaults to the traditional list that is currently included in the package manager [see here](be1843cddc/packages/metro-bundler/src/defaults.js (L27-L37)).
In future commits, `metro-bundler` will be able to manage the `polyfills` array passed to it, and use it, instead of the pre-defined ones.
Reviewed By: davidaurelio
Differential Revision: D5381614
fbshipit-source-id: 749d536b781843ecb3067803e44398cd6df941f1
Summary: Upgrade metro-bundler to v0.9.0. This version has no functional change. The only change is that the structure of the npm package reflects the structure of the source code.
Reviewed By: bestander
Differential Revision: D5315651
fbshipit-source-id: 3a69337106d4ccf708823c80d304941973360e8e
Summary:
This diff cleans up some cruft and adds some features:
* It removes the usage of an env variable to control workers.
* It removes the lazy and handwavy calculation on how many workers to use for jest-haste-map. Jest itself uses the maximum amount of workers available and it has never been reported as an issue – especially since it is a one-time startup cost of about 3 seconds on a cold cache only.
* It adds a `--max-workers` flag to replace the env variable. This one is able to control both the number of workers for `jest-haste-map` as well as the transformers.
* It makes the transformers run in the parent process if 1 or fewer workers are are specified. This should help with debugging.
Once you approve this diff, I will publish a new version of metro to npm and update the version used in RN and remove the use of the env variable altogether: https://our.intern.facebook.com/intern/biggrep/?corpus=xplat&filename=&case=false&view=default&extre=&s=REACT_NATIVE_MAX_WORKERS&engine=apr_strmatch&context=false&filter[uninteresting]=false&filter[intern]=false&filter[test]=false&grep_regex=
Note: the process of adding a CLI option is really broken. Commander also has a weird API. We should consider building a better public API for Metro and then consider how to build a new CLI on top of it and simplify our internal integration. I really don't like how Metro is integrated across pieces of the RN cli in ways that is hard to manage. But that is a larger task for another time :)
Reviewed By: jeanlauliac
Differential Revision: D5217726
fbshipit-source-id: 74efddbb87755a9e744c816fbc62efa21f6a79bf
Summary:
* Internally, we already set up babel before calling into metro-bundler.
* Externally, I moved the setup calls to outside the packager/ folder.
If somebody has a custom integration with RN, they would need to setup babel themselves up until we make the open source split. By the time this is released in open source, an npm version of metro-bundler will be available for use.
Next step: also do this for the worker and remove setupBabel from the metro repo.
Reviewed By: davidaurelio
Differential Revision: D5121429
fbshipit-source-id: e77c6ccc23bef1d13fd74c4727be2d7e09d2d0ca
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
Summary: I'd like to start typing the front-end so that it's easier to track adding new options, etc.
Reviewed By: davidaurelio
Differential Revision: D5069868
fbshipit-source-id: 9a18dca52efd486ca18f17d0ec434a5ec1c1649c
Summary: This makes it easier to verify correctness when adding new config/args.
Reviewed By: davidaurelio
Differential Revision: D5069537
fbshipit-source-id: 4d8058851900b23163d0f2744e91dd14dfcdd461
Summary:
This PR depends on #13172
Packager events are mostly logged through the TerminalReporter by default (#13172 makes this configurable). But there are a few things that aren't passed through TerminalReporter.
- We [log a banner with some information about the port and what's going on](8c7b32d5f1/local-cli/server/server.js (L22-L32))
- Also [a message about looking for JS files](8c7b32d5f1/local-cli/server/server.js (L34-L38)) (not sure what that is for / if it is useful beyond telling the user what directory root they started the packager in, but that's another thing).
- If the packager fails to start, then [we log an error message](8c7b32d5f1/local-cli/server/server.js (L41-L61)).
This pull request changes those log messages to be handled by TerminalReporter. I tri
Closes https://github.com/facebook/react-native/pull/13209
Differential Revision: D4809759
Pulled By: davidaurelio
fbshipit-source-id: 2c427ec0c1accaf54bf6b2d1da882cd6bfaa7829
Summary:
In Expo tools such as XDE, exp we listen listen to stdout from the packager process and print it in our own buffer. In the case of XDE, an electron app, our log pane is DOM-based, and before printing each log chunk we need to remove special tty characters and sometimes parse it to get information that we need (eg: progress bar). By using a custom reporter, we can take the raw events and pass them along in a format that is easy to consume by XDE and exp. This same motivation applies to create-react-native-app, where we currently don't show a progress bar in the terminal, but we can with this change.
Create `LogReporter.js` in the root of a project with the CLI changes included in this PR.
```
class LogReporter {
update(event) {
console.log(JSON.stringify(event));
}
}
module.exports = LogReporter;
```
Now, run `react-native start --customLogReporterPath=LogReporter.js` -- all of the raw events will be output as JSON (while the logs
Closes https://github.com/facebook/react-native/pull/13172
Differential Revision: D4795760
Pulled By: hramos
fbshipit-source-id: 80164b2f30e33a3f9965f4865a8404f8640a52c1
Summary:
Similar to https://github.com/facebook/jest/pull/2877, this introduces an optional config `HasteImpl` of type `{getHasteName(filePath: string): (string|void)}` that returns the haste name for a module at filePath if it is a haste module or undefined otherwise.
This allows us to inject a custom implementation of haste's module id resolution rather than only relying on `providesModule` annotations
Reviewed By: davidaurelio
Differential Revision: D4589372
fbshipit-source-id: 4d1983dfbf09c9d67faf725e86ae86ab42433b7d
Summary:
This moves the `src` directory one level up and removes the `react-packager` folder. Personally, I always disliked this indirection. I'm reorganizing some things in RNP, so this seems to make sense.
Not sure if I forgot to update any paths. Can anyone advice if there are more places that need change?
Reviewed By: jeanlauliac
Differential Revision: D4487867
fbshipit-source-id: d63f9c79d6238300df9632d2e6a4e6a4196d5ccb