Summary:
Resolves https://github.com/facebook/metro-bundler/issues/27
**Summary**
There is an edge case where tools like react-primitives need to assign to `Platform.OS`,
but the inline transformation results in an invalid AST.
When Platform.OS is unconditionally inlined, the following scenario:
````
Platform.OS = 'ios';
````
Is transformed to:
```
"ios"="ios"
````
And results in error `Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"**`.
See issue in react-primitives: https://github.com/lelandrichardson/react-primitives/issues/79
This patch checks whether the current node is on the left hand side of an AssignmentExpression
and skips the inlining when this is the case.
It also does the same for `process.env.NODE_ENV`, which suffers from the same problem. See related closed issue https://github.com/facebook/react-native/issues/7607#issuecomment-221425153 which was resolved by using bracket notation `process.env["NODE_ENV"]` instead.
**Test plan**
Unit tests included.
**Notes**
This is my first contribution to Metro, and haven't worked with Babel AST a lot, so constructive feedback on the implementation is welcome.
Closes https://github.com/facebook/metro-bundler/pull/45
Reviewed By: cpojer
Differential Revision: D5974615
Pulled By: mjesun
fbshipit-source-id: 224e63cef24f450b33e17ff9c0e0c0cea46bc70e
Summary:
In order to aid with debugging inline requires we add a method that
will give us the modules.
**Summary**
I was looking for a way to see what modules had been loaded when I was working with inline requires. I had tried using beginEvent on Systrace, but I was worried that there were modules that I might have missed (I'm not certain if all the loaded files are polyfills before the entryFile is invoked for instance). By adding getModules() it simplifies seeing what modules are loaded.
**Test plan**
At the root of my app `index.ios.js`:
```
import App from './App';
import { AppRegistry } from 'react-native';
AppRegistry.registerComponent('App', () => App);
// after 3 seconds the initial app data should have loaded, so lets take a look:
setTimeout(() => {
console.log(require.getModules());
}, 3000);
```
**NOTE**
If there is a way to get to this easily (via the debugger or some other mechanism) I would be happy to use that instead and add documentation for it.
Closes https://github.com/facebook/metro-bundler/pull/37
Differential Revision: D6008180
Pulled By: cpojer
fbshipit-source-id: 850103bbce166bf65a0cbd710582198c66273db5
Summary:
**Summary**
This is the workaround that cpojer suggested in #65 and should resolve the biggest pain point that developers are experiencing in that issue: using moment.js in React Native. Hopefully this at least serves as a starting point to reaching a decent solution for libraries using non-static `require()` statements.
**Test plan**
- Expected error when non-static-argument-based `require()` is nested more than one level deep within a `try` statement
- Expected no error when non-static-argument-based `require()` is nested directly within a `try` statement
```bash
ip-192-168-1-10:trueflipapp richard$ react-native bundle --entry-file index.js --platform ios --bundle-output /tmp/test.js --reset-cache
Scanning folders for symlinks in /repo/trueflip/sandbox/code/trueflipapp/node_modules (8ms)
Scanning folders for symlinks in /repo/trueflip/sandbox/code/trueflipapp/node_modules (8ms)
Loading dependency graph, done.
warning: the transform cache was reset.
bundle: start
bundle: finish
bundle: Writing bundle output to: /tmp/test.js
bundle: Done writing bundle output
```
Closes https://github.com/facebook/metro-bundler/pull/69
Differential Revision: D6008567
Pulled By: cpojer
fbshipit-source-id: f9be328cf50dc47c7433ffeb5eb053b398c92122
Summary:
Hi,
**Summary**
This fixes#40 where bundler cannot resolve a file starting with `.` from the root package directory.
it just adds a check to see if the absolute path filename is the same as the localpath filename then lets it through.
**Test plan**
- Steps to reproduce have been written up in #40
Thanks!
Closes https://github.com/facebook/metro-bundler/pull/54
Reviewed By: cpojer
Differential Revision: D5974618
Pulled By: mjesun
fbshipit-source-id: 4b7113c3bed20f2c908739881d61410d651e6ed7
Summary:
Whitelist node opt `--max-old-space-size` for JSTransformer.
Bundling can choke on the default node memory settings for those of us generating large index.js files. This change allows supplied node options to make it through to the node processes spawned by the JSTransformer worker farm.
Closes https://github.com/facebook/metro-bundler/pull/70
Differential Revision: D6008141
Pulled By: cpojer
fbshipit-source-id: 1ef3b436ea30baf3f255a4fd718fe4d958d70c65
Summary:
Add useful information in the README, as an initial first version. Not all of the fields are explained, and we still miss some useful bullet points (e.g. how to release), but that should be good to give some initial guidance as a standalone project.
Closes https://github.com/facebook/metro-bundler/pull/71
Reviewed By: cpojer
Differential Revision: D6008241
Pulled By: mjesun
fbshipit-source-id: b2c4672aee5088e9f4a2b12a225814e7f273f37c
Summary:
Addresses https://github.com/facebook/metro-bundler/issues/62
Apparently with some versions of `jest-haste-map`, the nested source file returns the module wrapped with `default` instead of the exports themselves (due to some ES6 babel transform, I am guessing). I wasn't able to reproduce this myself yet, but I think a good first step is to avoid using nested library files in the first place, ie. only use what's exported at the top-level.
Reviewed By: rafeca
Differential Revision: D5890757
fbshipit-source-id: 1196264b5626eda65c4aae222db2a1620f901c55
Summary:
**Summary**
Without this editors or a globally installed flow would use the latest version.
This ensures that flow uses the right version when checking the code.
**Test plan**
```
$ flow
```
Closes https://github.com/facebook/metro-bundler/pull/53
Reviewed By: jeanlauliac
Differential Revision: D5831038
Pulled By: kassens
fbshipit-source-id: c4a7cac7961b1176e940d86419f7a495e98baf23
Summary: Upgrades uglify to version 3 with (experimental) ES6 support turned on.
Reviewed By: jeanlauliac
Differential Revision: D5842410
fbshipit-source-id: 1c8ccea15785bc5bb1c68d7a83b75881432d0ce2
Summary:
This replaces `async/queue` with a hand-rolled queue that does not yield to the event loop if a unit of work can be run synchronously.
Anecdotally, this leads to a > 11x speedup for the graph traversal when all data is available synchronously, e.g. from an in-memory cache.
Reviewed By: jeanlauliac
Differential Revision: D5861763
fbshipit-source-id: f7cf5f916a13adf9ca418d7522cd2f19df596fba
Summary: Changes `GraphFn` to return a promise rather than taking a callback. This is more in line with call sites, which so far have been using `denodeify`.
Reviewed By: jeanlauliac
Differential Revision: D5857192
fbshipit-source-id: 61bbbef4fbf24b0b91c4a3008541eaa5a1af0f7a