Summary: This diff fixes https://github.com/facebook/metro-bundler/issues/78 by adding the `runBeforeMainModule` server parameter to the bundler. This is not the cleanest solution, but will be fixed once we use the Delta Bundler for builds from the CLI
Reviewed By: davidaurelio
Differential Revision: D6074469
fbshipit-source-id: 068926ef671d9f897ad9f1bd0540036a97340c00
Summary:
Adds module size as `fb_`-prefixed node attributes to the digraph output of dependencies.
The list of edges is now followed by a list of node declarations, that use the `fb_size` attribute to expose the module size in bytes.
E.g:
```
digraph {
"a" -> "b";
"b" -> "c";
"a"[fb_size=123];
"b"[fb_size=456];
"c"[fb_size=789];
}
```
Reviewed By: fkgozali
Differential Revision: D6064861
fbshipit-source-id: 73127e08c5e38075b5112053de12f9abac1102ee
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:
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: 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
Summary:
Changes `LoadFn` to be synchronous or return a promise, and `ResolveFn` to be synchronsous.
This makes for a nicer API, without losing the property of not yielding to the event loop for synchronous work.
Reviewed By: jeanlauliac
Differential Revision: D5855963
fbshipit-source-id: 4b3c3363f4e49a9890586462925e8e400872feb2
Summary: When running with node 8, the babel plugins `async-to-generator` and `syntax-trailing-function-commas` are unnecessary. Removing them makes runtime transpilation faster, and the resulting code is closer to the original (useful with debugging: less unmapped code areas, better breakpoint support, less renamed variables).
Reviewed By: mjesun
Differential Revision: D5842305
fbshipit-source-id: d99f719794e4a8f48fd10b0349fbb36f2994666e
Summary:
This copies the basic loading mechanism and default config from the RN local cli into Metro and exposes it under `metro-bundler`, and switches internal scripts over to it.
davidaurelio: I changed the packager-worker-for-buck to hardcode the rn.cli file, like we do in other files. I would like to pull the "find" mechanism that traverses up to find a config into Metro at some point, but for now I'd prefer to keep it lean until we need it. Let me know if that doesn't work for you.
The next diff will switch the RN cli over to these functions also.
Reviewed By: davidaurelio
Differential Revision: D5832596
fbshipit-source-id: a3e167644d96c8831e5a83378e8ba143e62426db
Summary: As a first step in defining a new public API and CLI for Metro, I'd like to pull the generally useful pieces from the RN cli into Metro. This diff makes it as a non-breaking change (so we don't have to bump the version of Metro for RN) by updating only the imports outside of the react-native-github folder.
Reviewed By: davidaurelio
Differential Revision: D5832464
fbshipit-source-id: 11b00b5517665441763c2207d577ae0e110c681b
Summary: Fixed the UNBUNDLE magic file location to match what JniJSModulesUnbundle.cpp expects.
Reviewed By: sahrens
Differential Revision: D5821637
fbshipit-source-id: 4342e4bb4d139b4eba77dd92a53b1683041fc7e9
Summary:
This diff renames all the stragglers in comments and strings from variations of "packager" to "Metro Bundler". I did one of three:
* Rename "packager" to "Metro Bundler"
* Rename "react-native-packager" to "Metro Bundler"
* Remove "packager" when code inside of Metro implies that it's about Metro
I also removed `Glossary.md` because it is unmaintained and very old. mjesun is currently starting to write documentation for Metro which will supersede whatever was there before.
Reviewed By: mjesun
Differential Revision: D5802993
fbshipit-source-id: ba99cb5ed04d84b0f7b7a8a0bf28ed99280a940a