Commit Graph

551 Commits

Author SHA1 Message Date
David Aurelio 2c5a2fec66 fix `$FlowFixMe`
Reviewed By: rafeca

Differential Revision: D6258938

fbshipit-source-id: 7331d0a3216c1714099139fe6c6ab8fe11771fae
2017-11-07 06:22:55 -08:00
Jean Lauliac dbb2d44c42 metro-bundler: collect-dependencies: expose async deps
Summary: To determine whether segment boundaries are properly covered by async imports rather than requires, we need to get knowledge about it higher up in the stack. This changeset exposes which of the dependencies are async as an array of indices within the `dependencies` array (I'd prefer avoiding duplicating the strings because they could get inconsistent, and I don't want to have 2 separate arrays of names either because we'd have to modify a bunch of stuff across the stack to support that).

Reviewed By: davidaurelio

Differential Revision: D6220236

fbshipit-source-id: 1ee36bc7c59f7f27e089f7771a24c45c8bd57b5d
2017-11-06 03:40:10 -08:00
Jean Lauliac 41ec9e6d4d react-native: BundleSegments
Reviewed By: davidaurelio

Differential Revision: D6231309

fbshipit-source-id: 565cbadedc5fd8ab25025b5846c098f24fb15a82
2017-11-06 03:40:10 -08:00
Miguel Jimenez Esun 0a292a2a58 Add code for generating remote assets
Reviewed By: davidaurelio

Differential Revision: D6201839

fbshipit-source-id: 78c81eae03c6137ba9bbe33cd7aab8b87020f8d2
2017-11-03 06:10:20 -07:00
Jia Li 0664367460 Revert D6210177: react-native: BundleSegments
Differential Revision: D6210177

fbshipit-source-id: 8cb4ee37cd03698e9f3980a9819269086a9d6eab
2017-11-02 12:04:31 -07:00
Avik Chaudhuri 4ed2139567 @allow-large-files Flow 0.58 upgrade for xplat/js
Reviewed By: yungsters

Differential Revision: D6219339

fbshipit-source-id: f003111500ef5971b9a95f26d43cee6644c16abe
2017-11-02 10:51:15 -07:00
Jean Lauliac 3129532cd9 react-native: BundleSegments
Reviewed By: davidaurelio

Differential Revision: D6210177

fbshipit-source-id: c39e4118389a9739e9e70ba34feb5d335a7f2546
2017-11-02 09:57:43 -07:00
Miguel Jimenez Esun 1ec323bbd5 Adding @email tags to most of the tests
Reviewed By: rafeca

Differential Revision: D6185623

fbshipit-source-id: 30df83288fe85516d8d5a1617a4fb8fea826ed6f
2017-11-02 06:25:10 -07:00
Rafael Oleza 26718da993 Fix flacky Server-test in metro
Reviewed By: mjesun

Differential Revision: D6220171

fbshipit-source-id: 603671db9a6345dd039c443eb14593e3631c7a88
2017-11-02 06:18:20 -07:00
Rafael Oleza cecb9bae99 Make metro always use the delta bundler
Reviewed By: jeanlauliac

Differential Revision: D6208727

fbshipit-source-id: 08589cc92de340d896833cfee2ed14b48b1e6f38
2017-11-01 20:02:10 -07:00
Rafael Oleza cdfe5b0f20 Remove buildBundle() method from metro public API
Reviewed By: mjesun

Differential Revision: D6208701

fbshipit-source-id: 9e2f20df778cdaad542466692256ca4740a7fb38
2017-11-01 14:53:59 -07:00
Jean Lauliac 64645cbaab react-native: move out the hardcoded import() transform
Reviewed By: davidaurelio

Differential Revision: D6196869

fbshipit-source-id: 237cd269a2f382851102e3e1ba3208f1460f8c0a
2017-11-01 05:36:24 -07:00
Rafael Oleza cd67cd4794 Update shared/output modules to accept the output from the Delta Bundler
Reviewed By: davidaurelio

Differential Revision: D6186386

fbshipit-source-id: 6160f5a02891dbfb56c6350239703ace91e53690
2017-10-31 10:26:10 -07:00
Rafael Oleza ff7ec2e6bf Prepare metro to build production bundles using the Delta Bundler
Reviewed By: davidaurelio

Differential Revision: D6186012

fbshipit-source-id: a9c2757211345881e3feba331bdbe66cdc0f6b97
2017-10-31 10:26:10 -07:00
Rafael Oleza 775867445a Make sourcemap flow types non-nullable
Reviewed By: mjesun

Differential Revision: D6185460

fbshipit-source-id: c33bac5f0e70c142d6238043ce8c2996f1d1ee50
2017-10-31 10:26:10 -07:00
Rafael Oleza 437a6a3f27 Add minify support to the Delta Bundler
Reviewed By: davidaurelio

Differential Revision: D6163566

fbshipit-source-id: d49eab159ee1d1b4453136f21e25e48154d0142a
2017-10-31 10:26:10 -07:00
Rafael Oleza 772d21f72d Move the getAssetData() logic out of the Bundler
Reviewed By: davidaurelio

Differential Revision: D6183424

fbshipit-source-id: 47a658de25ac0943f4b82e7eb90c1018e9d0357d
2017-10-31 09:16:18 -07:00
Rafael Oleza 2850627a66 Add prettier to metro-bundler
Reviewed By: mjesun

Differential Revision: D6187278

fbshipit-source-id: 05b0881743b69c4a1eb491a6f8c57581081a85e4
2017-10-31 03:51:26 -07:00
Jean Lauliac bada7f8684 metro-bundler: ModuleGraph tests: @flow
Summary: Having types in tests ensure that we're testing what the API is supposed to process and not something else. In that case, adding type revealed that we were mistakenly passing strings instead of `Buffer` objects to the transform and optimize functions, but it would still work because `toString` was called over it. Passing proper `Buffer` objects as expected ensures that it doesn't just work with strings, and that the integration of these files in the rest of the application works as expected. This changeset fixes these callsites and add a few invariants here and there. We use `invariant` instead of `expect()` because Flow understands only the former as a type refinement, even though `expect` would also be a form of possible refinement. I don't think it's a big deal.

Reviewed By: davidaurelio

Differential Revision: D6160019

fbshipit-source-id: cbcbb05d7bccf9e1b9f6bb3ea30b0bb2925aef1b
2017-10-30 11:05:13 -07:00
Jean Lauliac c293f4bfab metro-bundler: stricter TransformedCodeFile type and fix use sites
Summary: Here's a good example why Flow "exact types" are useful: there are a few place where we were adding unusused fields in the objects. As these fields end up in JSON files used to communicate with Buck, this can amount to a waste of resources. This changeset make the type exact and removes the unused fields.

Reviewed By: mjesun

Differential Revision: D6159350

fbshipit-source-id: 8cdf29d5729253f119778943ad961eacb8990c04
2017-10-26 07:57:00 -07:00
Rafael Oleza 0e764686e1 Add id to DeltaEntry object
Reviewed By: mjesun

Differential Revision: D6158753

fbshipit-source-id: 5997e36c8d85da750113250e5180a1f54ee14b76
2017-10-26 03:28:55 -07:00
Jean Lauliac e4dad595e1 xplat/js: replace import() calls by require.async() calls
Reviewed By: mjesun

Differential Revision: D6147316

fbshipit-source-id: b93a247ce0830a5db250824d22e81a3b786daf36
2017-10-26 02:21:05 -07:00
Jean Lauliac d01f514fa0 metro-bundler: ModuleGraph: add support for require.async() when collecting dependencies
Summary: This is the last step remaining before enabling the `import()` syntax to use `require.async()` (for now that function is just doing a simple `require()` in behind).

Reviewed By: davidaurelio

Differential Revision: D6147030

fbshipit-source-id: 5cd8ee6cc550816ae3cdea0b457dc2419c99e7a7
2017-10-26 02:21:05 -07:00
Rafael Oleza d74685fd1d Remove compactMapping call from JS transformer
Reviewed By: mjesun

Differential Revision: D6136200

fbshipit-source-id: a38cf19c247f60c0bfee01c39fae070043a76332
2017-10-25 10:28:03 -07:00
Rafael Oleza fa4091c63e Make insertion of modules into the delta structure deterministic
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
2017-10-24 12:28:46 -07:00
Rafael Oleza 0a225fc1e3 Add wordwrap dependency
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
2017-10-24 12:28:46 -07:00
Miguel Jimenez Esun b9023bd626 Backed out changeset c188b39e104f
Reviewed By: fkgozali

Differential Revision: D6111799

fbshipit-source-id: 34213f79135fb605aa2af60182cc1182b10aa602
2017-10-20 12:44:07 -07:00
Rafael Oleza 367a5f5db8 Apply inline code + constant fold transforms when dev is false
Reviewed By: davidaurelio

Differential Revision: D5940962

fbshipit-source-id: 699d45416bade8471164d6ddf5ef3ade535376b3
2017-10-19 18:53:43 -07:00
Miguel Jimenez Esun 0fdf36d06d Support for remote assets
Reviewed By: davidaurelio

Differential Revision: D6030886

fbshipit-source-id: c188b39e104f5c3f65a98336fecbffc93091ff4c
2017-10-19 18:39:49 -07:00
Rafael Oleza 1a2a46a9fb Always set the runBeforeMainModule bundle param on buildBundle()
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
2017-10-18 12:24:26 -07:00
Rafael Oleza 58f3fa957e Make sure that modules not present in the dependency graph are initially required
Reviewed By: davidaurelio

Differential Revision: D6071529

fbshipit-source-id: 916768e85657207d1f7a2bf41d0aa11abd158ee7
2017-10-18 12:24:26 -07:00
Rafael Oleza 941b25a2ca Ignore some irrelevant URL params in order to calculate the bundle cache
Reviewed By: davidaurelio

Differential Revision: D6086420

fbshipit-source-id: 52c1d5dc53d23b3963e663f4033446344b892659
2017-10-18 12:24:26 -07:00
Rafael Oleza e9d2575b26 Make the module ids deterministic between runs
Reviewed By: Hypuk

Differential Revision: D6082114

fbshipit-source-id: fd43b64818a1da192c9252a9d2aed918a130517c
2017-10-18 12:00:07 -07:00
David Aurelio 86ffdae347 Dependencies file: add size as attributes
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
2017-10-17 03:55:26 -07:00
Jean Lauliac 55a22d2c5c metro-bundler/src/ModuleGraph: test image asset transform
Reviewed By: davidaurelio

Differential Revision: D6039836

fbshipit-source-id: 0fc022b72892f8a7064482f63e19b9fa5a3d5b00
2017-10-12 10:01:31 -07:00
Jean Lauliac 0608332cb9 metro-bundler/src/ModuleGraph: throw on empty asset images
Reviewed By: fkgozali

Differential Revision: D6030788

fbshipit-source-id: 000757096f7af68c077e80829f48d52814752599
2017-10-12 10:01:31 -07:00
Kathy Gray 9bb438ed1d Upgrade babel generator
Reviewed By: arcanis

Differential Revision: D6008862

fbshipit-source-id: f8c0bc35d696453fd7cda82ce614d084cbc867e0
2017-10-12 07:52:01 -07:00
Jean Lauliac 6074d897db js1 metro-bundler: add script to publish new version
Reviewed By: davidaurelio

Differential Revision: D6019220

fbshipit-source-id: 97bb53323b29609e192f0e4f4d79b6be6440b98e
2017-10-12 03:23:38 -07:00
Burak Yigit Kaya d1d59d81e5 Show filename and line number on dynamic require errors
Reviewed By: cpojer

Differential Revision: D6008549

fbshipit-source-id: 72fde0a3f97841a020a6fc877f86513e9a7b8521
2017-10-10 06:43:08 -07:00
Burak Yigit Kaya a60ba098c5 Add option for disabling global hot key usage
Reviewed By: mjesun

Differential Revision: D6008860

fbshipit-source-id: 604059e2f2b738e6df2c756f3cdc62981544de64
2017-10-10 03:55:27 -07:00
Burak Yigit Kaya 9f8d4ad4fe Make bablyon parse files in module mode
Reviewed By: davidaurelio

Differential Revision: D6008659

fbshipit-source-id: 6ec3a5e1470e91208a6e71eeca3a2f7c5e755acf
2017-10-09 10:27:46 -07:00
Jani Eväkallio b2002609c1 Fixes Platform.OS and process.env.NODE_ENV inlining resulting in an invalid AST
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
2017-10-09 08:23:04 -07:00
Daniel Mueller 475a580569 Add require.getModules
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
2017-10-09 08:08:43 -07:00
Richard Girges c4307d7170 Prevent error on safely-handled requires using non-static arguments
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
2017-10-09 08:08:43 -07:00
Jean Lauliac 51d4754efc metro-bundler: AmbiguousModuleResolutionError: provide default message
Reviewed By: davidaurelio

Differential Revision: D5986044

fbshipit-source-id: f61d351f91fed3638177bd3c10702f1cb0742a21
2017-10-09 07:45:01 -07:00
Matt Labrum 6c60f61cbd Fix importing a dot file from the root directory doesn't work
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
2017-10-09 05:51:07 -07:00
Zachary Kim d07bfa1532 Whitelist node opt --max-old-space-size for JSTransformer
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
2017-10-09 04:28:39 -07:00
Jean Lauliac 1349edad70 Fix edge case of moving a haste file to a different folder
Reviewed By: davidaurelio

Differential Revision: D5945574

fbshipit-source-id: 5fdd12c0af1b7a92012f4be71ce18f44e42ad4e1
2017-10-05 04:51:40 -07:00
Jean Lauliac e235f6a9fd metro-bundler: writeFile: limit concurrency
Reviewed By: cpojer

Differential Revision: D5975830

fbshipit-source-id: c35be29e8dd64d9653cd24814c5d9f1ef89755dd
2017-10-05 03:27:59 -07:00
Rafael Oleza 6d0c371d65 Handle the case where a file gets modified and deleted afterwards
Reviewed By: jeanlauliac

Differential Revision: D5944099

fbshipit-source-id: 7d41cf849dc53936cb014c44ce02f106853733c6
2017-10-04 04:21:02 -07:00