Commit Graph

903 Commits

Author SHA1 Message Date
aleclarsoniv 82354640ff Fix node_modules resolution error messages
Summary:
We could probably relieve a lot of pain (in [this issue](https://github.com/facebook/react-native/issues/4968) specifically) by fixing the error message for when a module cannot be resolved after trying every relevant `node_modules` directory.

Currently, you get a confusing error message that only gives you the last `node_modules` directory checked. By creating the error message where we can access the `searchQueue`, we're able to provide all of the attempted `node_modules` directories.

Here's an example error message:

```
Unable to resolve module leftpad from /Users/aleclarson/ReactProject/src/stuff/index.js:
Module does not exist in the module map or as these directories:
  /Users/aleclarson/ReactProject/src/stuff/node_modules/leftpad
  /Users/aleclarson/ReactProject/src/node_modules/leftpad
  /Users/aleclarson/ReactProject/node_modules/leftpad
  /Users/aleclarson/node_modules/leftpad
  /Users/node_modules/leftpad
```
Closes https://github.com/facebook/react-native/pull/9832

Differential Revision: D3895408

Pulled By: davidaurelio

fbshipit-source-id: 872c9a3bb3633f751ec69b586a261616578ed511
2016-09-20 13:58:52 -07:00
James Ide 5ac77062be Add "assetPlugin" option to allow arbitrary asset processing
Summary:
Adds a new URL option to the packager server called "assetPlugin". This can be a name of a Node module or multiple Node modules (`assetPlugin=module1&assetPlugin=module2`). Each plugin is loaded using `require()` and is expected to export a function. Each plugin function is invoked with an asset as the argument. The plugins may be async functions; the packager will properly wait for them to settle and will chain them.

A plugin may be used to add extra metadata to an asset. For example it may add an array of hashes for all of the files belonging to an asset, or it may add the duration of a sound clip asset.
Closes https://github.com/facebook/react-native/pull/9993

Differential Revision: D3895384

Pulled By: davidaurelio

fbshipit-source-id: 0afe24012fc54b6d18d9b2df5f5675d27ea58320
2016-09-20 13:43:51 -07:00
Cristian Carlesso 7b2080e118 Removing automatically reset modules between test run
Reviewed By: bestander

Differential Revision: D3886125

fbshipit-source-id: c8f47c3466add1e2c89649a1c6f47b01f0d7a89e
2016-09-19 12:43:55 -07:00
aleclarson 38c5621602 Check if node_modules dir exists before adding to search queue
Summary:
We can keep the `searchQueue` cleaner by using `this._fastfs.dirExists` on the potential `node_modules` directory. In addition to avoiding useless lookups, this also makes the error message provided by #9832 much more understandable.

/cc davidaurelio
Closes https://github.com/facebook/react-native/pull/9973

Differential Revision: D3887053

Pulled By: davidaurelio

fbshipit-source-id: 6a5a488bb4217dd0f9db1c9c9f988b498c746ca9
2016-09-19 10:43:58 -07:00
Jean Regisser 1a3e6eb888 Fix iOS unchanged local assets refetched from packager in development
Summary:
Hi,

This PR fixes the problem described by chrisnojima in https://github.com/facebook/react-native/issues/9581#issuecomment-243766310

**Test plan**

In development mode,
- Run an app with an image: `<Image source={ require('./logo.png') }/>`
- Notice that you see the following in packager console:
```txt
6:46:42 PM] <START> processing asset request logo.png
[6:46:42 PM] <END>   processing asset request logo.png (1ms)
```
- Reload the app, or navigate to another page of the app with the same image
- Notice that you see again:
```txt
6:47:23 PM] <START> processing asset request logo.png
[6:47:23 PM] <END>   processing asset request logo.png (1ms)
```

Now wih the fix applied,
notice that you only see `logo.png` fetched once, even if you reload or show the same image in a different part of the app.

Let me know what you think.
Closes https://github.com/facebook/react-native/pull/9795

Differential Revision: D3876945

Pulled By: davidaurelio

fbshipit-source-id: f41f4719e87644692a690123fd6e54eead9cc87d
2016-09-19 10:43:58 -07:00
David Aurelio dd20aa5ef0 Unbreak RAM groups for modules without dependency pairs
Reviewed By: javache

Differential Revision: D3886546

fbshipit-source-id: 9b18834f91393de8a4b7c2e963a63a8f37c1c7b1
2016-09-19 09:58:35 -07:00
David Aurelio fd84447341 Fix HMR after adding RA-Bundle groups
Summary:
The introduction of groups for random access bundles broke hot module reloading, because HMR uses a different Bundle class. And that didn’t have the `setRamGroups()` method.

This just adds an empty method on the base class.

**Test plan (required)**

I ran `node scripts/run-ci-e2e-tests.js --android`
Closes https://github.com/facebook/react-native/pull/9982

Differential Revision: D3886096

Pulled By: bestander

fbshipit-source-id: 46e6183607b0275d3cfe0d892360248b7b2154e9
2016-09-19 04:44:12 -07:00
David Aurelio b62ed2f291 Add support for module groups to iOS Random Access Bundle format
Summary:
Adds the possibility to specify an array of files (group roots) that are used to bundle modules outside of the “startup section” into bigger groups by colocating their code.
A require call for any grouped module will load all modules in that group.
Files contained by multiple groups are deoptimized (i.e. bundled as individual script)

Reviewed By: martinbigio

Differential Revision: D3841780

fbshipit-source-id: 8d37782792efd66b5f557c7567489f68c9b229d8
2016-09-16 10:13:49 -07:00
David Aurelio 5710b230a2 Support `false` mappings in `"browser"` fields
Summary:
This adds support for `false` values in `package.json` `"browser"` and `"react-native"` mappings.
All `false` values are not longer silently ignored, but redirected to an empty file.

Fixes #9854 #9518

Reviewed By: bestander

Differential Revision: D3876521

fbshipit-source-id: 96d1ba03518812bc88c51672c374956eabd40c9b
2016-09-16 06:13:35 -07:00
Charles Dick e6bec9cb80 Add option to bundle server to generate full sourcemaps from babel
Reviewed By: bestander

Differential Revision: D3863894

fbshipit-source-id: a282758e022d403743841bc59277196e6741ed18
2016-09-15 06:58:26 -07:00
aleclarsoniv d4dff25292 Protect against roots that are contained within other roots
Summary:
For example, I could have a root named `random` and another root named `randomColor`.
A child of `randomColor` would **incorrectly** pass as a descendant of `random`.

So this commit changes `isDescendant` to do 2 things:
- check for exact matches (eg: the path is a root)
- call `startsWith` like before, but append `path.sep` to avoid false positives
Closes https://github.com/facebook/react-native/pull/9831

Differential Revision: D3864968

fbshipit-source-id: 7fe04913579aa0741840fc925216283304ae3433
2016-09-14 13:43:47 -07:00
David Aurelio 24736d1188 module graph
Summary:
This piece of code can assemble all transitive dependencies of a set of entry modules. It is supposed to replace `ResolutionRequest.getOrderedDependencies`.

It has the following advantages:
- has minimal API surface to other components of the system (uses two functions, exposes one function)
- allows to separate concerns into loading + transforming files, resolving dependencies, gathering all modules belonging to a bundle (this code), and bundling
- allows to specify multiple entry points
- allows to use any kind of dependency ID as entry point (haste IDs, node module IDs, relative paths, absolute paths – depends on the resolver)
- allows to skip files, which allows callers to incrementally update previously retrieved collections of modules

Reviewed By: cpojer

Differential Revision: D3627346

fbshipit-source-id: 84b7aa693ca6e89ba3c1ab2af9a004e2e0aaed3d
2016-09-14 10:28:34 -07:00
David Aurelio cacc31d759 Calculate asset hash from file contents, cache hashes
Summary: This makes the `hash` property of asset data depend on asset file contents rather than modification time of files. That means that bundles will be consistent across different checkouts.

Reviewed By: martinbigio

Differential Revision: D3856815

fbshipit-source-id: 8bfea4e0a714f48fc6a4ae5ed2a1426dc8d5868e
2016-09-14 04:28:46 -07:00
Jing Chen 2c0d44a902 Reverted commit D3841557
Reviewed By: davidaurelio

Differential Revision: D3841557

fbshipit-source-id: c6098f0d85aa5c56b4109cd4f1ffe622379ab457
2016-09-12 13:58:33 -07:00
Charles Dick 2bd5b0b440 use babel sourcemaps in bundle server
Reviewed By: davidaurelio

Differential Revision: D3841557

fbshipit-source-id: a6d40cf224ba7c2fd0a8eb0f0e2f7cc4bf222bcb
2016-09-12 09:28:42 -07:00
aleclarsoniv 8cfa7340d1 Remove 'new' keyword before Promise.race()
Summary:
I'm not sure if this was actually breaking anything, but I don't think `new` before `Promise.race()` is conventional.
Closes https://github.com/facebook/react-native/pull/9817

Differential Revision: D3836814

Pulled By: javache

fbshipit-source-id: 3bde46dca3760c3f7f3427f6346dd5f16f8ac011
2016-09-09 05:28:51 -07:00
aleclarsoniv 29febb9b1e Fix typo in new ModuleCache args
Summary:
👍
Closes https://github.com/facebook/react-native/pull/9774

Differential Revision: D3835002

Pulled By: mkonicek

fbshipit-source-id: a94f07a7f32fe709f0a7bed561f26d1d9c5ac377
2016-09-08 07:43:52 -07:00
Eric Rozell 4647b62f4d fix(packager): support node-haste browser and react-native replacements on Windows
Summary:
Explain the **motivation** for making this change. What existing problem does the pull request solve?

Fix issue with browser and react-native module mappings in node-haste when running the packager from Windows.

**Test plan (required)**

Tested on the NPM package uuid, which has a browser mapping, and it worked.

Fixes #9570
Closes https://github.com/facebook/react-native/pull/9572

Differential Revision: D3821761

Pulled By: davidaurelio

fbshipit-source-id: ebbd91f9e3215385afe3b81a97a962b45a6286f9
2016-09-06 08:58:37 -07:00
wusuopu 8d013c2326 Fix _processAssetsRequest when url contains non-latin letter
Summary:
When I use local static files as Image resources, it will occur a 404 error if the image file's name contains some non-latin letters.
The reason is that the request's url will be encoded if it contains some non-latin letters.
Closes https://github.com/facebook/react-native/pull/9604

Differential Revision: D3821328

Pulled By: javache

fbshipit-source-id: bfdc7f71517b5d4ba9e0a013979e5dcf6c31a237
2016-09-06 06:13:49 -07:00
Ovidiu Viorel Iepure 2ea65ec872 'silent' option for Activity events
Summary: Activity events now have a `silent` boolean option that specifies whether or not the event phases are to be logged to the console. Defaults to `false`, preserving current behaviour for events that do not explicitly have this option set.

Reviewed By: davidaurelio

Differential Revision: D3810802

fbshipit-source-id: 38d14b9e6c6502fbc73eece9466f20b60d19965e
2016-09-05 06:43:51 -07:00
David Aurelio 13994d5810 re-enable and fix tests
Summary:
When bringing back `node-haste` to React Native, I left an `fdescribe` in a test that led to ~70 tests being skipped.
This re-enables these tests, and fixes test failures

Reviewed By: cpojer

Differential Revision: D3811225

fbshipit-source-id: 67a16f385759bb829f1f3f559862eab7e78f2097
2016-09-03 01:13:37 -07:00
Ovidiu Viorel Iepure 46e47aaecd Telemetry for update bundle event
Summary: Updating an existing bundle is now logged as a telemetric event.

Reviewed By: davidaurelio

Differential Revision: D3804754

fbshipit-source-id: adab3b054a161bd9535ad01d52573fb7bb177d43
2016-09-01 11:14:07 -07:00
Ovidiu Viorel Iepure 20c80e4929 High resolution timers
Summary: - replaced `Date` timers with high resolution timers

Reviewed By: bestander

Differential Revision: D3770919

fbshipit-source-id: 08b10b02d59f260030359a1b65ff155c92952018
2016-08-27 06:28:42 -07:00
Ovidiu Viorel Iepure 11488d0338 Improvements to the Activity API
Summary:
Revised the Activity implementation
- added flow annotations
- fixed some lint warnings
- added event `options`, specifically a `telemetric` option which indicates that events tagged in this manner are relevant for telemetry. The duration of these events is now highlighted in the Activity log

Reviewed By: bestander, kentaromiura

Differential Revision: D3770753

fbshipit-source-id: 6976535fd3bf5269c6263d825d657ab0805ecaad
2016-08-25 09:58:37 -07:00
Alexander Jarvis ea7b2ef36b Check bundle file exists for release builds
Summary:
Motivation: While testing the RC, the bundle step failed (because the reset-cache true flag was still present) for an Archive build causing an app to be distributed without the JS bundle. This was obviously not great because the app just crashed on startup.

This fix just checks that the bundle file is present and if not fails the build, as you would expect it to.
Closes https://github.com/facebook/react-native/pull/9284

Differential Revision: D3749572

fbshipit-source-id: f1ccb8b6cd0b78f6d8267e7b4b0f10b4a3cec5a1
2016-08-21 11:28:46 -07:00
David Aurelio f83c869411 Fix module IDs of initial require calls
Summary: The logic of assigning module IDs to the initial require calls of a bundle was faulty, counting up from -1 instead of counting down. This change ensures that IDs are -1, -2, ...

Reviewed By: matryoshcow

Differential Revision: D3735560

fbshipit-source-id: 89efa3e73b39c2f8bfed8a6a30487733d1a8b145
2016-08-18 07:28:43 -07:00
David Aurelio 555430089e Remove cached bundle if update fails
Summary: If a bundle failed to build, a file change would trigger the *update bundle* path, without ever being able to resolve the bundle. If a bundle can't be updated, we evict it from the cache.

Reviewed By: cpojer

Differential Revision: D3726567

fbshipit-source-id: a342f00c5a41364551194c33082718e5483fd7a4
2016-08-16 17:43:41 -07:00
David Aurelio 754da27d94 Remove rejected promises from the cache
Summary: Rejected promises in the cache would prevent the cache from persisting. This removes rejected promises from the cache, so that subsequent successful cache updates can be persisted.

Reviewed By: cpojer

Differential Revision: D3726691

fbshipit-source-id: ddec03676a7a89264fe64b4af4b183cbead638fb
2016-08-16 17:43:41 -07:00
David Aurelio f8ce2f9f70 remove unused property
Reviewed By: matryoshcow

Differential Revision: D3717515

fbshipit-source-id: 5ecba83367cd11b19b56d19edf72efe9db717e2b
2016-08-15 12:43:31 -07:00
David Aurelio 8240339dca Clear bundles for potential dependency resolution changes
Summary:
This clears the packager server cache for potential changes of module resolutions.
We will make this a lot better in the future, but for now this crude mechanism will have to do.

Reviewed By: cpojer

Differential Revision: D3713143

fbshipit-source-id: 7c81f40e8ec71404c3369211b29f63928d6634b9
2016-08-15 08:43:34 -07:00
David Aurelio 5df9c67351 Make reloads faster for simple file changes
Summary:
This is a very hacky solution to make reloads from packager faster for simple file changes.

Simple means that no dependencies have changed, otherwise packager will abort the attempt to update and fall back to the usual rebuilding method.

In principle, this change avoids re-walking and analyzing the whole dependency tree, and just updates modules in existing bundles.

Reviewed By: bestander

Differential Revision: D3713704

fbshipit-source-id: ba182325c4f4003c0a7402ea87444a94c75ebaf8
2016-08-15 04:43:49 -07:00
Jing Chen 5b040a52c4 Reverted commit D3703896
Summary:
This is a very hacky solution to make reloads from packager faster for simple file changes.

Simple means that no dependencies have changed, otherwise packager will abort the attempt to update and fall back to the usual rebuilding method.

In principle, this change avoids re-walking and analyzing the whole dependency tree, and just updates modules in existing bundles.

Reviewed By: bestander

Differential Revision: D3703896

fbshipit-source-id: abc2a41144536baf969d346522a17044c1c9558b
2016-08-12 16:58:26 -07:00
David Aurelio 3f504ec147 Make reloads faster for simple file changes
Summary:
This is a very hacky solution to make reloads from packager faster for simple file changes.

Simple means that no dependencies have changed, otherwise packager will abort the attempt to update and fall back to the usual rebuilding method.

In principle, this change avoids re-walking and analyzing the whole dependency tree, and just updates modules in existing bundles.

Reviewed By: bestander

Differential Revision: D3703896

fbshipit-source-id: 671206618dc093965822aed7161e3a99db69a529
2016-08-12 09:43:27 -07:00
ColCh 8edb952403 make fsop timeout injectable
Summary:
We have a weak build machine for React Native app: a poor Mac Book Air with HDD, which is very slow.

So, fs operations sometimes fail because of timeout.

We likely don't care about build time, but it's pretty annoying to restart builds sometimes.

In this PR I make timeout injectable via environment variable.

__USAGE__:
export this variable into environment. It's measured in miliseconds.
Example, for 1 minute timeout:
`export REACT_NATIVE_FSOP_TIMEOUT=60000`

If you don't specify it, it will remain default value: `15000`

This should not break anything, but repair slow builds.

Related to : #9373 , #8794 (I think so)

This PR should handle case of issue and close #9373
Closes https://github.com/facebook/react-native/pull/9374

Differential Revision: D3709325

Pulled By: bestander

fbshipit-source-id: b00c89e10d05362314546faea7a4524f3d327c97
2016-08-12 07:28:38 -07:00
David Aurelio 24236a8926 Strip down asset data
Summary: This removes asset data that is not used at runtime from the bundle.

Reviewed By: javache

Differential Revision: D3628486

fbshipit-source-id: 33cd579c904e0b0e29502df39a4ff92cad43367c
2016-08-08 18:28:49 -07:00
Nikhilesh Sigatapu a2417065b1 Fix off-by-one error in range requests
Summary:
https://github.com/facebook/react-native/pull/8219 adds range requests to the asset server, but there was an off-by-one-error that made responses end prematurely. This made (for example) react-native-video not work for video assets. This change fixes the off-by-one error and react-native-video works with assets.

**Test plan (required)**

Try the test in the original pull request for range requests: https://github.com/facebook/react-native/pull/8219
Closes https://github.com/facebook/react-native/pull/9254

Differential Revision: D3680070

fbshipit-source-id: 3f2a18ba9f35b45b340f4a1046bc099b8444eb7d
2016-08-06 03:28:32 -07:00
Spencer Ahrens 0dd93b62b4 fix console.table polyfill when entries are missing
Summary: Looks like react-addons-perf is sometimes missing entries. This prevents it from crashing.

Reviewed By: davidaurelio

Differential Revision: D3669007

fbshipit-source-id: 18a1102b5ad8dcfd9b80d39e1172ba85ad0e9dd2
2016-08-04 11:43:56 -07:00
Tom Hayden cb778aa543 reset-cache flag no longer needs boolean
Summary:
When compiling 0.31-rc1 was having issues with xcode running the package script and failing (ie not running and returning the --help info) Was due to this - simply changing the flag to --reset-cache instead of --reset-cache true worked miracles.

**Test plan (required)**

Ran packager without and runs but doesn't build the package, runs with small change and works now. Can copy paste output if you want but it's pretty super verbose for this small change.
Closes https://github.com/facebook/react-native/pull/9177

Differential Revision: D3661831

fbshipit-source-id: 3cebc543806b8fe3e413f83c59c9fb74e5e078f4
2016-08-03 01:13:37 -07:00
androidtrunkagent 1ab4b2a792 Add support for passing in additional assetExts to packager
fbshipit-source-id: 42e508e37d960fbeb905a2ea8cb4741dba5c67fc
2016-08-02 10:27:25 -07:00
David Aurelio 23ede0fbc7 add `'change'` event to `HasteMap`
Reviewed By: bestander

Differential Revision: D3641360

fbshipit-source-id: 7941d0e954ad3e2aba1f16d797da280f6095aa05
2016-07-29 11:15:10 -07:00
David Aurelio 667aaa4621 Bring back node-haste to fbsource
Summary:
Since jest stopped using node-haste a while ago, we are the only client left.
This brings back node-haste back to fbsource to allow us to iterate faster.

Reviewed By: bestander

Differential Revision: D3641341

fbshipit-source-id: a859f8834765723a3515e2cf265581b9dd83997c
2016-07-29 11:15:02 -07:00
Christoph Pojer 75ecaf4190 Update to 14.0
Reviewed By: kassens

Differential Revision: D3627753

fbshipit-source-id: 35b8246c8cb61e60908d8c233a6e72063bf67096
2016-07-27 22:13:26 -07:00
David Aurelio fe8eca43ac Debounce progress updates
Summary: This shows at max 5 progress updates per second on the terminal, which results in a minor speedup of reloads.

Reviewed By: bestander

Differential Revision: D3620164

fbshipit-source-id: d1a30f2f29f7088602d276b8ad3fc8ff1b74c79d
2016-07-26 07:28:41 -07:00
Nathan Azaria 87124383ac Changed JS location of examples to source from RCTBundleURLProvider instead.
Summary:
This changes the JS location of the examples (2048, UIExplorer, Movies, and TicTacToe) to be set from RCTBundleURLProvider instead.
This also makes the example apps run the bundle script, which makes the build time longer.

Reviewed By: javache

Differential Revision: D3516371

fbshipit-source-id: 70e53c62feb81c067df4e2298e7d1f1458777490
2016-07-15 10:13:29 -07:00
David Aurelio ff0eb47dbd Adapt jest transform for node-only files
Summary:
This changes the jest preprocessor so that files targetet at node.js will be run with the node-specific transform.
It also adapts tests that relied on inline requires.

Benefit: packager tests run faster now.

Reviewed By: cpojer

Differential Revision: D3562007

fbshipit-source-id: e06c86d545926a5c546458025f505dca115e7ea8
2016-07-15 06:28:26 -07:00
Mark Oswald 91ff6868a5 Use HTTP range requests (responses) to serve mp4 from assets
Summary:
This PR solves a problem when video assets are used from third-party React Native components (e.g. [react-native-video](https://github.com/brentvatne/react-native-video). The video will not work while the assets are served from the react native packager because the used video component (iOS) relies on HTTP range requests.

I added a small fix that allows ranged requests (e.g. mp4) to be served in ranges.

To test this:

1. make new react native project
1. add [react-native-video](https://github.com/brentvatne/react-native-video) to xcode project
1. add video component to your project
```
import Video from 'react-native-video';
var resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
/* ... /*
render() {
    let source = resolveAssetSource(require('./someVideoFile.mp4')) || {};
    return <Video /*....*/ source={source} />;
}
```

That should not work (if video is smaller than a few megabytes, open app a few times). Then add my fix, that should do the trick.
Closes https://github.com/facebook/react-native/pull/8219

Reviewed By: davidaurelio

Differential Revision: D3542485

Pulled By: frantic

fbshipit-source-id: e4f2e4d3aaafa8445e965259bf04ad107dba8a4f
2016-07-13 03:58:22 -07:00
Konstantin Raev 41064991a2 fix: increased fs timeout for assetserver to test if this helps for large codebases
Reviewed By: jingc

Differential Revision: D3528913

fbshipit-source-id: f04eff42327bd729ebfcd71856a1d38ef9810986
2016-07-07 11:44:54 -07:00
Johannes Stein dc2597ffee Fixes typo in error message
Summary:
This pull request fixes a small typo when a module fails being transformed through the React Packager.
Closes https://github.com/facebook/react-native/pull/8596

Differential Revision: D3522272

Pulled By: mkonicek

fbshipit-source-id: e117a26bab5a99573ac68fb0e7618df0a14325a4
2016-07-06 08:13:45 -07:00
Konstantin Raev 46e880a3a7 Revert "Reverted commit D3516741"
Summary:
Unrevert a revert
Closes https://github.com/facebook/react-native/pull/8581

Differential Revision: D3517894

Pulled By: bestander

fbshipit-source-id: 19006b9c6438cf05d44ee152eb7b1b17ea4d61a0
2016-07-05 13:28:20 -07:00
Konstantin Raev f49cc6e2f1 Reverted commit D3516741
Summary:
Looks like spaces in function names can happen, but the lib we use for parsing stacktraces doesn't support that. As result, when error is thrown in global scope, new JSC puts "global code" as function name, our parser chokes on it and thinks "global code@http://...." is a file name and sends it to packager. The packager can't resolve that URL and fails the whole symbolication request.

Longer term fix here: https://github.com/errwischt/stacktrace-parser/pull/5

Reviewed By: astreet

Differential Revision: D3516741

fbshipit-source-id: 7f14b52a50a118dc95a3463aee842941e904e984
2016-07-05 11:43:19 -07:00
Alex Kotliarskyi 29e04a6d1b Fix test broken by D3516741
Reviewed By: astreet

Differential Revision: D3517064

fbshipit-source-id: 8fe6fca1bc2c77872b1bf09bd114a3d490d9c834
2016-07-05 10:58:49 -07:00
Alex Kotliarskyi 3e681c1acc Don't attempt symbolicating non-http(s) urls
Summary:
Looks like spaces in function names can happen, but the lib we use for parsing stacktraces doesn't support that. As result, when error is thrown in global scope, new JSC puts "global code" as function name, our parser chokes on it and thinks "global code@http://...." is a file name and sends it to packager. The packager can't resolve that URL and fails the whole symbolication request.

Longer term fix here: https://github.com/errwischt/stacktrace-parser/pull/5

Reviewed By: astreet

Differential Revision: D3516741

fbshipit-source-id: 4f2bb70084437ed9d37495cd775622a8c981fad1
2016-07-05 09:43:26 -07:00
David Aurelio bd60d828c5 Remove `node_modules/react` from the list of discoverable haste modules
Summary: This removes `node_modules/react` from the list of directories that are used for haste module resolutions. Modules required from React are now imported with `require('react/lib/…')`.

Reviewed By: astreet

Differential Revision: D3509863

fbshipit-source-id: 32cd34e2b8496f0a6676dbe6bb1eacc18124c01e
2016-07-05 06:44:33 -07:00
Christoph Pojer 89a9ca6688 Update some JS in preparation for some Jest updates.
Summary:
* Next version of Jest doesn't allow non test files in __tests__ folders.
* I'm trying to switch all tests off of jsdom on react-native. This should save 500ms of time when running a single test because jsdom is slow to load and react-native is also not supposed to run in a DOM environment, so let's not pretend we are providing the DOM in tests.
* Make the bridge config configurable so that when we disable automocking and we reset the registry we can redefine the value.

Oh also, stop using lodash in Server.js. First off, lodash 3 doesn't work in Jest's node env because it does some crazy stuff, second because we don't need to load all of lodash for debounce.

Reviewed By: davidaurelio

Differential Revision: D3502886

fbshipit-source-id: 1da1cfba9ed12264d81945b702e7a429d5f84424
2016-06-30 01:58:40 -07:00
Philipp von Weitershausen dd9b3e13a9 Allow rn-cli.config.js to specify the default transformer
Summary:
This will allow consumers to supply their own transformer to all `react-native` cli commands by simply implementing `rn-cli.config.js` and overriding `getTransformModulePath()`. That way they don't have to fork various parts of the iOS and Android build system that React Native already provides just to add a `--transformer` command line argument.

**Test plan:** Applied this patch to the React Native version in my app, implemented `getTransformModulePath()` in my `rn-cli.config.js`, and verified that my custom transformer is invoked.
Closes https://github.com/facebook/react-native/pull/7961

Differential Revision: D3404201

Pulled By: foghina

fbshipit-source-id: c7eaa85de84d485d06d23a2ffea899821b2cf71c
2016-06-22 08:13:26 -07:00
David Aurelio b39fc05dbb Print nicer error message if an asset directory is not found in any of the roots
Summary:
When an asset is included in a module, and the directory for that asset can't be found in any of the roots, it is hard to debug that, because the error message contains neither the name of the requested file, the sub directory it is located in, nor the roots that have been searched for it. It becomes more difficult, because that exception is created asynchronously. It contains the calling promise code.

This diff makes the error message more useful by including the name of the file, the sub directory, and the roots.

Reviewed By: bestander

Differential Revision: D3456738

fbshipit-source-id: 60b81f04626ad386f7120247c5f5361c81c52968
2016-06-20 10:13:22 -07:00
David Aurelio 62bb09d1f6 make module IDs deterministic when bundling
Summary:
This makes sure that `getModuleId` is called on modules in the order returned by `node-haste`, rather than waiting for a couple of promises to resolve before calling the function.

Related: #7758

Reviewed By: frantic

Differential Revision: D3450853

fbshipit-source-id: 7f26590b39b94ade32c73a8db9fd31d283d57549
2016-06-17 12:58:49 -07:00
Benoit Lemaire bc42861cbf Cleanup packager dead debug endpoint
Summary:
When trying to access the debug dependency graph through the `/debug/graph` endpoint of the packager server (documented in the packager README and listed as well when hitting the root `/debug` endpoint), all I am getting back is a nasty HTTP 500 error :'(

What triggers this HTTP 500 is a `TypeError` being thrown while trying to access a function that doesn't exists (anymore). Here is the error log of the packager when trying to access this endpoint :

```
TypeError: this._depGraph.getDebugInfo is not a function
    at Resolver.getDebugInfo (index.js:270:27)
    at Bundler.getGraphDebugInfo (index.js:575:27)
    at Server._processDebugRequest (index.js:369:28)
    at Server.processRequest (index.js:423:12)
    at next (/Users/blemair/Code/DependencyGraphTest/node_modules/connect/lib/proto.js:174:15)
    at Object.module.exports [as handle] (cpuProfilerMiddleware.js:17:5)
    at next (/Users/blemair/Code/DependencyGraphTest/node_modules/connect/lib/proto.js:174:15)
    at Object.module.exports [as
Closes https://github.com/facebook/react-native/pull/8117

Differential Revision: D3445582

fbshipit-source-id: cf5af8bbba293f39773f32814a3b388b7ff67bf7
2016-06-16 14:28:29 -07:00
Marc Horowitz 50caf4e809 Change the default guard behavior to throw the exception
Differential Revision: D3428928

fbshipit-source-id: 7847d7fac6a2dc1e4c58dfd5f97feea97ba58930
2016-06-14 16:28:46 -07:00
Nathan Azaria 8c29a52c54 Implemented automatic IP detection for iOS
Summary:
Implemented automatic IP detection for iOS, based on #6345 and #6362.
As the previous pull requests did, this works by writing the IP address of the host to a file.
Closes https://github.com/facebook/react-native/pull/8091

Differential Revision: D3427657

Pulled By: javache

fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
2016-06-13 15:58:36 -07:00
Tim Yung 5e73c070e8 RN: Fix Symbolicate Logspew for `/debuggerWorker.js`
Summary:
When remote debugging is enabled, stack traces start at `/debuggerWorker.js`. Since this is not a valid bundle URL, the packager fails to decipher it to find its sourcemap.

This changes the packager to skip the `/debuggerWorker.js` stack frame if one exists.

Reviewed By: frantic

Differential Revision: D3418341

fbshipit-source-id: 7434aa45dea7d120d9d77c060101dd9403989d0c
2016-06-10 12:28:26 -07:00
Yann Pringault c8101607d8 Minor typo in Error message
Summary: Closes https://github.com/facebook/react-native/pull/8001

Differential Revision: D3404663

fbshipit-source-id: 0d0af84e4f6d31e6ddf79ef4e263737542b81361
2016-06-08 06:13:25 -07:00
David Aurelio 8c3db9782e inline `Platform.select`
Summary: We are already inlining `Platform.OS`. This diff adds support to inline calls to `Platform.select` with an object literal as first argument. The transform will replace the call with the property value corresponding to the platform, or `undefined` if it does not exist.

Reviewed By: frantic

Differential Revision: D3385391

fbshipit-source-id: bb068d17948ed84e381707faeaa0450399c2f306
2016-06-05 05:58:20 -07:00
Steven Luscher 1b2d4266b9 Update `fbjs-scripts` to ^0.7.0
Summary:
`fbjs-scripts` 0.4.0 has Babel 5 as a dependency, which causes some amount of havoc when you're trying to use `react-native` in a project that's otherwise dependent on Babel 6 and using the flat-installing npm >=3.
Closes https://github.com/facebook/react-native/pull/7855

Reviewed By: frantic

Differential Revision: D3371679

Pulled By: steveluscher

fbshipit-source-id: 9f7643171d89da0de0492e7e97875f472725e990
2016-06-02 11:43:19 -07:00
Konstantin Raev aa53770c25 removed unused code: _numPrependedModules
Summary:
cc davidaurelio
Closes https://github.com/facebook/react-native/pull/7873

Differential Revision: D3371406

Pulled By: javache

fbshipit-source-id: 72ed3838a88022ae5c0832dcca5abda75f18dbe1
2016-06-01 06:28:22 -07:00
Yann Pringault ed47efe4a1 Add Array.prototype.includes polyfill
Summary:
Add `Array.prototype.includes` polyfill.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

I had all my `includes` running well on iOS 9 but when switching to Android `includes` threw an error.
[The compatibility table](http://kangax.github.io/compat-table/esnext/#test-Array.prototype.includes_Array.prototype.includes) shows that is not supported on Android yet as well as iOS 6-8.
With Chrome debugging it's working on both environment.
Closes https://github.com/facebook/react-native/pull/7756

Reviewed By: davidaurelio

Differential Revision: D3346873

Pulled By: vjeux

fbshipit-source-id: 2e17d29992873fbe4448b962df0423e516455b4b
2016-05-25 11:58:24 -07:00
David Aurelio 6629ae9fdf adapt instantiation of node-haste/DependencyGraph to new version
Reviewed By: bestander

Differential Revision: D3339969

fbshipit-source-id: 2b81f8019223b060f3e3afb940cc58360ed024e5
2016-05-24 05:13:27 -07:00
Eric Rozell 68af89dcbf Update node-haste dependency to 2.12.0
Summary:
Update to node-haste 2.12.0 to support pass through configuration of supported platforms.
Closes https://github.com/facebook/react-native/pull/7660

Differential Revision: D3335034

Pulled By: mkonicek

fbshipit-source-id: d238b90a90d51654301d61251ceb26d183fef57a
2016-05-23 10:28:34 -07:00
Janic Duplessis 6961fd23ba Use a separate babel config for the local-cli and the packager
Summary:
This separates the babel config of the local-cli and the packager from the one used by the transforms of the packager since it doesn't run in the same environment and the local-cli/packager doesn't require react specific transforms and runs in node 4 so we can also avoid some es2015 transforms that node already supports.

I had to move the code in cli.js so it can still run in node 0.12 that doesn't support `const` since it is no longer transformed.

**Test plan**
Run the local-cli on node 0.12 and there should be a message saying that it requires at least node 4.
Run the local-cli on node 4 and 5 and everything should work the same as before.

I was also hoping for some perf gains but there was nothing noticeable. I did benchmark the babel-register call and it stayed pretty much the same. As for runtime performance it can help if there are optimisations for es2015 features in node.
Closes https://github.com/facebook/react-native/pull/6155

Reviewed By: bestander

Differential Revision: D3301008

Pulled By: davidaurelio

fbshipit-source-id: 504180d158a1e50bc03e28fb0d1e53d0731ce32f
2016-05-21 06:58:26 -07:00
Alex Kotliarskyi 62e74f3832 Symbolicate JS stacktrace using RN Packager
Summary:
The way we currently symbolicate JS stack traces in RN during development time
(e.g. inside the RedBox) is the following: we download the source map from RN,
parse it and use `source-map` find original file/line numbers. All happens
inside running JSC VM in a simulator.

The problem with this approach is that the source map size is pretty big and it
is very expensive to load/parse.

Before we load sourcemaps:
{F60869250}

After we load sourcemaps:
{F60869249}

In the past it wasn't a big problem, however the sourcemap file is only getting
larger and soon we will be loading it for yellow boxes too: https://github.com/facebook/react-native/pull/7459

Moving stack trace symbolication to server side will let us:
- save a bunch of memory on device
- improve performance (no need to JSON serialize/deserialize and transfer sourcemap via HTTP and bridge)
- remove ugly workaround with `RCTExceptionsManager.updateExceptionMessage`
- we will be able to symbolicate from native by simply sending HTTP request, which means symbolication
  can be more robust (no need to depend on crashed JS to do symbolication) and we can pause JSC to
  avoid getting too many redboxes that hide original error.
- reduce the bundle by ~65KB (the size of source-map parsing library we ship, see SourceMap module)

Reviewed By: davidaurelio

Differential Revision: D3291793

fbshipit-source-id: 29dce5f40100259264f57254e6715ace8ea70174
2016-05-20 12:13:48 -07:00
Eric Rozell ef21d99ded Adds packager configuration to support windows platform
Summary:
This pull request is a prerequisite to enabling the react-native-windows platform extension.

In the Resolver component, we need to add 'windows' to the list of platforms that are allowed in the DependencyGraph.  We also need to add 'react-native-windows' (the name of the Windows platform extension NPM module) to the `providesModuleNodeModules` option. This allows the node_module folder check in the DependencyGraphHelper from node-haste to be bypassed for *.windows.js files in the Windows NPM package.

For good measure, I also included a change to blacklist.js to ensure .windows.js files are ignored when the packager is parameterized on a platform.
Closes https://github.com/facebook/react-native/pull/7639

Differential Revision: D3327771

Pulled By: mkonicek

fbshipit-source-id: d1080b045ff6aa0cbf05d8070ceb0eb4cdb6dceb
2016-05-20 05:28:38 -07:00
Alex Kotliarskyi 858643dbdf Add transform-react-jsx-source to react-native preset
Summary:
Putting this up as request for comments.

The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else?
Closes https://github.com/facebook/react-native/pull/6351

Differential Revision: D3302906

Pulled By: frantic

fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
2016-05-18 12:43:24 -07:00
Konstantin Raev 42e517b7a3 Added timeouts to fs operations in packager
Reviewed By: davidaurelio

Differential Revision: D3316555

fbshipit-source-id: edf6e08569b6cb434219f4460367eec0827530fd
2016-05-18 08:43:24 -07:00
Martín Bigio fdc6240018 Reset hasError flag after HMR request
Summary:
This got broken recently. As a result of this, when a module throws while being required, either by regular load or hot reload, the module object is marked as `hasError`. Form that point all subsequent HMR updates will fail because it will think the module failed while executing the factory but the failure could have been on an old run of an old factory.

The fix is very simple: just reset `hasError` to false when accepting a module.
Closes https://github.com/facebook/react-native/pull/7567

Differential Revision: D3310685

fbshipit-source-id: 2f0b48ab7432b7c221d0c88a019a28969a8862b2
2016-05-17 11:58:31 -07:00
Martín Bigio 6457effb7b Avoid clearing out factory on DEV mode
Summary:
grabbou pointed out this issue.

We recently started cleaning out the factory function after module are required to save some memory. This broke HMR on some edge cases because sometimes the factory function may need to be re-executed. This PR just wraps the optimization into `__DEV__` to make sure we don't use it while developing.
Closes https://github.com/facebook/react-native/pull/7568

Differential Revision: D3305120

Pulled By: martinbigio

fbshipit-source-id: 741cffbb327d118f0bd0ec34dc1af53d4f94880e
2016-05-16 10:43:21 -07:00
David Aurelio b4e970f6c3 Use continuous module IDs for random access bundles
Reviewed By: bestander

Differential Revision: D3292980

fbshipit-source-id: ab5791d31add42a26cf55a0309564330c383eaa2
2016-05-12 17:28:25 -07:00
David Aurelio d5ceb4175b Allow already loaded modules to be `require`’d by name string in dev mode
Summary:
The code to require modules by their name (rather than their numeric ID) was buggy, because it didn’t check whether the module factory was already executed and the module already existed.

This diff checks the already loaded modules, too, when loading modules by name.

Reviewed By: lexs

Differential Revision: D3281350

fbshipit-source-id: cef236e152fe5484f21c877d6cee37433fa11c76
2016-05-10 09:37:20 -07:00
Pieter De Baets 2760df761d Cleanup InitializeJavascriptAppEngine
Reviewed By: davidaurelio

Differential Revision: D3235141

fb-gh-sync-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a
fbshipit-source-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a
2016-05-04 10:50:32 -07:00
David Aurelio 5071907b27 Add verbose module names to dev builds
Summary:
This intends to make the devx story better after switching to numeric module IDs:

- `require('<verbose-name>)` works again for dev builds
- In dev builds, Systrace will use the verbose names of modules for markers

Reviewed By: bestander

Differential Revision: D3253318

fb-gh-sync-id: 3425d5086ce28634653a6c8c7f5f11afa1614902
fbshipit-source-id: 3425d5086ce28634653a6c8c7f5f11afa1614902
2016-05-04 09:33:22 -07:00
David Aurelio 46d98e1d68 remove support for `process.platform`
Reviewed By: javache

Differential Revision: D3252666

fb-gh-sync-id: af0e4987c34f43ec2472cbdf52fc112b81050513
fbshipit-source-id: af0e4987c34f43ec2472cbdf52fc112b81050513
2016-05-04 02:51:26 -07:00
jsdevel d4cc5b53c7 Setting current working directory for dev server.
Summary:
* This allows `react-native` to work for users on fedora.
* `react-native run-android` was failing because the launch packager script was unable to find packager.sh (see `source` in `man bash`).
* This change sets cwd for the dev server when run with `run-android`.
Closes https://github.com/facebook/react-native/pull/7316

Differential Revision: D3255866

fb-gh-sync-id: 88f6b18f7c61636ce8fecef77f7f4e60b1d9a637
fbshipit-source-id: 88f6b18f7c61636ce8fecef77f7f4e60b1d9a637
2016-05-04 02:45:29 -07:00
David Aurelio ee5a1deb0b @ignore-signedsource [react-native-packager] use a single require implementation
Reviewed By: javache, bestander

Differential Revision: D3252718

fb-gh-sync-id: bfd85acc28dd6e2df72a3227743514cb6f8c32f1
fbshipit-source-id: bfd85acc28dd6e2df72a3227743514cb6f8c32f1
2016-05-03 15:19:17 -07:00
Mark Oswald bb06536616 call bundle with reset-cache true as default from standard project
Summary:
addition to #7297

When called from an upstarting app, the bundling process should always be called with a cleared cache. That avoids possible problems with cached files.
Closes https://github.com/facebook/react-native/pull/7324

Differential Revision: D3247420

fb-gh-sync-id: 503ad39cb36455512ccea1af7618e89a80942f0c
fbshipit-source-id: 503ad39cb36455512ccea1af7618e89a80942f0c
2016-05-02 08:03:19 -07:00
Janic Duplessis f8f9362c05 Reverted commit D3242754
Summary:
This separates the babel config of the local-cli and the packager from the one used by the transforms of the packager since it doesn't run in the same environment and the local-cli/packager doesn't require react specific transforms and runs in node 4 so we can also avoid some es2015 transforms that node already supports.

I had to move the code in cli.js so it can still run in node 0.12 that doesn't support `const` since it is no longer transformed.

**Test plan**
Run the local-cli on node 0.12 and there should be a message saying that it requires at least node 4.
Run the local-cli on node 4 and 5 and everything should work the same as before.

I was also hoping for some perf gains but there was nothing noticeable. I did benchmark the babel-register call and it stayed pretty much the same. As for runtime performance it can help if there are optimisations for es2015 features in node.
Closes https://github.com/facebook/react-native/pull/6155

Differential Revision: D3242754

Pulled By: eczarny

fb-gh-sync-id: 6cd349e284b7d92a1b2cc8b5c0e26adbfb0d9a2f
fbshipit-source-id: 6cd349e284b7d92a1b2cc8b5c0e26adbfb0d9a2f
2016-04-30 16:54:31 -07:00
Janic Duplessis 19429f79b2 Use a separate babel config for the local-cli and the packager
Summary:
This separates the babel config of the local-cli and the packager from the one used by the transforms of the packager since it doesn't run in the same environment and the local-cli/packager doesn't require react specific transforms and runs in node 4 so we can also avoid some es2015 transforms that node already supports.

I had to move the code in cli.js so it can still run in node 0.12 that doesn't support `const` since it is no longer transformed.

**Test plan**
Run the local-cli on node 0.12 and there should be a message saying that it requires at least node 4.
Run the local-cli on node 4 and 5 and everything should work the same as before.

I was also hoping for some perf gains but there was nothing noticeable. I did benchmark the babel-register call and it stayed pretty much the same. As for runtime performance it can help if there are optimisations for es2015 features in node.
Closes https://github.com/facebook/react-native/pull/6155

Differential Revision: D3242754

Pulled By: davidaurelio

fb-gh-sync-id: 02880c841c10562d5f107e1c975d668e55cc619f
fbshipit-source-id: 02880c841c10562d5f107e1c975d668e55cc619f
2016-04-30 16:25:24 -07:00
David Aurelio cccb8db175 Unify source map approach for RA bundles on iOS/Android
Reviewed By: javache

Differential Revision: D3229780

fb-gh-sync-id: a3148d7626b32a2e6803ae8c35ac75025a992a32
fbshipit-source-id: a3148d7626b32a2e6803ae8c35ac75025a992a32
2016-04-29 10:16:22 -07:00
Janic Duplessis 891b87e7fb Launch the packager with `react-native run-android` on Windows
Summary:
Adds support for launching the packager in a new window on Windows.

**Test plan (required)**

Tested that the packager is launched in a completely independent process. This means that exiting the `react-native run-android` command should not close the packager window and it should exit properly when completed even if the packager window is still opened. Pretty much made sure it behaves exactly like on mac.

Also tested that an error in the packager will not close the window immediately to show the error stack trace.
Closes https://github.com/facebook/react-native/pull/7129

Differential Revision: D3240628

Pulled By: mkonicek

fb-gh-sync-id: 007582250536481d2b2376f9a201f8f415fc1080
fbshipit-source-id: 007582250536481d2b2376f9a201f8f415fc1080
2016-04-29 04:14:22 -07:00
David Aurelio e6bafca39e Improve constant inlining, add `process.platform`
Reviewed By: bestander

Differential Revision: D3235716

fb-gh-sync-id: f9019ec0042827e409fa84ba74f4c426ccad1519
fbshipit-source-id: f9019ec0042827e409fa84ba74f4c426ccad1519
2016-04-28 11:23:21 -07:00
Pieter De Baets c7eb47fd8c Enable console.debug
Summary: Apparently what we're using for console.trace is not really the same as what Chrome does (we don't log a stacktrace). Add `console.debug` with the same functionality as `console.trace`, just so we don't crash between browser and local execution.

Reviewed By: davidaurelio

Differential Revision: D3235053

fb-gh-sync-id: 4bed17ac8aa4c8c100f15cf0aabbc25101c913c1
fbshipit-source-id: 4bed17ac8aa4c8c100f15cf0aabbc25101c913c1
2016-04-28 07:02:29 -07:00
David Aurelio e3c18c3990 Upgrade to node-haste@2.10.0 and allow to specify extra node modules
Summary: This upgrades to node-haste@2.10.0 and allows to expose folders as additional node modules from rn-cli.config.js

Reviewed By: bestander

Differential Revision: D3232595

fb-gh-sync-id: dffca66fec55a79a2b3af1d6ec1b8799b2bbcf59
fbshipit-source-id: dffca66fec55a79a2b3af1d6ec1b8799b2bbcf59
2016-04-28 06:33:27 -07:00
Christoph Pojer d363b1f2e2 Update Jest APIs on fbsource
Reviewed By: javache

Differential Revision: D3229435

fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
2016-04-27 19:16:32 -07:00
Steven Luscher dad39eb502 Move `Number` polyfills into the `/polyfills/` directory
Reviewed By: vjeux

Differential Revision: D3223317

fb-gh-sync-id: a49a14f217b27d6542b65c4780c557e73da2443f
fbshipit-source-id: a49a14f217b27d6542b65c4780c557e73da2443f
2016-04-26 11:24:42 -07:00
Steven Luscher c05169d8b7 Add a `Number.isNaN` polyfill
Reviewed By: sahrens

Differential Revision: D3222299

fb-gh-sync-id: 601283fb0b140bb305181ea381907e62286f7a37
fbshipit-source-id: 601283fb0b140bb305181ea381907e62286f7a37
2016-04-25 23:15:18 -07:00
Alexander Micklewright 3881694892 Fix a bug in asset server when using relative project roots
Summary:This PR fixes a bug where when using relative roots for the packager server, asset paths would be deemed invalid by the recently introduced security check. Resolving the root to an absolute path fixes that problem.

I'd be happy to write a regression test for this but I had a hard time setting up a mock file system with relative paths. If it is required, some help would be appreciated...
Closes https://github.com/facebook/react-native/pull/7161

Differential Revision: D3214840

fb-gh-sync-id: 08e13fb9f94a98206fd2d090f74a8b63ba2bf80f
fbshipit-source-id: 08e13fb9f94a98206fd2d090f74a8b63ba2bf80f
2016-04-22 16:06:21 -07:00
Pieter De Baets 8b1726bdad Improve error handling in require-unbundle
Reviewed By: davidaurelio

Differential Revision: D3207450

fb-gh-sync-id: 35247c265e35976dcee9fca4215403efa604479e
fbshipit-source-id: 35247c265e35976dcee9fca4215403efa604479e
2016-04-22 06:18:26 -07:00
Sebastian Markbage 47a470a97c Move React Core Integration to a Dependency
Summary:Adding the react native renderer dependency and various fixes to support React 15.

Don't use dispatchID for touchableHandleResponderGrant

This callback argument was removed because "IDs" no longer exist. Instead, we'll
use the tag from the event target.

The corresponding PR on React Core is: https://github.com/facebook/react/pull/6338

Reviewed By: spicyj

Differential Revision: D3159788

fb-gh-sync-id: 60e5cd2aa0af69d83fcdac3dfde0a85a748cb7b9
fbshipit-source-id: 60e5cd2aa0af69d83fcdac3dfde0a85a748cb7b9
2016-04-21 09:28:23 -07:00
David Aurelio d8b87b232d Allow for falsy module exports
Reviewed By: javache

Differential Revision: D3207353

fb-gh-sync-id: 3e23eb9cc9facea7993ce684f87ff4b7b0003a1c
fbshipit-source-id: 3e23eb9cc9facea7993ce684f87ff4b7b0003a1c
2016-04-21 06:49:20 -07:00
Mike Grabowski 91a52421d4 Strip shebang when present in JS files
Summary:Fixes #7034
Closes https://github.com/facebook/react-native/pull/7073

Differential Revision: D3199816

fb-gh-sync-id: 2099dd1f81b030933794be6a592a697cec3627d0
fbshipit-source-id: 2099dd1f81b030933794be6a592a697cec3627d0
2016-04-19 18:09:22 -07:00
Tadeu Zagallo 887c275bcf Free modules' factories after caching module
Summary:The require functions will keep the generate bytecode + lexical environment in
memory unnecessarily, since we can be sure that it will be executed at most once

Reviewed By: davidaurelio

Differential Revision: D3168257

fb-gh-sync-id: 038e1bc08abea94ee52d0390b6aced5fb652f493
fbshipit-source-id: 038e1bc08abea94ee52d0390b6aced5fb652f493
2016-04-19 08:13:24 -07:00
Leland Richardson e9398c7926 Whitelist the 'pdf' extension in the packager
Summary:The WebView component in iOS currently does not support displaying PDFs without providing a remote URI or manually including the assets in the xcodeproj itself. This is because the packager has not whitelisted the 'pdf' extension.

I've gone ahead and whitelisted the 'pdf extension according to the recommendation by nicklockwood

GH comment: https://github.com/facebook/react-native/issues/1846#issuecomment-199302488
Closes https://github.com/facebook/react-native/pull/7004

Differential Revision: D3196019

Pulled By: nicklockwood

fb-gh-sync-id: 10a86a9232095f98f277506141de0b8af5b21ab4
fbshipit-source-id: 10a86a9232095f98f277506141de0b8af5b21ab4
2016-04-19 03:52:27 -07:00
David Aurelio f18a4f8043 Don't load 'babel-polyfill', only polyfill `Array#values`, `Object.values`, and `Object.entries`
Summary:Instead of loading `'babel-polyfill'` into packager, we only polyfill es6 methods that are unavailable in node 4, and es7 stage 4 proposals.
That makes sure that we are using native promises, and don't load unnecessary polyfills.

Reviewed By: vjeux

Differential Revision: D3168057

fb-gh-sync-id: 68b53795d9a1d7cfdc00fc31684da3ad21a7bb34
fbshipit-source-id: 68b53795d9a1d7cfdc00fc31684da3ad21a7bb34
2016-04-12 08:29:20 -07:00
Sam Swarr 7f56073b25 Delete SocketInterface code
Reviewed By: davidaurelio

Differential Revision: D3152105

fb-gh-sync-id: a6c13bb54c2164ebc063a1b14f00114738546c8c
fbshipit-source-id: a6c13bb54c2164ebc063a1b14f00114738546c8c
2016-04-11 14:38:26 -07:00
Sam Swarr a35ef6c745 Remove socket interface from dependencies command
Reviewed By: davidaurelio

Differential Revision: D3136438

fb-gh-sync-id: 51fce2caf60fdf32a8cba180c79b1996834cda6e
fbshipit-source-id: 51fce2caf60fdf32a8cba180c79b1996834cda6e
2016-04-11 09:23:29 -07:00
Thomas Aylott 41576eaa56 Fixes hotcode reloading issue
Reviewed By: martinbigio

Differential Revision: D3136032

fb-gh-sync-id: 5666fd45ffa574d2156b03c7bfbda3fe97090f56
fbshipit-source-id: 5666fd45ffa574d2156b03c7bfbda3fe97090f56
2016-04-06 12:14:20 -07:00
Adam Miskiewicz 8200041694 Pass transformOptions to getShallowDependencies.
Summary:We weren't passing `transformOptions` to `getShallowDependencies`, and therefore, when this method was called on a module, it would bust the cache and cause a retransform of the file. This was resulting in a complete retransforming of all files when the HMR Client connected to the packager.
Closes https://github.com/facebook/react-native/pull/6843

Differential Revision: D3145306

Pulled By: martinbigio

fb-gh-sync-id: 3619c27801b2fc07b758fafed47fcc892bb8e6db
fbshipit-source-id: 3619c27801b2fc07b758fafed47fcc892bb8e6db
2016-04-06 11:38:27 -07:00
Nick 2a03182b1c CHORE - Remove Trailing Spaces
Summary:Remove Trailing Spaces.

Why:
Sometimes there are conflicts with trailing spaces
Saves space
Those whose tools automatically delete them will have their pr watered down with trailing space removal
Closes https://github.com/facebook/react-native/pull/6787

Differential Revision: D3144704

fb-gh-sync-id: d8a62f115a3f8a8a49d5b07f56c540a02af38cf8
fbshipit-source-id: d8a62f115a3f8a8a49d5b07f56c540a02af38cf8
2016-04-06 09:21:53 -07:00
Konstantin Raev d0566d8bc3 Fixed images required from node_modules
Summary:This fixes https://github.com/facebook/react-native/issues/6638 by resolving AssetRegistry relatively.
Closes https://github.com/facebook/react-native/pull/6822

Reviewed By: davidaurelio

Differential Revision: D3144463

Pulled By: bestander

fb-gh-sync-id: d3eeb24ae9e08a32f742c50ae5f0314fd33d1b6b
fbshipit-source-id: d3eeb24ae9e08a32f742c50ae5f0314fd33d1b6b
2016-04-06 07:59:29 -07:00
Janic Duplessis c61100d0ce Fix HMR on Windows
Summary:Tested HMR on Windows and found 2 small issues related to paths that made it not work. Now it works nicely :)

**Test plan (required)**
Tested HMR in UIExplorer on Windows.
Closes https://github.com/facebook/react-native/pull/6678

Differential Revision: D3138379

fb-gh-sync-id: f27cd2fa21f95954685c8c6916d820f41bc187be
fbshipit-source-id: f27cd2fa21f95954685c8c6916d820f41bc187be
2016-04-05 01:13:18 -07:00
Mart?n Bigio 98411f1642 Avoid getting `entryFilePath` on HMR codepath
Summary: The HMR codepath is currently broken because of a recent change that tries to compute the absolute entryFile path (needed for RAM Bundling). HMR Bundler's bundles are special as they contains a single file (the file that was transformed). However, for performance reasons we recycle an existing resolution response which contains the polyfills and the module system modules.

Reviewed By: sam-swarr

Differential Revision: D3098069

fb-gh-sync-id: 23d61aa304cd6f59d4df4840965f5eedda05dc31
fbshipit-source-id: 23d61aa304cd6f59d4df4840965f5eedda05dc31
2016-03-25 08:45:21 -07:00
Satyajit Sahoo 6c22a2174e Fix fetching sourcemap in genymotion. Fixes #5338
Summary:Source maps are broken on Genymotion right now as they aren't being loaded from the correct URL. refer - https://github.com/facebook/react-native/issues/5338#issuecomment-188232402

**Test plan**

Build and install UIExplorer from master branch in genymotion and enable hot reload. When you change a file and save it, you'll see a Yellow box due to source map fetching failed, as per the referenced comment.

Doing the same for this branch doesn't produce any yellow boxes.
Closes https://github.com/facebook/react-native/pull/6594

Differential Revision: D3088218

Pulled By: martinbigio

fb-gh-sync-id: 0d1c19cc263de5c6c62061c399eef33fa4ac4a7b
shipit-source-id: 0d1c19cc263de5c6c62061c399eef33fa4ac4a7b
2016-03-24 12:06:45 -07:00
Steven Chaitoff 1396de9989 file change listener for relay fragments in packager server
Reviewed By: martinbigio

Differential Revision: D3011797

fb-gh-sync-id: 9f7ddc7b3c0c0e2a78db829343d9fa93a46b4ad6
shipit-source-id: 9f7ddc7b3c0c0e2a78db829343d9fa93a46b4ad6
2016-03-24 08:08:34 -07:00
Mart?n Bigio 3888d052f1 Fix OSS tests
Reviewed By: bestander

Differential Revision: D3088301

fb-gh-sync-id: 310d9c7c1956f21f3c8e5da6a1455c2a9fad2d04
shipit-source-id: 310d9c7c1956f21f3c8e5da6a1455c2a9fad2d04
2016-03-23 15:17:21 -07:00
Shayne Sweeney 8cd3a38fd4 Use different tmpdir
Reviewed By: wez

Differential Revision: D3086091

fb-gh-sync-id: b26a792b80b523205ceafaa0e9d2299527bc8176
shipit-source-id: b26a792b80b523205ceafaa0e9d2299527bc8176
2016-03-23 12:36:21 -07:00
Martín Bigio 8edc35004c Move preloaded modules to startup code section
Summary:We found that moving the preloaded modules to the startup section of the RAM Bundle improves TTI quite a bit by saving lots of through the bridge calls and injecting multiple modules at once on JSC. However, doing this on a non hacky way required a lot of work. The main changes this diff does are:
  - Add to `BundleBase` additional bundling options. This options are fetched based on the entry file we're building by invoking a module that exports a function (`getBundleOptionsModulePath`).
  - Implement `BundleOptions` module to include the `numPreloadedModules` attribute as a bundle additional option. This value is computed by getting the dependencies the entry file has and looking for the first module that exports a module we don't want to preload. The `numPreloadedModules` attribute is then used to decide where to splice the array of modules.
- Additional kung fu to make sure sourcemaps work for both preloaded and non preloaded modules.

Reviewed By: davidaurelio

Differential Revision: D3046534

fb-gh-sync-id: 80b676222ca3bb8b9eecc912a7963be94d3dee1a
shipit-source-id: 80b676222ca3bb8b9eecc912a7963be94d3dee1a
2016-03-23 09:28:31 -07:00
Shayne Sweeney 98aea639b2 Fix asset path-traversal outside of roots
Summary:`/assets/...` requests previously supported path-traversal potentially exposing and serving (private) files outside roots.

**Test plan**

Prior to patching perform the a path-traversal request to the server:
```
GET /assets/../../../../etc/hosts HTTP/1.1
Cache-Control: no-store
Host: 127.0.0.1:8081
Connection: close
Accept-Encoding: gzip
User-Agent: okhttp/2.5.0
```

Apply patch and verify a `404` response with body: `Asset not found`

Test normal asset requests work.
Closes https://github.com/facebook/react-native/pull/6398

Differential Revision: D3034857

Pulled By: shayne

fb-gh-sync-id: f0e6714e4e3c5a63a3a402634a1eb5f3186d3561
shipit-source-id: f0e6714e4e3c5a63a3a402634a1eb5f3186d3561
2016-03-21 21:58:22 -07:00
Martín Bigio 1ef9e4dc59 Make HMR compatible with numeric IDs
Summary:We recently refactor the packager to transform the module names into numeric IDs but we forgot to update the HMR call site. As a consequence, HMR doesn't work the first time a file is saved but the second one.

This is affecting master as of 3/20. If we don't land this before v0.23 is cut we'll have to cherry pick it. This rev does *not* need to be picked on v0.22.

Reviewed By: bestander

Differential Revision: D3075192

fb-gh-sync-id: 410e4bf8f937c0cdb8f2b462dd36f928a24e8aa8
shipit-source-id: 410e4bf8f937c0cdb8f2b462dd36f928a24e8aa8
2016-03-21 15:51:24 -07:00
Shayne Sweeney 77e1b3773a Atomic install, remove locking, cache xz archives (for offline installs)
Reviewed By: martinbigio

Differential Revision: D3015398

fb-gh-sync-id: e0d987917b94ce541c8fa890930799aa8613737e
shipit-source-id: e0d987917b94ce541c8fa890930799aa8613737e
2016-03-21 12:58:22 -07:00
David Aurelio 5b5a89aefa Add sourcemap support for asset-based random access bundles
Summary:This adds support for source maps that can be used for “random access modules” / “unbundles”

- source maps contain an extra custom field: `x_facebook_offsets`
- this field maps module IDs to line offsets
- the source map is built as if all files were concatenated

Decoding/symbolication works as follows:
- when decoding a stack trace, and a stack frame comes from a filename that contains only numbers and ends with `.js`, look up the additionally needed line offset in the offset map and add it to the original line of the stack frame.
- consume the source map as usual

Reviewed By: martinbigio

Differential Revision: D3072426

fb-gh-sync-id: 827e6dc13b1959f02903baafa7f9e4fc2e0d4bb9
shipit-source-id: 827e6dc13b1959f02903baafa7f9e4fc2e0d4bb9
2016-03-21 12:32:22 -07:00
Konstantin Raev 84183ffc30 Improved OSS flow and lint reporting
Summary:- lint bot is now managed by Circle CI
- checked that flow and lint errors are caught both by bot and CI
- flow fix for npm 3
- Travis is now using npm 2 and Circle CI npm 3
- Refactored Travis script to be able to be able to fail on multiple lines
Closes https://github.com/facebook/react-native/pull/6508

Differential Revision: D3069500

Pulled By: davidaurelio

fb-gh-sync-id: 02772bf1eae5f2c44489c2e3a01899428a9640cb
shipit-source-id: 02772bf1eae5f2c44489c2e3a01899428a9640cb
2016-03-18 08:10:26 -07:00
David Aurelio f9d79b3415 Upgrade node-haste to v2.9.1 to make module order deterministic
Summary:Changing the order of transformation and extraction of dependencies made the order of modules dependent on the time when the worker pool returns a result.
node-haste v2.9.1 addresses this issue and makes the order of dependencies deterministic.

This also bumps the packager versions to enforce cache invalidation.

Reviewed By: martinbigio

Differential Revision: D3065063

fb-gh-sync-id: 1d45b066e45c3f64092f779c3fce3becf6739409
shipit-source-id: 1d45b066e45c3f64092f779c3fce3becf6739409
2016-03-17 14:59:52 -07:00
Sam Swarr d5445d5fbc Add ability to silence packager logs to stdout
Summary:We use a few different modules to output logs to stdout when building a bundle with the packager:
- ##js/react-native-github/packager/react-packager/src/Activity/index.js##
- ##js/react-native-github/local-cli/util/log.js##
- ##https://www.npmjs.com/package/progress##

This diff also adds a ##silent## option to the packager ##Server##, which, when ##true##, will not create a ##progress## instance for the transformer.

Reviewed By: martinbigio

Differential Revision: D3048739

fb-gh-sync-id: a4c6caf36f5127946593f4a0a349fa145ad0d4e6
shipit-source-id: a4c6caf36f5127946593f4a0a349fa145ad0d4e6
2016-03-15 12:10:31 -07:00
David Aurelio 06b5bda349 Bring back "Use numeric identifiers when building a bundle"
Summary:This brings back "Use numeric identifiers when building a bundle", previously backed out.
This version passes on the correct entry module name to code that decides transform options.

Original Description:
Since the combination of node and haste modules (and modules that can be required as both node and haste module) can lead to situations where it’s impossible to decide an unambiguous module identifier, this diff switches all module ids to integers. Each integer maps to an absolute path to a JS file on disk.

We also had a problem, where haste modules outside and inside node_modules could end up with the same module identifier.

This problem has not manifested yet, because the last definition of a module wins. It becomes a problem when writing file-based unbundle modules to disk: the same file might be written to concurrently, leading to invalid code.

Using indexed modules will also help indexed file unbundles, as we can encode module IDs as integers rather than scanning string IDs.

Reviewed By: martinbigio

Differential Revision: D2855202

fb-gh-sync-id: 9a011bc403690e1522b723e5742bef148a9efb52
shipit-source-id: 9a011bc403690e1522b723e5742bef148a9efb52
2016-03-14 16:17:20 -07:00
Martín Bigio f99468de65 Sourcemaps support for RAM
Summary:This rev adds support for production sourcemaps on RAM.

When we inject a module into JSC we use the original `sourceURL` and specify the `startingLineNumber` of the module relative to a "regular" bundle. By doing so, when an error is thrown, JSC will include the provided `sourceURL` as the filename and will use the indicated `startingLineNumber` to figure out on which line the error actually occurred.

To make things a bit simpler and avoid having to deal with columns, we tweak the generated bundle so that each module starts on a new line. Since we cannot assure that each module's code will be on a single line as the minifier might break it on multiple (UglifyJS does so due to a bug on old versions of Chrome), we include on the index the line number that should be used when invoking `JSEvaluateScript`. Since the module length was not being used we replaced the placeholder we have there for the line number.

Reviewed By: javache

Differential Revision: D2997520

fb-gh-sync-id: 3243a489cbb5b48a963f4ccdd98ba63b30f53f3f
shipit-source-id: 3243a489cbb5b48a963f4ccdd98ba63b30f53f3f
2016-03-13 11:14:32 -07:00
Martín Bigio e82a7a8649 Avoid hardcoding platform on blacklist
Reviewed By: davidaurelio

Differential Revision: D3042906

fb-gh-sync-id: 4a424ef1012d75d06c830b284806aefd1556ff74
shipit-source-id: 4a424ef1012d75d06c830b284806aefd1556ff74
2016-03-12 10:59:26 -08:00
David Aurelio a29d67eea3 Remove debug code from tests + re-enable tests
Reviewed By: bestander

Differential Revision: D3040961

fb-gh-sync-id: 4e49334fb1d3f80f7a701b88088011f33cb9df6e
shipit-source-id: 4e49334fb1d3f80f7a701b88088011f33cb9df6e
2016-03-11 06:39:25 -08:00
Janic Duplessis fd816b1349 Update node-haste and replace fast-path with node-haste's version to fix Windows compatibility
Summary:This is the last bits needed to fix Windows compatibility on master, most of the work was done in node-haste.

**Test plan**
Run npm test
Run the packager using Windows and Mac

cc cpojer davidaurelio
Closes https://github.com/facebook/react-native/pull/6260

Reviewed By: dmmiller, bestander

Differential Revision: D3005397

Pulled By: davidaurelio

fb-gh-sync-id: e16847808ebfa8b234315b2093dba204c9c1e869
shipit-source-id: e16847808ebfa8b234315b2093dba204c9c1e869
2016-03-11 06:00:30 -08:00
David Aurelio 925e2eba32 Make order of bundle transports deterministic
Summary:After starting to minify off the main process, the order of module transport objects in `Bundle` instances became less deterministic.
These changes guarantee that module transports appear in addition order, not in order of minification completion.

Reviewed By: bestander

Differential Revision: D3029588

fb-gh-sync-id: 80e83c05d7f78ed7e69583d7e3aa2831bd5ae4d0
shipit-source-id: 80e83c05d7f78ed7e69583d7e3aa2831bd5ae4d0
2016-03-09 08:30:21 -08:00
Kureev Alexey db3a00d58c Replace underscore by lodash
Summary:As far as we agreed to merge `rnpm` into react-native core, we need to align our dependencies to exclude duplications. One of the steps forward would be to use the same utilities library. According to the thread on fb, everybody is fine with replacing underscore by lodash (which we use internally for rnpm).

So, here we go!

cc mkonicek davidaurelio grabbou

**Test plan**
```
$ npm test
```
![image](https://cloud.githubusercontent.com/assets/2273613/13173972/ee34c922-d700-11e5-971b-68ff7322b6d6.png)

**Code formatting**

Changes are aligned with the current [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).
Closes https://github.com/facebook/react-native/pull/6030

Differential Revision: D3016271

Pulled By: davidaurelio

fb-gh-sync-id: c4f6776a7de7470283d3ca5a8b56e423247f5e45
shipit-source-id: c4f6776a7de7470283d3ca5a8b56e423247f5e45
2016-03-09 03:09:44 -08:00
David Aurelio dc4d4863a2 Make uglify not append //# sourceMappingURL=
Summary: We also need a more recent version of uglify that supports this

Reviewed By: martinbigio

Differential Revision: D3024959

fb-gh-sync-id: f9efdddceda4f726567c39884c844a8e74e6e09d
shipit-source-id: f9efdddceda4f726567c39884c844a8e74e6e09d
2016-03-08 12:22:31 -08:00
David Aurelio e76fb68141 Don't rebuild bundles automatically on file changes
Summary: Don’t rebuild bundles automatically after they have been requested once. This helps to not lock developer machines.

Reviewed By: martinbigio

Differential Revision: D3019751

fb-gh-sync-id: 98367b4fb89c5ae22c00444eabc1194ba6832dba
shipit-source-id: 98367b4fb89c5ae22c00444eabc1194ba6832dba
2016-03-08 10:44:38 -08:00
David Aurelio 9d09efdd53 transform before extracting dependencies
Summary:Make packager transform files before extracting their dependencies.

This allows us to extract dependencies added by transforms (and to avoid including them manually).

It also allows for better optimization and to get rid of the “whole program optimization” step:
This diff utilizes the new worker introduced in D2976677 / d94a567 – that means that minified builds inline the following variables:

- `__DEV__` → `false`
- `process.env.NODE_ENV` → `'production'`
- `Platform.OS` / `React.Platform.OS` → `'android'` / `'ios'`

and eliminates branches of conditionals with constant conditions. Dependency extraction happens only after that step, which means that production bundles don’t include any modules that are not used.

Fixes #4185

Reviewed By: martinbigio

Differential Revision: D2977169

fb-gh-sync-id: e6ce8dd29d1b49aec49b309201141f5b2709da1d
shipit-source-id: e6ce8dd29d1b49aec49b309201141f5b2709da1d
2016-03-08 09:51:26 -08:00
David Aurelio 54b6b92520 Un-blacklist fbjs
Summary: Blacklisting is no longer necessary, as fbjs is not used for haste module resolution any longer

Reviewed By: yungsters

Differential Revision: D3014257

fb-gh-sync-id: 39a0397e6b07bdff3dba9d48d58f4254c43eb6b6
shipit-source-id: 39a0397e6b07bdff3dba9d48d58f4254c43eb6b6
2016-03-04 17:05:40 -08:00
David Aurelio 2708df49e3 Use `invariant` from fbjs everywhere
Reviewed By: yungsters

Differential Revision: D3002422

fb-gh-sync-id: c7d308e6cfc717726dbbc43a2462fdabb052b2fe
shipit-source-id: c7d308e6cfc717726dbbc43a2462fdabb052b2fe
2016-03-02 17:14:30 -08:00
David Aurelio c331d113dc Fix breakages caused by switch to fbjs
Summary: This fixes a couple of breakages introduced by the switch to fbjs

Reviewed By: bestander

Differential Revision: D3000078

fb-gh-sync-id: 2971d049030f754d5001f6729716373a64078ddf
shipit-source-id: 2971d049030f754d5001f6729716373a64078ddf
2016-03-02 08:26:33 -08:00
David Aurelio e7499e39a4 limit number of workers
Summary:This limits the number of spawned transformation workers depending on the number of available cores (`n`):

```
n < 3   → n
n < 8   → floor(3/4 * n)
n < 24  → floor(3/8 * n + 3) // factor going from 3/4 to 1/2
n >= 24 → floor(n / 2)
```

Reviewed By: bestander

Differential Revision: D2999894

fb-gh-sync-id: 0163240b5f066432f9ba07161c0dfa2ec767ba58
shipit-source-id: 0163240b5f066432f9ba07161c0dfa2ec767ba58
2016-03-02 07:31:42 -08:00
David Aurelio ad8a335864 Remove knowledge of fbjs from the packager
Summary:Follow-up to https://github.com/facebook/react-native/pull/5084

This…
- changes all requires within RN to `require('fbjs/lib/…')`
- updates `.flowconfig`
- updates `packager/blacklist.js`
- adapts tests
- removes things from `Libraries/vendor/{core,emitter}` that are also in fbjs
- removes knowledge of `fbjs` from the packager

Closes https://github.com/facebook/react-native/pull/5084

Reviewed By: bestander

Differential Revision: D2926835

fb-gh-sync-id: 2095e22b2f38e032599d1f2601722b3560e8b6e9
shipit-source-id: 2095e22b2f38e032599d1f2601722b3560e8b6e9
2016-03-02 04:28:38 -08:00
David Aurelio d94a56747d Add new worker for code transform, optimization, and dependency extraction
Summary:This adds a new worker implementation that

- uses the existing transforms to transform code
- optionally inline `__DEV__`, `process.env.NODE_ENV`, and `Platform.OS`
- optionally eliminate branches of conditionals with constant conditions
- extracts dependencies
- optionally minifies

This will land as part of a multi-commit stack, not in isolation

Reviewed By: martinbigio

Differential Revision: D2976677

fb-gh-sync-id: 38e317f90b6948b28ef2e3fe8b66fc0b9c75aa38
shipit-source-id: 38e317f90b6948b28ef2e3fe8b66fc0b9c75aa38
2016-03-01 04:41:32 -08:00
Martín Bigio 436db67126 Allow parents to accept children modules
Summary:In order to be able to Hot Load Redux stores and modules that export functions, we need to build infrastructure to bubble up the HMR updates similar to how webpack does: https://webpack.github.io/docs/hot-module-replacement-with-webpack.html.

In here we introduce the minimum of this infrastructure we need to make this work. The Packager server needs to send the inverse dependencies to the HMR runtime that runs on the client so that it can bubble up the patches if they cannot be self accepted by the module that was changed.

This diff relies on https://github.com/facebook/node-haste/pull/40/files which adds support for getting the inverse dependencies.

Reviewed By: davidaurelio

Differential Revision: D2950662

fb-gh-sync-id: 26dcd4aa15da76a727026a9d7ee06e7ae4d22eaa
shipit-source-id: 26dcd4aa15da76a727026a9d7ee06e7ae4d22eaa
2016-02-26 15:17:43 -08:00
Adam Miskiewicz b2b41da37f Don't hardcode 'localhost:8081' as the _hmrURL in the Bundler
Summary:martinbigio this fixes your TODO. 🚀 🚀 🚀
Closes https://github.com/facebook/react-native/pull/5827

Differential Revision: D2932188

Pulled By: martinbigio

fb-gh-sync-id: 8c8caf0782f05b51c90c8d09fdb743ddd3e6f97e
shipit-source-id: 8c8caf0782f05b51c90c8d09fdb743ddd3e6f97e
2016-02-26 09:15:56 -08:00
Geoffrey Goh 9ae3714f4b Create offline package if not running in "Debug" config
Summary:**Problem**: As seen in https://github.com/facebook/react-native/issues/5820, many devs are confused by the fact that the offline bundle is not generated when running against the simulator, even when running in the "Release" configuration which is supposed to mimic "production" scenarios.

This pull request is a small change that fixes https://github.com/facebook/react-native/issues/5820 by updating the `react-native-xcode.sh` shell script to still generate the ofline bundle during Release configuration. It also updates `AppDelegate.m` to better document this behaviour in the comments so as to avoid any surprises.

**Test plan**: This is a simple change, the two tests done were
1. In a new React Native project, verify that an offline build is not generated when running against the simulator in "Debug" configuration as per normal.
2. Change to a "Release" configuration via Product > Scheme > Edit Scheme in XCode, then verify that the project runs with the offline build generated.

![screen shot 2016-02
Closes https://github.com/facebook/react-native/pull/6119

Differential Revision: D2970755

Pulled By: javache

fb-gh-sync-id: 64f658512869c73aa19286ca1e3dc6e31b5ac617
shipit-source-id: 64f658512869c73aa19286ca1e3dc6e31b5ac617
2016-02-24 03:11:38 -08:00
David Aurelio b41ad9f5dc Upgrade node-haste to v2.3.0
Summary: This updates to the latest published node-haste version, and also adapts code and tests to that version. Future upgrades should be easier.

Reviewed By: bestander

Differential Revision: D2963144

fb-gh-sync-id: 9fd2c84fc49643fb85ee5d9674a5e458d43d44ca
shipit-source-id: 9fd2c84fc49643fb85ee5d9674a5e458d43d44ca
2016-02-23 06:10:33 -08:00
Christoph Pojer fa3a67e251 Install node-haste2 and remove DependencyResolver
Summary: This installs the 2.0 version of node-haste, removes the DependencyResolver and fixes up all the tests.

Reviewed By: davidaurelio

Differential Revision: D2943416

fb-gh-sync-id: aa83d436a33f910d12ed4cc6e2ad8d5742c123a5
shipit-source-id: aa83d436a33f910d12ed4cc6e2ad8d5742c123a5
2016-02-18 18:03:34 -08:00
Steve Kellock 3415e31f46 Adds additional help when a module is missing.
Summary:Hey.  Long time fan, first time forker.

You know when you're working on a project with someone and they bring in a new dependency?

When you first pull their code and you haven't also installed that dependency, the error that is shown is this:

![image](https://cloud.githubusercontent.com/assets/68273/13145164/d8748b3e-d61c-11e5-9df9-3e47edf3fcfb.png)

This PR simply adds  `or running "npm install"` to the end of that message.

Just adds a little clarity to newcomers.  Hell knows I was lost for a while when I was starting.

![image](https://cloud.githubusercontent.com/assets/68273/13145253/65e8f31a-d61d-11e5-99ac-2d79d8e37123.png)
Closes https://github.com/facebook/react-native/pull/6009

Differential Revision: D2949127

Pulled By: davidaurelio

fb-gh-sync-id: b297d8c1570fec23cb179ddab4847e2438cc463b
shipit-source-id: b297d8c1570fec23cb179ddab4847e2438cc463b
2016-02-18 07:36:35 -08:00
Qiao Liang e0a0cac280 add getter as public api for ErrorUtils._globalHandler
Summary:As discussed here #1194 . This add an getter the default handler, so that custom handler can be added (monkey patch?) without overwriting the default handler
Closes https://github.com/facebook/react-native/pull/5575

Differential Revision: D2948994

fb-gh-sync-id: 2b6d1619cfe68f78b326c6d232b9bf57c489c45d
shipit-source-id: 2b6d1619cfe68f78b326c6d232b9bf57c489c45d
2016-02-18 05:40:31 -08:00
Christoph Pojer 82eeca659e Update + use node-haste2
Summary:This updates jest to 0.9 which will result in *much* faster startup time (1s vs. 10-15s) and better runtime overall (2-3x).

The route gen and cli integration tests are failing locally, but also on master. javache is this expected right now or is this related to my changes?

Reviewed By: javache

Differential Revision: D2943137

fb-gh-sync-id: 8b39ba5f51e30fbc5bacb84d67013ab0a4061f6e
shipit-source-id: 8b39ba5f51e30fbc5bacb84d67013ab0a4061f6e
2016-02-18 00:14:34 -08:00
Martín Bigio 5ec33d1a69 Tweak Hot Loading yellow box wording
Summary: Users don't know what an accept callback is. Lets be more explicit on what type of modules we currently support hot loading.

Reviewed By: weicool

Differential Revision: D2945438

fb-gh-sync-id: d0fc228ab23833371f8fbbd86ed18e81c8ba0ebf
shipit-source-id: d0fc228ab23833371f8fbbd86ed18e81c8ba0ebf
2016-02-17 15:40:30 -08:00
Martín Bigio b5f80065d4 Introduce transformer `cacheKey`
Summary:public

At the moment, the packager's cache can only be broken by changing packager's `package.json` version,by supplying a different `cacheKey` or by updating the `mtime` of the transformer. We need to add support for breaking the cache key when a plugin the transformer use gets updated. To do so, lets introduce a property on the transformer, namely `cacheKey`.

Reviewed By: davidaurelio

Differential Revision: D2940267

fb-gh-sync-id: 82c937d06c73abd32708bf97afe5f308c2a3b565
shipit-source-id: 82c937d06c73abd32708bf97afe5f308c2a3b565
2016-02-17 10:01:43 -08:00
Adam Ernst 97c799a680 Update README.md
Reviewed By: svcscm

Differential Revision: D2924282

fb-gh-sync-id: fe845cfa775470dc71dac8ab3bc62681e04f4f13
shipit-source-id: fe845cfa775470dc71dac8ab3bc62681e04f4f13
2016-02-16 11:59:29 -08:00
Christoph Pojer 9a918ef48f Improve performance of node-haste2 and react-packager
Reviewed By: davidaurelio

Differential Revision: D2911210

fb-gh-sync-id: 8ac2f213e8a9e089281bb065f9a7190d2e0f5b18
shipit-source-id: 8ac2f213e8a9e089281bb065f9a7190d2e0f5b18
2016-02-16 02:01:59 -08:00
David Aurelio 6c55d5b851 Replace custom rolled stable string hashing with library
Reviewed By: cpojer

Differential Revision: D2937202

fb-gh-sync-id: dc08547c71da2bc35cfad108e63fd5e87f0ba734
shipit-source-id: dc08547c71da2bc35cfad108e63fd5e87f0ba734
2016-02-15 06:59:01 -08:00
David Aurelio d7e5392139 Remove test for missing feature
Reviewed By: cpojer

Differential Revision: D2937175

fb-gh-sync-id: 7c348018918a509e1cd681dfa8df9151b94ce765
shipit-source-id: 7c348018918a509e1cd681dfa8df9151b94ce765
2016-02-15 06:33:31 -08:00
Martín Bigio 3781bf974d Fix RAM detection logic
Reviewed By: davidaurelio

Differential Revision: D2932012

fb-gh-sync-id: ae2340de09ec3a4fae9371c3b8e6148d4ef267b8
shipit-source-id: ae2340de09ec3a4fae9371c3b8e6148d4ef267b8
2016-02-12 08:28:30 -08:00
David Aurelio 727a2a95d1 Let the module cache depend on transform options
Reviewed By: martinbigio

Differential Revision: D2921693

fb-gh-sync-id: 6f95bdb03d59183a1b5f50db16c6aab2b16d3146
shipit-source-id: 6f95bdb03d59183a1b5f50db16c6aab2b16d3146
2016-02-12 06:14:32 -08:00
Adam Miskiewicz 28116ec3db Reverted commit D2803288
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on https://github.com/facebook/fbjs/pull/95. **DO NOT MERGE** until #95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes https://github.com/facebook/react-native/pull/5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: javache

fb-gh-sync-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
shipit-source-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
2016-02-11 02:45:34 -08:00
Adam Miskiewicz 98e5e2b427 Remove knowledge of fbjs from the packager
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on https://github.com/facebook/fbjs/pull/95. **DO NOT MERGE** until #95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes https://github.com/facebook/react-native/pull/5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: davidaurelio

fb-gh-sync-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
shipit-source-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
2016-02-11 02:21:37 -08:00
David Aurelio 7c03b16a1b / [node-haste] Remove support for asynchronous dependencies (`System.import`)
Summary:
public
Remove the unused feature for async dependencies / bundle layouts. We can bring it back later, if needed.

Reviewed By: cpojer

Differential Revision: D2916543

fb-gh-sync-id: 3a3890f10d7d275a4cb9371a6e9cace601a82b2c
shipit-source-id: 3a3890f10d7d275a4cb9371a6e9cace601a82b2c
2016-02-09 17:17:57 -08:00
David Aurelio 6b74535e97 Clean up Bundler
Summary:
The bundler class had duplicated code and parts that were hard to follow, because functions accepted heterogenous arguments, leading to a lot of conditionals.

This commit tries to remove duplication between build steps of different type of bundles, and by accepting less different types of arguments. These differences are now handled further up the call stack.

public

Reviewed By: sebmarkbage

Differential Revision: D2905807

fb-gh-sync-id: ef85ea0d461a9a06a4a64480e014a5324c4ef532
2016-02-08 11:19:31 -08:00
Christopher Chedeau 577206fe51 Remove String.prototype.contains polyfill
Summary:
Now that String.prototype.includes is there, we should remove the .contains one which has not been standardized.

For fb reviewers, this needs to land after D2910339 which updates internal callsites.
Closes https://github.com/facebook/react-native/pull/5794

Reviewed By: svcscm

Differential Revision: D2910855

Pulled By: vjeux

fb-gh-sync-id: 8fd216222385f038995d1ed10e8a2c4c34c7e928
2016-02-07 16:42:33 -08:00
Corentin Smith 2f73ad0241 Add String.prototype.includes polyfill
Summary:
Add a polyfill for `String.prototype.includes` taken from MDN (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
See https://github.com/facebook/react-native/issues/5727
Closes https://github.com/facebook/react-native/pull/5735

Reviewed By: svcscm

Differential Revision: D2906667

Pulled By: vjeux

fb-gh-sync-id: e02f605bf57171062b29a98b98ba9fc898cedfc2
2016-02-05 12:09:33 -08:00
Nick Lockwood 81fb985335 Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.

This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).

I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.

Reviewed By: martinbigio

Differential Revision: D2895619

fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-03 17:30:39 -08:00
Adam Miskiewicz e6cb02d61a Use "babel-preset-react-native"
Summary:
Rather than specifying Babel plugins in the `.babelrc` packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native).

This allows for a much better user experience for those who want (or need) to override options in their project's `.babelrc`.

Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the `.babelrc` in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own `.babelrc`. Note - the custom transformer was necessary because without it, RN's `.babelrc` options would supersede the options defined in the project's `.babelrc`...potentially causing issues with plugin ordering.

This PR makes the transformer check for the existence of a project-level `.babelrc`, and if it it's there, it _doesn't_ use the react-native `.babelrc`. This prevents any oddities with Babel plug
Closes https://github.com/facebook/react-native/pull/5214

Reviewed By: davidaurelio

Differential Revision: D2881814

Pulled By: martinbigio

fb-gh-sync-id: 4168144b7a365fae62bbeed094d8a03a48b4798c
2016-02-03 08:15:32 -08:00
Christoph Pojer 55f4e55109 Move process.exit outside of DependencyResolver
Summary:
node-haste shouldn't ever call process.exit and should leave it up to clients to shut down properly. This change just moves it out into the `Resolver` class – I'll leave it up to David and Martin to improve error handling for the rn packager :)

public

Reviewed By: davidaurelio

Differential Revision: D2889908

fb-gh-sync-id: 6f03162c44d89e268891ef71c8db784a6f2e081d
2016-02-02 18:10:47 -08:00
Christoph Pojer 5ca519de29 Add mocks for packages to resolution responses
Summary:
Right now, a mock called `debug.js` shadows a node module called `debug`. When I made mocking more strict I didn't realize that it didn't include those mocks any more because requiring `debug` would result in a module like `debug/node.js` which doesn't have a mock associated with it. This diff changes it so it looks at the associated `package.json` to match the name up to mocks. This is the least invasive non-breaking change I can make right now. Yes, mocking strategies are basically fucked but I don't want the haste2 integration to have even more breaking changes right now. Consider this code to be temporary, I'll fix this and make the mocking system more sane mid-term.

public

Reviewed By: davidaurelio

Differential Revision: D2889198

fb-gh-sync-id: 58db852ed9acad830538245f7dc347365fe4de38
2016-02-02 17:50:33 -08:00
David Aurelio 8c62ed7c95 Use `fastfs.readWhile` to parse module docblocks
Summary:
Uses `fastfs.readWhile` to build the haste map

- cuts the time needed to build the haste map in half
- we don’t need to allocate memory for all JS files in the tree
- we only read in as much as necessary during startup
- we only read files completely that are part of the bundle
- we will be able to move the transform before dependency extraction

public

Reviewed By: martinbigio

Differential Revision: D2890933

fb-gh-sync-id: 5fef6b53458e8bc95d0251d0bcf16821581a3362
2016-02-02 15:48:37 -08:00
Jan Kassens 80e1ca870b move Relay sources to unsigned directory
Reviewed By: yungsters

Differential Revision: D2887448

fb-gh-sync-id: 53e71be7fa875b3495991f2bf941c5eeb6ae1534
2016-02-01 20:12:19 -08:00
Christoph Pojer 361f3f30d3 Fix shallow dependency resolution
Summary:
The feature added in D2862850 only adds the module that requests shallow dependency resolution to the dependencies of a module. The reason why this is happens is because `collect` calls `response.addDependency` but if `recursive` is set to `false`, dependencies don't call `collect` and therefore don't get added to the resolution response. This fixes it by adding dependencies outside of the `collect` call.

public

Reviewed By: davidaurelio

Differential Revision: D2885152

fb-gh-sync-id: 8ab3b6c6b7cd45d59615a99ac87984a41b5d7025
2016-02-01 19:08:36 -08:00
Christoph Pojer db275dd49f Updates from GitHub
Summary:
This syncs a couple of changes from GitHub that are necessary for jest:

* Expose `set` on Cache
* Add a function to `getAllModules` from the graph
* Explicitly dontMock `graceful-fs` in the fastfs test. node-haste2 has this manual mock which is still used in automocked tests (ugh!).

public

Reviewed By: davidaurelio

Differential Revision: D2885112

fb-gh-sync-id: b2060d5474ebee5aa13e6ba2bdf5879b46f3fd5f
2016-02-01 18:27:36 -08:00
Christoph Pojer 700b848826 Expose fastfs on the DepencenyGraph instance.
Summary:
The FS as seen by an instance of a dependency graph is useful for clients of node-haste. This provides an accessor to fastfs so that the partial view of the filesystem can be queried. I was thinking of splitting out the fastfs creation to outside the constructor but the necessary refactoring doesn't seem worth it. The fastfs is intrinsically tied to the dependency graph and the `DependencyGraph` instance is meant to be a base-class for clients anyway. Both in react-packager and jest we are wrapping it with higher-level client specific containers, Resolver and HasteResolver respectively.

public

Reviewed By: davidaurelio

Differential Revision: D2885217

fb-gh-sync-id: 47a408b2682516bee9d6a4e6c61b9063817aaf22
2016-02-01 17:00:38 -08:00
David Aurelio f04882f8e4 Fix problems with graceful-fs bug
Summary:
public
This fixes the problem that graceful-fs exposes an unpatched `close()` method, that will never trigger retries.
This behavior deadlocks the packager when trying to use graceful-fs’s `open()`/`read()`/`close()` methods.

See: isaacs/node-graceful-fs#56

Reviewed By: cpojer

Differential Revision: D2885512

fb-gh-sync-id: 71112d2488929bf1775fe9f8566fa03fd66b6bea
2016-02-01 10:00:40 -08:00
Shane Rogers 97723e4d7e Typo
Summary:
Tiny typo :)

🐝 🍻
Closes https://github.com/facebook/react-native/pull/5665

Reviewed By: svcscm

Differential Revision: D2885581

Pulled By: androidtrunkagent

fb-gh-sync-id: 4f442a95ea05e2f58c47c664644210c99e256943
2016-02-01 07:43:33 -08:00
Christoph Pojer 9308f89c1c Add per-field cache invalidation
Summary:
Jest needs this for efficient caching of resolution responses.

public

Reviewed By: voideanvalue

Differential Revision: D2873291

fb-gh-sync-id: fee27d2ffdfe64bd68fdb4d9e4259e721b33631f
2016-01-31 23:25:32 -08:00
Sam Neubardt 23412459b2 Handle spaces in $REACT_NATIVE_DIR
Summary:
`react-native-xcode.sh` can fail to execute if `$REACT_NATIVE_DIR` contains spaces.

E.g. if `$REACT_NATIVE_DIR` was `/Users/samn/src/Xcode Projects/AwesomeReact` then `react-native-xcode.sh` would fail with the following error:

```
node /Users/samn/src/Xcode Projects/ReactNativeBeaconTest/node_modules/react-native/local-cli/cli.js bundle .... (elided)

module.js:341
    throw err;
    ^

Error: Cannot find module '/Users/samn/src/Xcode'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:139:18)
    at node.js:999:3
Command /bin/sh failed with exit code 1
```

This change properly handles paths with spaces in them by quoting `$REACT_NATIVE_DIR`
Closes https://github.com/facebook/react-native/pull/5651

Reviewed By: svcscm

Differential Revision: D2884600

Pulled By: androidtrunkagent

fb-gh-sync-id: 3784d8f4e16c0c2cadac738c5f085a5023b5ecf7
2016-01-31 15:51:36 -08:00
Austin Kuo d3a1d27aaa Improve the error message when the packager can't find a module
Summary: Closes https://github.com/facebook/react-native/pull/5647

Reviewed By: svcscm

Differential Revision: D2884241

Pulled By: androidtrunkagent

fb-gh-sync-id: 115491270c8f84d45f67a1a477543d9ace76f447
2016-01-31 06:45:35 -08:00
Jan Kassens 1bc03871f3 remove ReactDOM from Jest blacklist
Reviewed By: yungsters, spicyj

Differential Revision: D2875010

fb-gh-sync-id: d316d5befd0d978bded99f70b814dc133c85b40f
2016-01-29 18:18:33 -08:00
Martín Bigio 68f71dab4c Make HMR faster (2)
Summary:
public

The HMR listener needs to be invoked on the non debounced callback to avoid loosing updates if 2 files are updated within the debounce configured time.

Also, improve the time it takes to send HMR updates by avoiding rebuilding the bundle when the listener is defined. Instead just invalidate the bundles cache so that if the user reloads or disables Hot Loading the packager rebuilds the requested bundle.

Reviewed By: davidaurelio

Differential Revision: D2863141

fb-gh-sync-id: 3ab500eacbd4a2e4b63619755e5eabf8afdd1db9
2016-01-29 10:15:41 -08:00
Martín Bigio 65b8ff17f3 Make HMR faster
Summary:
public

At the moment, when the user changes a file we end up pulling the dependencies of the entry point to build the bundle. This could take a long time if the bundle is big. To avoid it, lets introduce a new parameter to `getDependencies` to be able to avoid processing the modules recursively and reuse the resolution responseto build the bundle.

Reviewed By: davidaurelio

Differential Revision: D2862850

fb-gh-sync-id: b8ae2b811a8ae9aec5612f9655d1c762671ce730
2016-01-29 10:15:36 -08:00
David Aurelio b9ceecb31f Adapt tests to new Object/es7 polyfill
Summary:
public

Adds the new polyfill to the relevant tests (Resolver/BundlesLayout)

Reviewed By: martinbigio

Differential Revision: D2878697

fb-gh-sync-id: 9681f16dd19a0b337aac63101450c703bf387346
2016-01-28 22:02:31 -08:00
David Aurelio 2d9876dedf Add partial reading of files to fastfs
Summary:
public

Adds the ability to read files partially with `readWhile` to `Fastfs`
This feature will be used by for building the haste map, where we only need to read the doc block (if present) to extract the provided module name.

Reviewed By: martinbigio

Differential Revision: D2878093

fb-gh-sync-id: 219cf6d5962b89eeb42c728e176bf9fcf6a67e9c
2016-01-28 21:19:31 -08:00
Dmitry Soshnikov 598df0bc20 Add Object.entries and Object.values polyfill
Reviewed By: martinbigio

Differential Revision: D2876430

fb-gh-sync-id: 25c7680a71c9187beb937f6faf030a83c9c81fc5
2016-01-28 17:21:31 -08:00
Martín Bigio 181896e4d9 Move HMR to external transformer
Summary:
public

`babel-plugin-react-transform` doesn't support to run on transformed code (it doesn't detect some react components). The reason why HMR was originally on the internal transform was so that it worked with non JS code (TypeScript, Coffeescript, etc), but looks like this is not very popupar in the community, maybe because the JS ecosystem is getting better everyday.

So long story short, for now lets move HMR to the external transformer. This should also give us a perf boost.

Reviewed By: davidaurelio

Differential Revision: D2870973

fb-gh-sync-id: 68ca8d0540b88b9516b9fef10643f93fc9b530d2
2016-01-28 17:02:32 -08:00
Dave Miller 0b39c72bfa Fix bundler to not do as many passes in optimization
Reviewed By: davidaurelio

Differential Revision: D2876894

fb-gh-sync-id: b652ff77dd442a82c16f3b446c931fb985a2efcd
2016-01-28 16:36:31 -08:00
David Aurelio a61ab8795a Add transform option to module / module cache
Summary:
public

This adds an option to `Module` (and its callers) that allows to transform code before extracting dependencies. The transform function has to return a promise that resolves to an object with `code`, and optionally `dependencies` and/or `asyncDependencies` properties, if standard dependency extraction cannot be applied

Reviewed By: cpojer

Differential Revision: D2870437

fb-gh-sync-id: 806d24ba16b1693d838a3fa747d82be9dc6ccf00
2016-01-28 16:29:33 -08:00
Adam Miskiewicz b7b27bdf25 Fixing typo in Bundler
Summary:
With an upgraded Babel dependency, failing tests correctly found this typo.

It does not currently cause a test failure in the current version of master, however,
which is concerning. I found it when testing #5214.

cc martinbigio just because it was your code :)
Closes https://github.com/facebook/react-native/pull/5601

Reviewed By: svcscm

Differential Revision: D2876386

Pulled By: androidtrunkagent

fb-gh-sync-id: 378da39be79ac1b9a950ea9a7442ac24c0c3a87d
2016-01-28 15:18:31 -08:00
Christoph Pojer 3117a334b1 Limit mocks shared with a resolution response
Reviewed By: davidaurelio

Differential Revision: D2872340

fb-gh-sync-id: a76b580ff670115cd4bd0098e7b9f31110239369
2016-01-27 18:47:33 -08:00
Martín Bigio f2438b440d Hot Loading Sourcemaps
Summary:
public

To make sourcemaps work on Hot Loading work, we'll need to be able to serve them for each module that is dynamically replaced. To do so we introduced a new parameter to the bundler, namely `entryModuleOnly` to decide whether or not to process the full dependency tree or just the module associated to the entry file. Also we need to add `//sourceMappingURL` to the HMR updates so that in case of an error the runtime retrieves the sourcemaps for the file on which an error occurred from the server.

Finally, we need to refactor a bit how we load the HMR updates into JSC. Unfortunately, if the code is eval'ed when an error is thrown, the line and column number are missing. This is a bug/missing feature in JSC. To walkaround the issue we need to eval the code on native. This adds a bit of complexity to HMR as for both platforms we'll have to have a thin module to inject code but I don't see any other alternative. when debugging this is not needed as Chrome supports sourceMappingURLs on eval'ed code

Reviewed By: javache

Differential Revision: D2841788

fb-gh-sync-id: ad9370d26894527a151cea722463e694c670227e
2016-01-27 14:55:36 -08:00
Martín Bigio 825ba6cf48 Inline Require every module but the preloaded ones
Reviewed By: javache

Differential Revision: D2858983

fb-gh-sync-id: b73de54163d7b75891cb00be96ffb4556d3311a3
2016-01-27 07:41:36 -08:00
Christoph Pojer 7e64ad8fc4 Fix some lint nits
Reviewed By: voideanvalue

Differential Revision: D2862332

fb-gh-sync-id: 19ab5e8a580137ffe6276b21a9018f7b322dd0cb
2016-01-26 11:16:39 -08:00
Christoph Pojer 6b75d7f497 Expose `has` method on Cache.
Reviewed By: davidaurelio

Differential Revision: D2862315

fb-gh-sync-id: 03728a2593b477aef3bbfe01d42382893a05ea50
2016-01-26 10:51:28 -08:00
Alex Kotliarskyi 5f0ef12cb5 Skip bundling for Simulator
Summary:
Following up on the conversation in https://www.prod.facebook.com/groups/reactnativeoss/permalink/1516993445263951/ I currently don't see any good reason to create an offline bundle for simulator builds.
Closes https://github.com/facebook/react-native/pull/5519

Reviewed By: svcscm

Differential Revision: D2859751

Pulled By: mkonicek

fb-gh-sync-id: f70481e447e258f5531de773729fc31d9ebec6f7
2016-01-26 08:21:29 -08:00
Alex Kotliarskyi d3e44143f6 Improve react-native-xcode.sh integration
Summary:
Inspired by conversation in https://github.com/facebook/react-native/pull/5374, this PR improves `react-native-xcode.sh`:

* No longer depends on global `react-native` binary
* Gracefully handles missing `node` dependency and adds a new way to configure the path to `node` in non-standard installation environments

This is how the error looks like:
![image](https://cloud.githubusercontent.com/assets/192222/12538882/3f9b5c3e-c29a-11e5-84fc-c7ccedf1c46a.png)
Closes https://github.com/facebook/react-native/pull/5518

Reviewed By: svcscm

Differential Revision: D2861116

Pulled By: frantic

fb-gh-sync-id: 9a80eda6c844d066e34369b1cda503955171485b
2016-01-25 12:36:33 -08:00
Mark Vayngrib 191b692e05 breaking test and fix for browser field mapping from package to file
Summary:
breaks on mappings like:

```json
"browser": {
  "node-package": "./dir/browser.js"
}
```
Closes https://github.com/facebook/react-native/pull/5505

Reviewed By: svcscm

Differential Revision: D2860579

Pulled By: androidtrunkagent

fb-gh-sync-id: 0d64c0999c47a6cbbf084cc8e0c8a6ea209b0880
2016-01-25 10:09:33 -08:00
James Ide 0893d07db1 Revert "Enable JSX files extension"
Summary:
This reverts commit 888749220d.

The original commit didn't handle cases like .(ios|android|native).js, and vjeux is in favor of standardizing on .js instead of custom extensions like .jsx or .es6 everywhere.

> Unfortunately this pull request doesn't implement with .ios.jsx. But, when/if it does, it raises more questions like what happens if you have both ios.js and ios.jsx?
>
> Sorry to chime in super late but I actually think that this is harmful to support .jsx extension. We now live in a world where we have many transforms for es6, flow, jsx... Why would we add .jsx but not .flow or .es6. Supporting more extensions is only going to fragment tools even more.

https://github.com/facebook/react-native/pull/5233#discussion_r49682279
Closes https://github.com/facebook/react-native/pull/5296

Reviewed By: svcscm

Differential Revision: D2830784

Pulled By: bestander

fb-gh-sync-id: 9a7a4745803acbcbc5dba176b971c629c904bacd
2016-01-25 05:33:32 -08:00
David Aurelio a23785ca2e Pass on the bundle name rather than the ID when getting transform options
Summary:
public

This is needed to bring numerical module IDs back.

The numerical ID of the main module will always be `0` and is therefore of no use when used as conditional. We have to pass on the name, which will be preserved, when requesting transform options.

Reviewed By: martinbigio

Differential Revision: D2855106

fb-gh-sync-id: f9bc40e753b1b283ce0b00068e3c9964a541ad9b
2016-01-22 13:55:29 -08:00
David Aurelio a0c5fb99a0 Backout "Use numeric identifiers when building a bundle"
Summary:
public

The reverted change doesn’t play nice with inline requires, let’s revert it for now.
I will bring it back after fixing it or adapting inline requires

Reviewed By: martinbigio

Differential Revision: D2854771

fb-gh-sync-id: 32fdbf8ad51240a9075b26502decb6328eed4b29
2016-01-22 11:39:30 -08:00
David Aurelio 722bc73c0d Distinguish between module ID and name
Reviewed By: martinbigio

Differential Revision: D2854975

fb-gh-sync-id: 8c75037d5d7f6155369d4ec581158ebabf445bac
2016-01-22 10:40:29 -08:00
David Aurelio 89207a1171 `require` implementation for unbundles: Systrace and guard
Summary:
public

Adds two feature to the require implementation for unbundled code:
- Ports Systrace from `require.js`
- Prevents already loaded modules from being overwritten by repeated calls to `nativeRequire` with the same ID

Reviewed By: martinbigio

Differential Revision: D2850345

fb-gh-sync-id: 122e2d5d4a64b2e868d4cf6e5079810f59b1db18
2016-01-21 14:14:08 -08:00
David Aurelio 17e1ceb543 Add ability to load “unbundles” to android
Summary:
public

This adds the ability to load “unbundles” in RN android apps. Unbundles are created by invoking the packager with the `unbundle` command rather than `bundle`.

The code detects usage of an “unbundle” by checking for the existence of a specific asset.

Reviewed By: astreet

Differential Revision: D2739596

fb-gh-sync-id: d0813c003fe0fa7b47798b970f56707079bfa5d7
2016-01-21 14:13:50 -08:00
Martín Bigio 0963192b18 Bump js/package.json version to clear cache
Reviewed By: sam-swarr

Differential Revision: D2851399

fb-gh-sync-id: 0fbeb7d4c6d669f981e3f5139387e506a3670931
2016-01-21 13:57:42 -08:00
tfallon@mail.depaul.edu 528e30987a Adding ETag handling to packager improves local development
Summary: Closes https://github.com/facebook/react-native/pull/2473

Reviewed By: svcscm

Differential Revision: D2669385

Pulled By: mkonicek

fb-gh-sync-id: bb9ee4a309a05e0da0ccc7663a373f4a53b9a0a2
2016-01-21 13:00:35 -08:00
Martin Konicek dc96935681 Fix a tiny typo in error message
Reviewed By: davidaurelio

Differential Revision: D2850195

fb-gh-sync-id: 8177ce2f8d7f799edc559b4f5a0da99d865874a7
2016-01-21 10:59:59 -08:00
David Aurelio cb4fca3590 Use numeric identifiers when building a bundle
Summary:
public

Since the combination of node and haste modules (and modules that can be required as both node and haste module) can lead to situations where it’s impossible to decide an unambiguous module identifier, this diff switches all module ids to integers. Each integer maps to an absolute path to a JS file on disk.

We also had a problem, where haste modules outside and inside node_modules could end up with the same module identifier.

This problem has not manifested yet, because the last definition of a module wins. It becomes a problem when writing file-based unbundle modules to disk: the same file might be written to concurrently, leading to invalid code.

Using indexed modules will also help indexed file unbundles, as we can encode module IDs as integers rather than scanning string IDs.

Reviewed By: martinbigio

Differential Revision: D2842418

fb-gh-sync-id: 97addd28e964ac5f2b5081dcd3f36124d2864df8
2016-01-21 10:37:15 -08:00
Martín Bigio 4362e98170 Unit test reloading when hot loading is enabled
Reviewed By: sahrens

Differential Revision: D2824276

fb-gh-sync-id: a81acd20eb5b7d3da61becac00e4bdbea6b61a2f
2016-01-21 09:52:33 -08:00
Martín Bigio c888e6583f Unit test `worker.js`
Summary:
public

We had a bug a few weeks ago which caused transform errors not to be shown properly. The problem was on this piece of code, so lets unit test it.

Reviewed By: davidaurelio

Differential Revision: D2849990

fb-gh-sync-id: 9f6bb8a8b7d59bbaa3577c29cee37fb23a50d66f
2016-01-21 09:10:37 -08:00
Martín Bigio 5d9163b87d Improve error message
Summary:
There's a long standing issue on open source (https://github.com/facebook/react-native/issues/4968). Until someone gets some free bandwidth to fix it lets at the very least improve the error message to guide users to the issue and suggest workarounds.

public

Reviewed By: mkonicek

Differential Revision: D2849051

fb-gh-sync-id: ef7913442ceabcab2076141bd13ab1ceeb529759
2016-01-21 08:16:34 -08:00
Janic Duplessis d33b554f5d Make the packager work with babel strict mode transform
Summary:
At the moment we have to disable strict mode for the transform-es2015-modules-commonjs because strict mode leaks to the global scope and breaks the bridge. It was due to the way the polyfills were bundled in the package. To fix it, I wrapped the polyfill modules in an IIFE. Then when strict mode was enabled some polyfills were broken due to strict mode errors so that was fixed too. Also removed the IIFE from the polyfills that included one.

This diff doesn't enable the strict mode transform since some internal facebook modules depend on it not being enabled. When #5214 lands we could make the default babel config shipped with OSS react-native use strict mode modules and facebook could just modify the babel config to disable it if needed.

This will allow removing `"strict": false` from https://github.com/facebook/react-native/blob/master/packager/react-packager/.babelrc#L16

Fixes #5316
Closes https://github.com/facebook/react-native/pull/5422

Reviewed By: svcscm

Differential Revision: D2846422

Pulled By: davidaurelio

fb-gh-sync-id: a3e2f8909aa87dabab2b872c61b887e80220fb56
2016-01-21 07:23:34 -08:00
Pieter De Baets 1dffd056bf Fix default logger's loglevel, improve default error handler
Reviewed By: majak

Differential Revision: D2834267

fb-gh-sync-id: c89ce5160f03f57409497cc802690c8360d88a4d
2016-01-20 10:28:38 -08:00
Jan Kassens 52c2533b66 add babelHelpers.toArray to polyfill
Reviewed By: yungsters, davidaurelio

Differential Revision: D2844203

fb-gh-sync-id: 6e76ed51265150108ef91ca64c5c5d930f14982e
2016-01-20 10:26:30 -08:00
Martín Bigio 4afeb4310b Simplify HMR codepath
Reviewed By: davidaurelio

Differential Revision: D2839590

fb-gh-sync-id: 9bb14cafc69eec7d7a8712b60435e29f2ba48d3c
2016-01-20 07:14:33 -08:00
Emil Sjölander 3453a60bf8 Escape directory path in packager.sh
Summary:
Previously could not handle directory paths with spaces.
Closes https://github.com/facebook/react-native/pull/5381

Reviewed By: svcscm

Differential Revision: D2839193

Pulled By: javache

fb-gh-sync-id: e95825a602c053761826255ac5254b97fadbe090
2016-01-18 12:42:33 -08:00
Martín Bigio c9f274c02d Send assets updates through HRM interface
Reviewed By: frantic

Differential Revision: D2832693

fb-gh-sync-id: 816a01fa2f1f7cc8ca218de86b3e2e847ee005c9
2016-01-15 10:52:31 -08:00
Martín Bigio 38486dcbba Throw if there's an error persisting the cache
Reviewed By: davidaurelio

Differential Revision: D2824116

fb-gh-sync-id: 46b3c51a11d22e2da750f9c5a4b431a88004cd81
2016-01-15 10:32:29 -08:00
Christoph Pojer dd06596595 Don't extract dependencies from .json files
Reviewed By: davidaurelio

Differential Revision: D2832417

fb-gh-sync-id: 8bf3705bf620f3cc6d713ca08dde52464185797a
2016-01-15 10:06:33 -08:00
Kyle Corbitt cd89016ee7 PixelRatio.pixel()
Summary:
This implements #5073. It adds a static method `PixelRatio.pixel()` which returns the smallest drawable line width, primarily for use in styles.

It also updates the example apps to use the new function.
Closes https://github.com/facebook/react-native/pull/5076

Reviewed By: svcscm

Differential Revision: D2799849

Pulled By: nicklockwood

fb-gh-sync-id: b83a77790601fe882affbf65531114e7c5cf4bdf
2016-01-15 05:15:31 -08:00
Martín Bigio bba35f0415 Make Hot Loading work on OSS
Summary:
public

- Tweak OSS server to enable the HMR connection
- Remove client gating code.
- Resolve internal transforms plugins

After this diff, Hot Loading should work on OSS.

Reviewed By: javache

Differential Revision: D2803620

fb-gh-sync-id: b678180c884d2bfaf454edf9e7abe6b3b3b32ebe
2016-01-14 19:33:42 -08:00
Christoph Pojer 4074b7980e Cache all module data
Summary:
We used to only cache the `dependencies` and `name` of a Module but we were actually accessing two more fields (async dependencies and the `isHaste` field) which meant we were always reading every single file from disk. In D2644383 I noticed that but realized that the Promise was cached, meaning we would read every file once *per instance* and I didn't think about cross-instance reads over time. My initial version added more caching (but also missed the `isHaste` field) but then I got rid of the cache call for `dependencies`. So my change from before didn't make anything worse but it also didn't make anything better. This change now caches everything until the contents of the file actually changes.

public

Reviewed By: martinbigio

Differential Revision: D2831569

fb-gh-sync-id: 74081abc0ce3ca96b4e56c3c9b6d24aa84f7496c
2016-01-14 13:48:33 -08:00
Martín Bigio 51621b14cb Get rid of deprecated `fs.existSync`
Reviewed By: mmahoney

Differential Revision: D2824569

fb-gh-sync-id: efed6e88f566110b8286ea59563c2904b3dd8059
2016-01-12 16:45:33 -08:00
Christoph Pojer 801b83da2d Support "free" mocks.
Summary:
It's possible that a mock doesn't have an associated real module that it maps to. This is actually very common in www, where we have JS mocks for dynamic PHP JS modules. The implementation I chose seems like the smartest one for now: if a module cannot be resolved, we look up whether we have a mock with the same id. If we do, we just resolve it. That's it! And it also only does the minimum amount of resolution necessary.

public

Reviewed By: martinbigio

Differential Revision: D2822277

fb-gh-sync-id: 7c9fbb6f69a0c0c85157c0650f5719d94a02410e
2016-01-12 15:33:32 -08:00
Kelvin De Moya 888749220d Enable JSX files extension
Summary:
JSX extension is much used in React, this would be a natural addition for React Native.
See: https://github.com/facebook/react-native/issues/2303
Closes https://github.com/facebook/react-native/pull/5233

Reviewed By: svcscm

Differential Revision: D2818888

Pulled By: mkonicek

fb-gh-sync-id: 856d1b8ba9ff88ba08a00923174e3284f359d774
2016-01-12 08:25:36 -08:00
Martín Bigio cb91d652fa Include socket interface logs when timing out on transformer
Reviewed By: davidaurelio

Differential Revision: D2819820

fb-gh-sync-id: 066fd1191c459cf3434899de6326e25f798c4b07
2016-01-11 09:38:32 -08:00
Martin Bigio 2f3f84eecd Bump timeout to track intermittent error
Reviewed By: sam-swarr

Differential Revision: D2816605

fb-gh-sync-id: 3d05746493f0ff97c396c82eb30d9a49537a0473
2016-01-08 13:39:28 -08:00
Martín Bigio 8604bd1812 Add option to disable internal transforms
Reviewed By: davidaurelio

Differential Revision: D2815307

fb-gh-sync-id: 17ed8f13de7b4c41111efa4a5f2af5283e6ef3e0
2016-01-08 11:10:29 -08:00
Christoph Pojer 36dbe86208 Use graceful-fs directly
Reviewed By: davidaurelio

Differential Revision: D2811784

fb-gh-sync-id: 95e4fd1538f4cd468288dc65e83f1d6ca98ce791
2016-01-08 08:37:29 -08:00
David Aurelio 324493edae Require transform file eagerly in transform worker
Summary:
One consequence we didn't predict after introducing the Internal Transform Pipeline, was that when the workers would get started, we won't require the external transformer the user specified up until the first time each worker received a job. There're 2 visible consequences of this: (1) the transform progress bar seems to get stuck for about 5 seconds the first time the packager receives a request and (2) the first N (# of cores) HMR requests take way longer (about 4 seconds with FB's transformer instead of << 1 second) as we need to require lots of modules.

This diff creates a temporary file for the js transformer workers that requires the user-specified transform file eagerly.
That makes sure workers have imported babel and the transforms before receiving the first request.

There are better ways to do this, like adding an `init()` method to the workers and call that eagerly. I will follow with another diff doing that.

public

Reviewed By: javache

Differential Revision: D2812153

fb-gh-sync-id: 15be316b792d1acd878ed9303bea398aa0b52e1d
2016-01-08 08:35:32 -08:00
Christoph Pojer 83ddd74ac7 Make Cache dir configurable
Reviewed By: davidaurelio

Differential Revision: D2811278

fb-gh-sync-id: 77c03a8f806135fff56914bac60c156d10b05ea4
2016-01-08 06:56:27 -08:00
Christoph Pojer b84ad2ab0d Updates for haste2 inside of jest
Summary:
I'm working on deploying haste2 with jest. This updates all the files that require changes for this to work and they are backwards compatible with the current version of jest.

* package.json was just outdated. I think haste1's liberal handling with collisions made this a "non-issue"
* env.js didn't properly set up ErrorUtils, also unsure why that isn't a problem in jest right now already?
* some things were mocking things they shouldn't
* Because of the regex that matches against providesModule and System.import, it isn't possible to list module names more than once. We have multiple tests reusing the same providesModule ids and using System.import with modules that only exist virtually within that test. Splitting up the strings makes the regexes work (we do the same kind of splitting on www sometimes if we need to) and using different providesModule names in different test files fixes the problem. I think the BundlesLayoutIntegration-test is going to be deleted, so this doesn't even matter.

public

Reviewed By: voideanvalue

Differential Revision: D2809681

fb-gh-sync-id: 8fe6ed8b5a1be28ba141e9001de143e502693281
2016-01-08 06:52:29 -08:00
Martín Bigio b9c5f753aa Fixes Hot Loading re-loading bug
Summary:
public

Fixes a terrible bug due to which when Hot Loading enabled when the user reloads we'll serve them the first `hot` bundle he requested. This happened because when HMR enabled we bailed out after sending the HMR updates and didn't rebuild any of the bundles the user requested before. As a consequence, when they reload we'd sent him the first and only one we ever built.

The fix is to tweak the hmr listener to return a promise. This way we can run the remaining code on the file change listener just after the HMR stuff finishes. We need to do it this way to avoid the remaining stuff to compete for CPU with the HMR one and give the best possible experience when HMR is enabled.

Reviewed By: davidaurelio

Differential Revision: D2811382

fb-gh-sync-id: 906932d71f35467485cf8a865a8d59f4d2ff41a0
2016-01-07 12:03:58 -08:00
Martín Bigio 2b09614068 Skip file removal on HMR interface
Summary:
public

We're not planning to accept file removals in the short term on the HMR interface so lets bail when a file is removed (before this this we were throwing when trying to get the shallow dependencies).

Reviewed By: yungsters

Differential Revision: D2810534

fb-gh-sync-id: f2733382f4a2619e22bdf1163aa4180694fff9f8
2016-01-07 12:02:47 -08:00
Christoph Pojer 6579b705e9 Add option to throw/not throw when module can't resolve
Reviewed By: martinbigio

Differential Revision: D2808973

fb-gh-sync-id: 2e06355d1e0dd3c1ea297273c44858ec4ed574ee
2016-01-07 12:01:47 -08:00
Martín Bigio 7bb60449bd Bail internal transforms if there're no transforms to run
Reviewed By: sam-swarr

Differential Revision: D2810474

fb-gh-sync-id: d5ba48922c91c3dbacfccb0d087cc1deac14fa1c
2016-01-06 20:04:27 -08:00
Henrik Kok Jørgensen 7ecb6936bc Dont call npm before node is available
Summary:
This fixes an error introduced in `0.18.0-rc`

`node` and `npm` isn't available if the developer is using `nvm` or `nodeenv`. XCode throws an error because of the call to `npm`. Simple move the line to after `node` and `npm` has been setup.
Closes https://github.com/facebook/react-native/pull/5156

Reviewed By: svcscm

Differential Revision: D2807589

Pulled By: androidtrunkagent

fb-gh-sync-id: 30c33145b2cb6f30ff67f6648153d5aa67fb74ed
2016-01-06 11:03:34 -08:00
Martín Bigio 51d8ed92d5 Move HMR to internal transform
Summary:
public

We want to support Hot Loading on the packager itself instead of on the transformer. This will allow us to enable it on OSS (and for any scripting language, yay!).

For now to enable Hot Loading the packager's internals transforms need to be manually enabled (start packager with `--enable-internal-transforms`). I think the internal pipeline should always be enabled as it doesn't affect performance if there're no transforms and the user can disable Hot Loading through the setting on the app though. I'll tweak this on a follow up commit.

Reviewed By: vjeux

Differential Revision: D2801343

fb-gh-sync-id: 563984d77b10c3925fda6fd5616b814cdbea2c66
2016-01-06 09:47:39 -08:00
Martín Bigio d875aac3c8 Resolve requires on HMR
Summary:
public

Requires are transformed when building the bundle but we forgot doing so when building the HMR one.

Reviewed By: vjeux

Differential Revision: D2801319

fb-gh-sync-id: ae70612945ab81a05154b14d6b756ef390770542
2016-01-06 09:47:31 -08:00
Martin Bigio 0d4cfa00f9 Increase worker-farm timeout
Reviewed By: davidaurelio

Differential Revision: D2806738

fb-gh-sync-id: a165578002415388af830f77bd96f4888143028f
2016-01-06 07:15:29 -08:00
Martín Bigio f421d2b056 Fix cache errors
Reviewed By: yungsters

Differential Revision: D2806495

fb-gh-sync-id: 4c1088cde8f0b88070f31b3a130b66f20a2a07cb
2016-01-05 22:04:39 -08:00
Martín Bigio 5a4ee0bfaa Pipe transforms errors through transformation pipelines
Summary:
public

Fixes an issue on the transforms pipeline which caused not to pipe errors that occured on the external transformer to JSTransformer.

Reviewed By: yungsters

Differential Revision: D2806498

fb-gh-sync-id: c9347d1957a3a9320b3f177ff9b19bf3802087a0
2016-01-05 21:57:31 -08:00
Christoph Pojer 0cb63bb971 Fix lint warnings in the resolver
Reviewed By: martinbigio

Differential Revision: D2803192

fb-gh-sync-id: 721821ed9ce8dd846f90ec09e7e1f36abf322b5a
2016-01-05 10:45:34 -08:00
Martín Bigio f2bdb79782 Make HMR server send full list modules that changed
Summary:
public

Before this diff we were only accepting the module that was modified but the user. This works fine as long as the user doesn't modify the dependencies a module has but once he starts doing so the HMR runtime may fail when updating modules' code because they might might a few dependencies. For instance, if the user changes the `src` a `Image` has to reference an image (using the new asset system) that wasn't on the original bundle the user will get a red box. This diff addresses this by diffing the modules the app currently has with the new ones it should have and including all of them on the HMR update. Note this diffing is only done when the we realize the module that was modified changed it's dependencies so there's no additional overhead on this change.

Reviewed By: vjeux

Differential Revision: D2796325

fb-gh-sync-id: cac95f2e995310634c221bbbb09d9f3e7bc03e8d
2016-01-04 13:02:27 -08:00
Martín Bigio 8c9c7e6286 Introduce transforms pipeline
Summary:
public

This diff introduces an internal transforms pipeline that integrates with the external one. This has been a feature we've been looking to implement for a long time to use babel instead of `replace` with regexps on many parts of the packager.

Also, to split the bundle we'll need to run one transform. Internally for Facebook we can run the system-import transform altogether withe the other ones. For OSS we offer `transformer.js` which people can use out of the box if they're writing ES6 code. For those people, `transformer.js` will also run the internal transforms`. However they might want to tune the transforms, or even write the code on another language that compiles to Javascript and use a complete different transformer. On those cases we'll need to run the external transforms first and pipe the output through the internal transforms. Note that the order it's important as the internal transforms assume the code is written in JS, though the original code could be on other scripting languages (CoffeeScript, TypeScript, etc).

Reviewed By: davidaurelio

Differential Revision: D2725109

fb-gh-sync-id: d764e209c78743419c4cb97068495c771372ab90
2016-01-04 11:32:42 -08:00
Janic Duplessis 2d50ac359c Fix issues running the website locally on windows with npm3 2016-01-02 03:56:32 -05:00
Ben Alpert 6a838a4201 Consume react, fbjs from npm
Summary:
We don't (yet) treat these the same as any other modules because we still have special resolution rules for them in the packager allowing the use of `providesModule`, but I believe this allows people to use npm react in their RN projects and not have duplicate copies of React. Fixes facebook/react-native#2985.

This relies on fbjs 0.6, which includes `.flow` files alongside the `.js` files to allow them to be typechecked without additional configuration. This also uses react 0.14.5, which shims a couple of files (as `.native.js`) to avoid DOM-specific bits. Once we fix these in React, we will use the same code on web and native. Hopefully we can also remove the packager support I'm adding here for `.native.js`.

This diff is not the desired end state for us – ideally the packager would know nothing of react or fbjs, and we'll get there eventually by not relying on `providesModule` in order to load react and fbjs modules. (fbjs change posted here but not merged yet: https://github.com/facebook/fbjs/pull/84.)

This should also allow relay to work seamlessly with RN, but I haven't verified this.

public

Reviewed By: sebmarkbage

Differential Revision: D2786197

fb-gh-sync-id: ff50f28445e949edc9501f4b599df7970813870d
2015-12-30 11:41:09 -08:00
Martín Bigio e798817e5a Yellow boxes for HMR errors
Reviewed By: vjeux

Differential Revision: D2795143

fb-gh-sync-id: fd5c92af511258bb1252d991e994a8c37657644e
2015-12-30 10:08:29 -08:00
wvengen 494d607e28 Improve watcher timeout error message (fixes #5005)
Summary: Closes https://github.com/facebook/react-native/pull/5022

Reviewed By: svcscm

Differential Revision: D2793185

Pulled By: milend

fb-gh-sync-id: ec49d27d6e405924269a48f32cce401b1ce380f6
2015-12-30 08:19:32 -08:00
Ben Alpert fe07a9c576 Update Object.assign non-object error message
Summary:
These are the sources, not the target. Copy pasta from above.
Closes https://github.com/facebook/react-native/pull/4989

Reviewed By: svcscm

Differential Revision: D2795198

Pulled By: spicyj

fb-gh-sync-id: 61c52add02cb877284fbf62a4344361b5bf44515
2015-12-29 23:09:29 -08:00
Martín Bigio e75e861116 Make Hot Loading faster
Summary:
public

Before this this when a file was changed besides sending the HMR update we rebuild every single bundle that the packager had build (to serve it faster when the user hit cmd+r). Since when hot loading is enabled we don't do cmd+r all this work was pointless (except for when you're developing multiple apps using the same packager instance at the same time, which we can assume is very uncommon). As a consequence, the HMR update was competing with the rebundling job making HMR quite slow (i.e.: on one huge internal app it took up to 6s for the HMR changes to get applied).

So, this diff tweaks the file change listener so that we don't rebundle nor invoke the fileWatchers (use for live reload which is also useless when hot load is enabled) when hot loading is enabled. Also, it makes the HMR listener more high pri than the other listeners so that the HMR dev experience is as good as it can get.

Reviewed By: vjeux

Differential Revision: D2793827

fb-gh-sync-id: 724930db9f44974c15ad3f562910b0885e44efde
2015-12-29 18:25:40 -08:00
Martín Bigio b5081abae3 Send HMR updates only for files on the bundle
Summary:
public

Compute the dependencies of the bundle entry file just before sending HMR updates. In case the file that was changed doesn't belong to the bundle bail.

Reviewed By: vjeux

Differential Revision: D2793736

fb-gh-sync-id: f858e71b0dd5fe4f5b2307a22c6cef627eb66a22
2015-12-29 18:25:35 -08:00
Martín Bigio d1864fa436 Improve error wording
Reviewed By: frantic

Differential Revision: D2793300

fb-gh-sync-id: f3f9403ee332d193b8a6c4a6dfb89d636dc48875
2015-12-29 11:36:32 -08:00
Martín Bigio e43e2146d9 Gate Hot Loading
Summary:
public

Until we support this fature on OSS, don't show the menu option.

Reviewed By: vjeux

Differential Revision: D2791198

fb-gh-sync-id: 11b66d467c1ab784bbf549b893d0a3abd69e2741
2015-12-28 16:45:07 -08:00
Martín Bigio 4ffb241647 Hot Loading E2E basic flow
Summary:
public

Implement all the necessary glue code for several diffs submitted before to get Hot Loading work end to end:

- Simplify `HMRClient`: we don't need to make it stateful allowing to enable and disable it because both when we enable and disable the interface we need to reload the bundle.
- On the native side we introduced a singleton to process the bundle URL. This new class might alter the url to include the `hot` attribute. I'm not 100% sure this is the best way to implement this but we cannot use `CTLSettings` for this as it's are not available on oss and I didn't want to contaminate `RCTBridge` with something specific to hot loading. Also, we could potentially use this processor for other things in the future. Please let me know if you don't like this approach or you have a better idea :).
- Use this processor to alter the default bundle URL and request a `hot` bundle when hot loading is enabled. Also make sure to enable the HMR interface when the client activates it on the dev menu.
- Add packager `hot` option.
- Include gaeron's `react-transform` on Facebook's JS transformer.

The current implementation couples a bit React Native to this feature because `react-transform-hmr` is required on `InitializeJavaScriptAppEngine`. Ideally, the packager should accept an additional list of requires and include them on the bundle among all their dependencies. Note this is not the same as the option `runBeforeMainModule` as that one only adds a require to the provided module but doesn't include all the dependencies that module amy have that the entry point doesn't. I'll address this in a follow up task to enable asap hot loading (9536142)

I had to remove 2 `.babelrc` files from `react-proxy` and `react-deep-force-update`. There's an internal task for fixing the underlaying issue to avoid doing this horrible hack (t9515889).

Reviewed By: vjeux

Differential Revision: D2790806

fb-gh-sync-id: d4b78a2acfa071d6b3accc2e6716ef5611ad4fda
2015-12-28 16:44:59 -08:00
Martín Bigio 245065be87 Introduce HMR runtime
Summary:
public

Add a very simple runtime for self-accepting modules. The API is the same one as Webpacks's one for now.
The new infra will be end-to-end tested on a follow up diff.

Reviewed By: vjeux

Differential Revision: D2789428

fb-gh-sync-id: c39524814d53c6e4ec9d9d011081ea81089b00b6
2015-12-28 16:44:45 -08:00
Martín Bigio ac9c3c548d Make Packager send fresh modules through HMR interface
Reviewed By: frantic

Differential Revision: D2787951

fb-gh-sync-id: 63c04710b60d99b5161ef9a40b116ba2f72df745
2015-12-28 16:44:38 -08:00