Commit Graph

577 Commits

Author SHA1 Message Date
Maël Nison c6b0134398 Removes debug
Reviewed By: rafeca

Differential Revision: D6358889

fbshipit-source-id: f04a6dd33dac72d0ad9ceb56c49215ebc53452ff
2017-11-17 07:51:46 -08:00
Jean Lauliac f0a4418b5b metro-bundler: ModuleGraph: nit: reduce code nesting
Reviewed By: davidaurelio

Differential Revision: D6324409

fbshipit-source-id: da7626772cb24b4f3749962e72e5952982b917d6
2017-11-15 06:22:04 -08:00
Rafael Oleza c04393b397 Fix sending multipart delta responses
Reviewed By: jeanlauliac

Differential Revision: D6328147

fbshipit-source-id: fcd16e64180a49bad0a0c606ab0f2bdd2d9ac0ee
2017-11-15 03:06:04 -08:00
Jean Lauliac 56e790f958 metro-bundler: ModuleGraph: fix in-memory node-haste impl error
Reviewed By: cpojer

Differential Revision: D6323532

fbshipit-source-id: 067be85171d8d8839c977bd2aa7fdc7efc178f0a
2017-11-14 06:08:17 -08:00
Benjamin Weggersen b75f385524 Normalize module name to have platform specific folder separators
Summary:
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. -->

**Summary**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

It is currently not possible to resolve specific module imports (such as `react-native/Libraries/Image/AssetRegistry` using forward slashes as folder separators) using a custom mapping defined in `extraNodeModules` on Windows. This PR solves this issue by normalizing module names to use platform-specific folder separators before splitting the module name using `path.sep` as separators.

**Test plan**

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->

