Summary:
After checking more deeply, there were still situations where the delta bundler could generate different bundles between runs: when a module is required by two different modules (it has two or more inverse dependencies), that module would not always be inserted after the first inverse dependency in the bundle, which would cause some bundling order discrepancies.
In order to fix that, the bundler now re-traverses synchronously the dependency graph using a DFS traversing algorithm to guarantee the same order. This will add some small runtime overhead (specially when generating the initial bundle), but it's not worrying (from benchmarks in my macbook pro it'll add ~10ms of initial build for every 1000 modules traversed, being this overhead linear).
Reviewed By: mjesun
Differential Revision: D6124993
fbshipit-source-id: 9bc7cb329f01a7860c7d3b52c3376c643ea5cf3b
Summary:
The `formatBanner.js` file is requiring the `wordwrap` package, but it was not defined in the package.json. Somehow this was working before (maybe the package was being downloaded by another depdendency or maybe `formatBanner` was not used).
This fixes https://github.com/facebook/metro-bundler/issues/79
Reviewed By: mjesun
Differential Revision: D6136865
fbshipit-source-id: 722dd61cb936fca893453f4cfc3248718a329779
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:
**Summary**
I started reading the readme and felt this needed to be done. So I did it 😄
Closes https://github.com/facebook/metro-bundler/pull/75
Differential Revision: D6051094
Pulled By: mjesun
fbshipit-source-id: 373bb58844f36141197625286eb3684eb2de1b1c
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