We use `extraNodeModules` to create a mapping between `react-native` and a forked and scoped version of react-native (i.e. `scope/react-native`). If we import a specific file from react-native (such as [`react-native/Libraries/Image/AssetRegistry`](https://github.com/facebook/react-native/blob/master/local-cli/core/Constants.js), which gets referenced when importing image assets), `ModuleResolution.js` is not able to extract the first folder name on Windows. This first folder name is the name of the module (`react-native` in the previous example) and is used to query `extraNodeModules` for possible matches. It is not able to find this folder name because the module name is split using `path.sep` as a separator, which is `'\\'` on Windows. Most module names use forward slashes as folder separators. The solution is to normalize `toModuleName` before we split on `path.sep`.
Closes https://github.com/facebook/metro-bundler/pull/89

Differential Revision: D6312391

Pulled By: jeanlauliac

fbshipit-source-id: 920c52633e8c9584ecb2bdd309dc4a8516c3199b
2017-11-14 02:52:35 -08:00
Maël Nison 1bd30c977d Adds an experimental metro-cli to metro-bundler
Reviewed By: davidaurelio

Differential Revision: D6129384

fbshipit-source-id: b32049ad17aeae74cde23dbaa79845e6a4a51507
2017-11-13 17:36:35 -08:00
Rafael Oleza e1b5fe79fa Remove ModuleTransport/ResolutionResponse modules and lots of logic from Resolver/ResolutionRequest
Reviewed By: davidaurelio

Differential Revision: D6284728

fbshipit-source-id: 53d27cd65b8c96ed6d6872eb16a9b5d1e14db85e
2017-11-13 16:43:36 -08:00
Rafael Oleza 860dcc4867 Use current DependencyGraph tests as integration tests for the traverseDependency logic
Reviewed By: davidaurelio

Differential Revision: D6284627

fbshipit-source-id: 7e3f21c53142238f7d50444627c417388a4c1d1d
2017-11-13 16:43:36 -08:00
Rafael Oleza f1728e4c7b Add support for the postProcessModules param
Reviewed By: davidaurelio

Differential Revision: D6277777

fbshipit-source-id: b9a0341f17f3829ccc3daf7db89275f07e435803
2017-11-13 16:43:36 -08:00
Caleb Meredith 42a547551f Flow 0.59 xplat/js deploy
Reviewed By: avikchaudhuri

Differential Revision: D6300238

fbshipit-source-id: a6839fa2a9bbc50c3832a3f5b1cac2a6d2bd96b7
2017-11-10 21:12:40 -08:00
Rafael Oleza 1dec296000 Downgrade uglify-js from 3.1.8 to 3.1.1
Summary:
Uglify@3.1.7 is causing some perf issues (more specifically, this commit: 5b4b07e9a7) that are impacting TTI on RN views and increased memory usage.

More specifically, code like:

```
function nonTrivialFn(pre) {
  return pre + Math.random();
}
function hotFunctionCalledALotOfTimes(num) {
  return nonTrivialFn(num + Math.random());
}
hotFunctionCalledALotOfTimes(3);
hotFunctionCalledALotOfTimes(5);
```

in v3.1.7 gets converted to:

```
function hotFunctionCalledALotOfTimes(num){
  return function(pre) {
    return pre + Math.random();
  }(num + Math.random())
}
hotFunctionCalledALotOfTimes(3);
hotFunctionCalledALotOfTimes(5);
```

This causes a function creation each time `hotFunctionCalledALotOfTimes` is called.

By comparison, in v3.1.6, that previous code was converted to:

```
function nonTrivialFn(pre){
  return pre + Math.random()
}
function hotFunctionCalledALotOfTimes(num){
  return nonTrivialFn(num + Math.random())
}
hotFunctionCalledALotOfTimes(3);
hotFunctionCalledALotOfTimes(5);
```

Reviewed By: jeanlauliac, alexeylang

Differential Revision: D6296740

fbshipit-source-id: b3988d886e607103ec3ae6b9763b2f0411a8aa3c
2017-11-10 04:52:50 -08:00
Miguel Jimenez Esun e08b34239e Add asset size to the module
Reviewed By: jeanlauliac

Differential Revision: D6284248

fbshipit-source-id: 3b860d7b123a1d2470c7b6c7e9e9082d0622c369
2017-11-10 03:20:52 -08:00
Rafael Oleza e7b4e50813 Fix flow types of sourcemaps
Reviewed By: davidaurelio

Differential Revision: D6271757

fbshipit-source-id: abf9c91a4ebd36eb4cd77acf75c40f85fbecd5f9
2017-11-08 13:03:43 -08:00
Rafael Oleza 7b93876541 Remove old Bundler/* logic
Reviewed By: mjesun

Differential Revision: D6259048

fbshipit-source-id: b39e4c602a0af9d2ad91b72a699b1369526ac9f2
2017-11-08 13:03:43 -08:00
Rafael Oleza 2eefccc72a Remove old bundler code from Server class
Reviewed By: mjesun

Differential Revision: D6255868

fbshipit-source-id: 74695129199c8be43e13c97f2ae2ca2c03b801eb
2017-11-08 13:03:43 -08:00
Rafael Oleza 8f45fb6bf3 BREAKING: Bump metro-bundler to v0.21.0
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
2017-11-08 09:20:17 -08:00
Rafael Oleza 08ed373a60 Add postMinifyModule param support to Delta Bundler
Reviewed By: mjesun

Differential Revision: D6264450

fbshipit-source-id: 1dd0bc8c5957d99b6f4b6722c843fe9cc284ec3a
2017-11-08 07:07:46 -08:00
Rafael Oleza 98518c9fff Add ramGroups and preloadedModules support when creating RAM bundles
Reviewed By: davidaurelio

Differential Revision: D6250307

fbshipit-source-id: b7143fa31ded9fcaa28025f05b9d28013361ea0e
2017-11-08 07:07:46 -08:00
Miguel Jimenez Esun 91f724d69d Update Jest to 21.3.0-beta.8
Reviewed By: davidaurelio

Differential Revision: D6221784

fbshipit-source-id: 189e895378635dd21d14d6fb1f93510a52c90742
2017-11-08 06:50:53 -08:00
Rafael Oleza ed55e0a53f Remove cyclic dependency when getting the transform options
Reviewed By: davidaurelio

Differential Revision: D6231766

fbshipit-source-id: ae200a4507febcd47bcc636d0e62f01eb6a93477
2017-11-08 04:07:07 -08:00
Andreas Amsenius b0c79aa193 Upgrade uglify-es to fix minification issues
Summary:
**Summary**

Minification fails or minified bundle may crash due to uglify-es bugs which have been fixed recently. See https://github.com/facebook/react-native/issues/16689

**Test plan**

Try to production bundle a project using ex-navigation, which fails with:
```
Maximum call stack size exceeded
```

Use this patch and see that bundling suceeds. There are also minified runtime errors solved by this change, see https://github.com/facebook/react-native/issues/16689 for more information.
Closes https://github.com/facebook/metro-bundler/pull/85

Reviewed By: mjesun

Differential Revision: D6259177

Pulled By: rafeca

fbshipit-source-id: 55987eb338b06938181c0da74d104d23eeb135b6
2017-11-07 08:28:17 -08:00
Rafael Oleza 8fe2d588bc Use Delta Bundler to get all bundle assets
Reviewed By: mjesun

Differential Revision: D6255563

fbshipit-source-id: fe08021ef6be8528ddcbb553be62e8a8cf2bcf0a
2017-11-07 08:10:32 -08:00
Miguel Jimenez Esun d4dcd4c6fa Migrate metro-bundler to jest-worker
Summary:
This diff migrates Metro Bundler from `worker-farm` to `jest-worker`:

* Fully removes the custom patched `worker-farm` fork.
* Removes //a lot// of non-clear Flow types used to cast functions from callbacks to promises.
* Reduces cyclomatic complexity of the `Transformer` class by using `async`/`await`.
* Cleans all additional methods inside `JSTransformer/index.js`, by moving them to a single class and properly scoping them.

**Note:**  this diff does not still enable the ability to bind files to workers by using `computeWorkerKey`; this will come at a later stage.

Reviewed By: davidaurelio

Differential Revision: D6247532

fbshipit-source-id: 51259360a5c15117996777a3be74b73b583f595e
2017-11-07 07:52:16 -08:00
Jean Lauliac 81bfef0389 metro-bundler: allow different run-before-main-module depending on entry point
Reviewed By: davidaurelio

Differential Revision: D6248242

fbshipit-source-id: 9471820fce926e676170e3024bd48c9d7335c1a7
2017-11-07 07:41:58 -08:00
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