Commit Graph

651 Commits

Author SHA1 Message Date
Pieter De Baets f9da45197f 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 4608593dce 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 5f53658fb0 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
David Aurelio daa426c46a @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
David Aurelio 2a77da76ae 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
David Aurelio 17726e1ae6 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 cc538b9b35 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 789978a9ec 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 d4e704be17 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 d07a52d887 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 ca409964fc 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 05871df2a9 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 bdc9749ba0 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
David Aurelio faa9adf2ab 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 ae9f74e68d 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 f0e4826c46 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 b7b8861b75 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
Sam Swarr 43c5ed2be0 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 1d9df442a4 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 f9a9cd6f25 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 65b0f7c868 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 27e79ff0c3 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 6f9aad3641 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 30bdfdd370 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 97e1db3e6c 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 7cf1c7f51f 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 4ea783234b 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 cccbb342a0 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
Martín Bigio c0f446d7e2 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 18612273be 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 ebfb4f738a 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
David Aurelio f361f99f53 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 8a860a01c5 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
Sam Swarr 054642231b 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 482e2fea0e 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 44f7df4432 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
David Aurelio 0fe44bd1ab 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 ec24c63e86 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 c17a8e48cf 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 4a5cbbbec8 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 faaafd771e 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 3f072d22ea 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 3e1708bcc3 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 d13b75794f 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 a8a501b5cf 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 5309991ba6 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 bf0806b803 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 9de2ed3d48 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
David Aurelio aafa9d684d 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 60dacf3bc4 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 c107132a36 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 278b40ff69 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 b2a11aff51 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 a558c4b59d 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 ccbf9273fe 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
Christoph Pojer 715c5b9b81 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 5357bd7d99 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 012caf0e22 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 c50043dd15 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 d066468cb2 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 2dd2975fb9 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 fd7782849e 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 54e6576199 / [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 03a85ea8c2 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 f6af247123 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 96b82f43c7 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 e90d06dbed 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 38cea2edeb 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 6d8ccc318b 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 f2cb2355b2 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 042dc4349a 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
Christoph Pojer c620ddd71d 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 1a547cc2b1 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 f4fc79ab68 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 f0a42f7035 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
Christoph Pojer f51d9718da 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
Austin Kuo 6d58de1b7b 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
Martín Bigio 72ddf1ef67 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 5d2a457880 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 d503cf243c 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 fb09783e81 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 df48cd1163 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 e8472b44f4 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 82d4cbe7dd 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 9fb1762784 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 370b7b25a3 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 1de20b0135 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 1f2e16c0af 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 d70519d5c5 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 4d834b3cb9 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 2049eb99fd Expose `has` method on Cache.
Reviewed By: davidaurelio

Differential Revision: D2862315

fb-gh-sync-id: 03728a2593b477aef3bbfe01d42382893a05ea50
2016-01-26 10:51:28 -08:00
Mark Vayngrib 2963af0bef 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 c00871f086 Revert "Enable JSX files extension"
Summary:
This reverts commit 888749220dac26382412f2c38ac5f9205cc842e5.

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 42e508efb8 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 baa6d7fb24 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 741cb48fa2 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 153989bcd3 `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 782d0838be 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
tfallon@mail.depaul.edu 0dbc239685 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 d1ae909bbb 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 6ec2225fc9 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 18e5e50e11 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 da3838f6ca 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 6adf3a4f61 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 f1fa67feaf 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 d8888183ba 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 f13ceab315 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 95b69d548b Simplify HMR codepath
Reviewed By: davidaurelio

Differential Revision: D2839590

fb-gh-sync-id: 9bb14cafc69eec7d7a8712b60435e29f2ba48d3c
2016-01-20 07:14:33 -08:00
Martín Bigio 8a36625689 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 85df6cf2ca 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 a258d55716 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 fb94be4358 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 62a3d2c843 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 da27090d83 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 1b33b523f4 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 91fb94b5ce 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 e35b8f1724 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 0001c20760 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 a401b1d166 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 0cc1132b8c 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 4501181cc9 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 87e8086937 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 c75610febb 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 c2dcb04d29 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 28b3bbefaf 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 0680259ad4 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 a62f260680 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 db91ff81fd 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
Martín Bigio 9e5dfbddbc 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 e02756ca21 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 d30da1ec01 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 3ba3503cd8 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 18f1fb2046 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 b34845e4b0 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 3ee52f04ce 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 e94c9d042b 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
Ben Alpert e41008f208 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 eed6dde1d4 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 2ab3fe921b 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 ac0b2df846 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 d7a0233e2d 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 dcbc6708e3 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 d59f716a22 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 e2ba64630d 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 724fa73adf 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 5bbd33051a 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 afba6b48e7 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
Martín Bigio e6a807a8b7 Introduce Packager and App HMR WebSocket connection
Summary:
public

This diff adds infra to both the Packager and the running app to have a WebSocket based connection between them. This connection is toggled by a new dev menu item, namely `Enable/Disable Hot Loading`.

Reviewed By: vjeux

Differential Revision: D2787621

fb-gh-sync-id: d1dee769348e4830c28782e7b650d025f2b3a786
2015-12-28 16:44:32 -08:00
Tadeu Zagallo ecec0ea842 Move WPO to the minify step
Summary:
public

The Whole Program Optimisation (WPO) pass is quite slow, and can make it painful
to iterate when having `dev=false`. Move it to happen only when both `dev=false` and `minify=true`.

Reviewed By: davidaurelio

Differential Revision: D2773941

fb-gh-sync-id: ac5ca4e1286e233c2d175eecdbf7494d5d3497b2
2015-12-27 06:01:30 -08:00
Adam Miskiewicz 30e8f9fd22 Fix @providesModule not being ignored properly
Summary:
There's quite a bit of code scattered around the packager regarding ignoring the `providesModule` Haste pragma in any file that isn't in `react-native`, `react-tools` or `parse`. There is even a (passing) test case.

However, there's an edge case.

Take, for example, `fbjs`. It has a module inside of it called `ErrorUtils`. `react-relay` requires this file normally, in Common.JS style, by doing `require('fbjs/libs/ErrorUtils')`. But when `react-native` attempts to require `ErrorUtils` using the HasteModule format (in it's JavaScript initialization), it resolves the `fbjs` `ErrorUtils` module, instead of RN's `ErrorUtils`.

This happens, it turns out, because when a module is read (in `Module._read`), it's not caring about whether or not it should pay attention to `providesModule`, and is just assigning the `providesModule` value as the id of the module no matter what. Then when `Module.getName` is called, it will always use that `data.id` that was set, thus creating the wrong dependency tree.

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

Reviewed By: svcscm

Differential Revision: D2632317

Pulled By: vjeux

fb-gh-sync-id: efd8066eaf6f18fcf79698beab36cab90bf5cd6d
2015-12-24 08:32:31 -08:00
Bhuwan Khattar 19e7bf2322 getTransformOptionsModulePath
Summary:
Passing around a `getTransformOptions` function doesn't really work with the CLI utils, so I'm changing this to `getTransformOptionsModulePath` instead, which can easily be injected in through `rn-cli.config.js`.

public

Reviewed By: martinbigio

Differential Revision: D2785789

fb-gh-sync-id: c9fdc358cb5d0db27e0d02496e44c013c77f3d5f
2015-12-24 01:02:30 -08:00
Janic Duplessis 61c745b8e6 Use //# instead of //@ for sourceMappingURL comment
Summary:
I had an issue debugging in chrome 48 on windows where source maps didn't work. I tried changing the sourceMappingURL comment to use the //# syntax instead and it fixed the problem.

According to https://developers.google.com/web/updates/2013/06/sourceMappingURL-and-sourceURL-syntax-changed?hl=en the //@ syntax was deprecated for //#.
Closes https://github.com/facebook/react-native/pull/4892

Reviewed By: martinbigio

Differential Revision: D2781046

Pulled By: davidaurelio

fb-gh-sync-id: 3b85f6153692a2e23509029ecf18dc51d35ba921
2015-12-23 11:39:07 -08:00
Philipp von Weitershausen f2124b5544 Improvements to the packager for very large projects
Summary:
Here are some small fixes for issues we've encountered with very large RN projects (mostly huge dependency trees in `node_modules`).

cc amasad martinbigio
Closes https://github.com/facebook/react-native/pull/4880

Reviewed By: svcscm

Differential Revision: D2782834

Pulled By: mkonicek

fb-gh-sync-id: e316a62b84ba796b80ac819431414ebf27f7b566
2015-12-23 10:08:24 -08:00
Christoph Pojer 869c0543d0 Update all tests to use Jasmine 2
Reviewed By: vjeux

Differential Revision: D2782581

fb-gh-sync-id: 1d938a2bbdd8670c917c1793234dfdcb29fd4511
2015-12-23 10:08:01 -08:00
Bhuwan Khattar da44545090 getTransformOptions based on bundle and module
Summary:
Currently, the app server accepts `transformModulePath` which allows us to use different transformation variants. However, these options persist through the lifetime of the server. So we cannot conditionally transform a module differently for two bundles without restarting the server with different options.

`getTransformOptions` basically allows us to change the options to the transformer at runtime based on the bundle and module being transformed.

These options are also used as a cache key for the transformedSource to ensure that if a file is transformed with different options, caching doesn't cause any inconsistencies.

public

Reviewed By: martinbigio

Differential Revision: D2776399

fb-gh-sync-id: 1e0f34d8fa7f0377fcf81f23eb6f3236bd397d56
2015-12-21 12:15:31 -08:00
Christoph Pojer 90d1b6ee62 Move Cache into DependencyGraph
Reviewed By: martinbigio

Differential Revision: D2758776

fb-gh-sync-id: 15fb232e00267698e386d5422cb70e2091dabcdd
2015-12-18 16:17:42 -08:00
Tadeu Zagallo 3f81ea5844 Fix the sourceMap url on minified bundles
Summary:
public

The minified bundle was always being generated with the `bundle.js` as the source map url.

Reviewed By: martinbigio

Differential Revision: D2773725

fb-gh-sync-id: 02cda95eb172fc373ce4e605418cbfcec22f433d
2015-12-18 11:01:30 -08:00
David Aurelio 280cc2e807 Unbreak console reassignment on iOS7
Summary:
public
Unbreaks console assignment on iOS7 introduced in #3322

Reviewed By: alexeylang

Differential Revision: D2759689

fb-gh-sync-id: 28cccfdf1123245732fa5ba0337ee8d7bb43c822
2015-12-15 07:46:31 -08:00
James Ide 174c573c86 Keep the original console as `global.originalConsole`
Summary:
If a console exists, keep the original as `global.originalConsole` before overwriting `global.console` with a polyfill. This matches what we do for XHR, fetch, and some other libraries.
Closes https://github.com/facebook/react-native/pull/3322

Reviewed By: svcscm

Differential Revision: D2755873

Pulled By: androidtrunkagent

fb-gh-sync-id: 4c23f807b73b79cfa9fbbd4e2814d76eecabd596
2015-12-14 12:30:31 -08:00
Christoph Pojer ae4ea67fa6 Move FileWatcher into node-haste
Reviewed By: davidaurelio

Differential Revision: D2752711

fb-gh-sync-id: e656a3019b95c7677d5b27e74dc921ef62ba5c83
2015-12-14 11:29:31 -08:00
WanderWang 26102c3934 improve exception message when we can't find a file
Summary:
in ```fastfs.js ``` when ```getFile()``` got a exception it will print ``` Unable to find file with path: null ``` in terminal .

It's  confused
Closes https://github.com/facebook/react-native/pull/4737

Reviewed By: svcscm

Differential Revision: D2752888

Pulled By: androidtrunkagent

fb-gh-sync-id: a366da1eea27c691248dcb17019f4462a639ea70
2015-12-12 17:28:33 -08:00
Tadeu Zagallo 2927b76993 Rename BridgeProfiling to Systrace for consistency
Summary:
public

Rename the `BridgeProfiling` JS module to `Systrace`, since it's actually just
an API to Systrace markers.

This should make it clearer as we add more perf tooling.

Reviewed By: jspahrsummers

Differential Revision: D2734001

fb-gh-sync-id: 642848fa7340c545067f2a7cf5cef8af1c8a69a2
2015-12-11 03:53:19 -08:00
Christoph Pojer ff3cac5436 Update node-haste from upstream
Reviewed By: zpao

Differential Revision: D2747183

fb-gh-sync-id: f1b963b19cb6ea16945b16370d1bee26110bb329
2015-12-10 18:13:28 -08:00
David Anderson 8bc99d9a53 Fix asset httpServerLocation on Windows.
Summary:
Functions from the path module return paths with the native file system path separator. generateAssetModule is using path.join and path.dirname to generate httpServerLocation.  That means that on Windows systems, the generated URL path has backslashes rather than forward slashes which breaks the app's ability to retrieve image assets using require('./image.png').  This change fixes this by checking path.sep and replacing backslashes with slashes on systems that require it.
Closes https://github.com/facebook/react-native/pull/4416

Reviewed By: svcscm

Differential Revision: D2740529

Pulled By: mkonicek

fb-gh-sync-id: edae0f6762c7dc1db7af078209e38a2feab1e0a1
2015-12-09 14:08:28 -08:00
Thomas Parslow 8766f727b3 Add taggedTemplateLiteral to babelHelpers
Summary:
Needed to support tagged template literals (which are already enabled in babel). Not having this helper means we get a runtime crash.
Closes https://github.com/facebook/react-native/pull/4680

Reviewed By: svcscm

Differential Revision: D2740233

Pulled By: spicyj

fb-gh-sync-id: 12729f670b7942ad7a04bd50ae1eca35d2b1e410
2015-12-09 13:01:24 -08:00
Martín Bigio 1e8e4dc223 Introduce `loadBundles`
Summary:
public

Introduce a new Polyfill module to load bundles. This polyfill contains the function to which System.import gets transformed into. It works similarly to require in the way it's registered. It keeps track of the bundles that have ever been requested using promises, either fulfilled or not. The use of promises makes the implementation quite easy as we don't need to differenciate whether the request has been started or not.

There're a couple of follow up steps that still need to get done:

- Included this polyfill on the ones we automatically include on the bundle.
- Modify the transform to include the modules the user is actually requesting and pipe that through loadBundles so that the promise, once resolved, has the ordered list of modules the user requested.
- Implement the actual native code that loads a bundle. This shouldn't be that taught  as native will be able to assume it will never receive the same request twice.

Reviewed By: davidaurelio

Differential Revision: D2727241

fb-gh-sync-id: 317d80754783caf43f10c71a34a4558a4d298d45
2015-12-08 12:31:36 -08:00
Mike Armstrong 5ea0b333e7 Append JS_require_ to require profile names
Reviewed By: tadeuzagallo

Differential Revision: D2717939

fb-gh-sync-id: 4648e240eebfb3a7bc1c5041d4f1fba8761264a9
2015-12-03 08:20:25 -08:00
Tim Yung c68fa4b4d8 RN: Support Multiple Packager Servers
Summary:
Adds support for multiple packager servers, which could be used to hot-reload dependencies in response to a change in the `cacheVersion`.

Currently, there is no way to:

- Create multiple `ReactPackager` servers.
- Instantiate more than one `FileWatcher` constructor (due to the "single instance" invariant).

public

Reviewed By: martinbigio

Differential Revision: D2713455

fb-gh-sync-id: 9be0f0cb2b846baf088d0cf14650cc8b9e950815
2015-12-02 19:03:27 -08:00
David Aurelio d6dc12e551 Add for-of transform to babel configurations
Summary:
Adds babel-plugin-transform-es2015-for-of to babel configuration.

public

Reviewed By: tadeuzagallo

Differential Revision: D2712220

fb-gh-sync-id: cc6dd9e6e70946607ef9bb9f659eb628cf2eb555
2015-12-02 04:14:30 -08:00
David Aurelio b428bebf56 Add unbundling to packager
Reviewed By: tadeuzagallo

Differential Revision: D2707409

fb-gh-sync-id: 30216c36066dae68d83622dba2d598e9dc0a29db
2015-12-01 08:48:30 -08:00
Bram df687d8442 bugfix #3997: react-native bundle not working on windows 10
Summary: fixes https://github.com/facebook/react-native/issues/3997

the root cause is in

Mon, 09 Nov 2015 13:22:47 GMT ReactNativePackager:SocketServer uncaught error Error: listen EACCES C:\Users\donald\AppData\Local\Temp\react-packager-9248a9803ac72b509b389b456696850d

This means that the socket server cannot create the socket.

cfr https://gist.github.com/domenic/2790533 the socket name is not a valid windows socket name.
Closes https://github.com/facebook/react-native/pull/4071

Reviewed By: mkonicek

Differential Revision: D2699546

Pulled By: davidaurelio

fb-gh-sync-id: 6c6494c14c42bb17506b8559001419c9f85e91e3
2015-11-27 08:22:29 -08:00
David Aurelio efdc037859 Don’t do manual connection counting
Reviewed By: tadeuzagallo

Differential Revision: D2696017

fb-gh-sync-id: 039abf9b7ed1570590e96e7077bb48a5493e8471
2015-11-26 11:04:28 -08:00
David Aurelio 882707ed13 Don’t error for known files that are reported as “added” by watchman
Reviewed By: tadeuzagallo

Differential Revision: D2696636

fb-gh-sync-id: 89f90aba2a22d9c3e93632df4c4bc01791525833
2015-11-26 07:06:24 -08:00
Sebastian Markbage df5d178115 Extract the Require polyfill from the default list of polyfills
Summary: Extracts the module system from the list of dependencies and adds it back to the bundling process.

Unbundling and Prepack has their own module systems. jest does as well. This is not normally part of the resolver, nor polyfills.

In fact, I think we'll eventually start treating polyfills as normal modules just like core-js.

The prelude is the weird part right now but I think that we'll eventually move the DEV flag to be module level instead of global and we can just get rid of this prelude.

public

Reviewed By: davidaurelio

Differential Revision: D2693701

fb-gh-sync-id: a59ccda0fa15fcfcda52897e8290805eed1b92b3
2015-11-25 18:46:28 -08:00
Mark Vayngrib e88322d3a8 support react-native field with fallback to browser field
Summary: React Native is a lot more powerful an environment than the browser, so we need an alternate mapping, as specified [here](https://github.com/defunctzombie/node-browser-resolve#browser-field)

An example:
```js
{
  "browser": {
     "./lib/server": false
   },
   "react-native": {
     "dgram": "react-native-udp",
     "fs": "react-native-level-fs"
   },
   "chromeapp": {
     "dgram": "chrome-dgram",
     "fs": "level-filesystem"
   }
}
```

on the other hand, if "react-native" is not present in package.json, you should fall back to "browser"

other than the one (nesting) test added, the tests are unchanged, just done for both "react-native" and "browser"

(I've implemented [react-native-udp](https://npmjs.org/package/react-native-udp) and [react-native-level-fs](https://npmjs.org/package/react-native-level-fs), but they obviously don't belong in the traditional "browser" field as they won't run anywhere except in React Native.)
Closes https://github.com/facebook/react-native/pull/2208

Reviewed By: svcscm

Differential Revision: D2691236

Pulled By: vjeux

fb-gh-sync-id: 34041ed50bda4ec07f31d1dc50dcdfa428af2512
2015-11-24 11:10:41 -08:00
David Aurelio 8638b666fa Add babel helpers necessary for es2015 imports
Summary: public

Adding the babel helpers that are necessary to support ES2015 imports.

Fixes: https://gist.github.com/ehd/49cb2465df9da6b39710

Reviewed By: mkonicek

Differential Revision: D2690772

fb-gh-sync-id: b1b6c0c048bad809a5c58cdd0a2cbeaa11c72ea7
2015-11-24 09:17:29 -08:00
Tadeu Zagallo 97f0432de5 Add systrace markers to module require
Summary: public

Show modules' dependencies and time to load.

Reviewed By: davidaurelio

Differential Revision: D2603245

fb-gh-sync-id: a1d5067a8522b908b87fdfdd51ff4c4fdbc2edfc
2015-11-21 11:11:26 -08:00
Sebastian Markbage f02d6c1848 Add infra for Prepack build option
Summary: This adds a build option for using Prepack (an experimental packager) to
build a bundle. It doesn't actually take on the npm package dependency
because it's not published/open source (yet).

This will be used while we experiment and should be maintained as the
build system changes so that we can continue getting fresh builds.

I found that saveBundleAndMap and processBundle were over abstracted and
got in my way so I inlined it and removed the unit tests because the unit
test was testing trivial code that is likely to change interface.

I went with a separate build phase and a separate Bundle class even though
there are a lot of commonalities. I imagine that the requirements for
Prepack will continue to diverge. Especially for source maps but a larger
refactor could try to unify these a bit more. The fact that modules are
wrapped before the write phase seems to be an unfortunate architecture
that makes this difficult.
Closes https://github.com/facebook/react-native/pull/4226

Reviewed By: amasad

Differential Revision: D2673760

Pulled By: sebmarkbage

fb-gh-sync-id: 299ccc42e4be1d9dee19ade443ea3388db2e39a8
2015-11-20 20:19:25 -08:00
Pieter De Baets b289600a7a Port CatalystLoggingTestCase to iOS
Reviewed By: nicklockwood

Differential Revision: D2658485

fb-gh-sync-id: e6803aefee69ee058651fc4c8c202619543f0cd2
2015-11-20 04:41:24 -08:00
Tadeu Zagallo 4ddb158c72 Add ternary elimination support to the WPO pass
Summary: public

Replaces

```
__DEV__ ? foo() : bar()
```

with

```
bar()
```

for non-dev builds.

Reviewed By: davidaurelio

Differential Revision: D2663838

fb-gh-sync-id: 30fdfa72dda89fc0d340da359e0f43db2917fcf5
2015-11-17 11:14:15 -08:00
Tadeu Zagallo 844282c37b Add a naive WPO implementation
Summary: public

RFC: The minifier haven't been stripping dead-code, and it also can't kill unused
modules, so as a temporary solution this inlines `__DEV__`, kill dead branches
and kill dead modules. For now I'm just white-listing the dev variable, but we
could definitely do better than that, but as a temporary fix this should be
helpful.

I also intend to kill some dead variables, so we can kill unused requires,
although inline-requires can also fix it.

Reviewed By: vjeux

Differential Revision: D2605454

fb-gh-sync-id: 50acb9dcbded07a43080b93ac826a5ceda695936
2015-11-17 03:39:28 -08:00
Christoph Pojer a8ded758d0 Sync new haste features from upstream
Reviewed By: amasad

Differential Revision: D2644383

fb-gh-sync-id: 5225e6afb8e5b835865473b2880a77235e6bd6eb
2015-11-16 22:50:30 -08:00
Tadeu Zagallo ccea74fc87 Fix babelHelpers.extend
Summary: public

The recent change to move babelhelpers out of the module broke the extends method.

Reviewed By: spicyj

Differential Revision: D2656448

fb-gh-sync-id: 633433deea00ecb140afbb732bff0599e67b4d41
2015-11-14 13:51:25 -08:00
David Aurelio b7df3ca666 Unbreak jest tests (and travis e2e tests)
Reviewed By: mkonicek

Differential Revision: D2652002

fb-gh-sync-id: 8aab8da47dd737acc4ee9acddc484bd3bbdf1184
2015-11-14 03:26:24 -08:00
Giampaolo Bellavite 48ffe711f8 Fix typo in console.error
Summary: Closes https://github.com/facebook/react-native/pull/4116

Reviewed By: svcscm

Differential Revision: D2652595

Pulled By: cpojer

fb-gh-sync-id: a46a19dcbb119b4e14df2e4418787ea232c32606
2015-11-13 11:02:42 -08:00
Ben Alpert 17706d6ce4 Use external babel helpers
Reviewed By: vjeux

Differential Revision: D2643810

fb-gh-sync-id: a415e2449a98b6070c688c1c250eb8a908b40409
2015-11-12 07:04:55 -08:00
Tadeu Zagallo a7338495f8 Fix breakages when upgrading to babel 6
Reviewed By: vjeux

Differential Revision: D2628092

fb-gh-sync-id: 077a3572fe8b261d390be2bdc32d9d06c2b80a01
2015-11-10 10:56:48 -08:00
Tadeu Zagallo 7ea13f835c Use the previously upgraded transforms
Summary: public

Move all the transforms that had been previously upgraded to be the default now.

Reviewed By: vjeux

Differential Revision: D2631308

fb-gh-sync-id: a2120a9850c98ce65784b77598baa123121246ab
2015-11-10 10:55:32 -08:00
Tadeu Zagallo a88f69e482 Upgrade transformers to be compatible babel 6
Reviewed By: vjeux

Differential Revision: D2626155

fb-gh-sync-id: e919c8fb8bbf139bcd979ee2738c7ec4fc9eba74
2015-11-10 10:55:23 -08:00
Christoph Pojer 7e89bb9920 Use `debug` instead of `console.warn`
Reviewed By: voideanvalue

Differential Revision: D2636111

fb-gh-sync-id: d21ec56045461353317348c4da14c92be8015bd3
2015-11-10 02:30:34 -08:00
Christoph Pojer a724cfde2d Defualts for platforms and assetExts
Reviewed By: voideanvalue

Differential Revision: D2635446

fb-gh-sync-id: 57e628cf5f917c7e2511d0c8bde696310ab0fc7a
2015-11-09 19:48:29 -08:00
Christoph Pojer 391e4c8236 Inline cache mock for DependencyGraph-test
Reviewed By: davidaurelio

Differential Revision: D2629211

fb-gh-sync-id: ade0bf4e486b58ecbc9a29eb3bdb61286eebb3d5
2015-11-09 13:34:55 -08:00
Christoph Pojer de981ecccd Use a mock for FileWatcher
Reviewed By: davidaurelio

Differential Revision: D2628885

fb-gh-sync-id: f8b96c483eb7deb52a7ca4897801e2d0ef9e4f4c
2015-11-09 13:34:50 -08:00
Christoph Pojer 8ff93e65d2 Fix lint errors
Reviewed By: davidaurelio

Differential Revision: D2628366

fb-gh-sync-id: 8d849e2deb038842475e66ef641fa1d4f7b78d8f
2015-11-09 13:34:45 -08:00
Christoph Pojer 120bdae3f6 Remove usage of declareOpts
Reviewed By: martinbigio

Differential Revision: D2619798

fb-gh-sync-id: ddc58233c06899017dbb98b3d8258eb0fe61cda3
2015-11-09 13:34:38 -08:00
Christoph Pojer 57fed218a8 Move `getPlatformExtension` and `getAssetDataFromName` into `DependencyResolver`
Reviewed By: martinbigio

Differential Revision: D2619690

fb-gh-sync-id: 04ca68a1fa2dc7b77a49c38ea1515d7afbdee603
2015-11-09 13:34:32 -08:00
Christoph Pojer 0d1a442cff Don't require Activity inside of DependencyResolver
Reviewed By: martinbigio

Differential Revision: D2619364

fb-gh-sync-id: 7947388c8041e5d6cbc1e20c8eb9fc7325dc46e0
2015-11-09 13:33:29 -08:00
Ben Alpert 1d1006449e Update core libraries for React 0.14 final
Summary: All minor changes since we were already on the beta: most notable is that destructors are required in pooling to help prevent memory leaks.

public

Reviewed By: sebmarkbage

Differential Revision: D2608692

fb-gh-sync-id: acdad38768f7f48c0f0e7e44cbff6f0db316f4ca
2015-11-06 19:52:34 -08:00
Joe Savona ef0b3e9338 Add polyfills to jest setup scripts
Reviewed By: cpojer

Differential Revision: D2627866

fb-gh-sync-id: 6d2c95ebc1fe05da3a90f8f6df3287bdbac870bd
2015-11-06 17:20:35 -08:00
Joe Savona 9373eb73ac Polyfill Array.from
Reviewed By: cpojer

Differential Revision: D2627437

fb-gh-sync-id: 6a7c94e13db772d96cbd8ebab37eccb0826963bc
2015-11-06 14:14:28 -08:00
Pieter De Baets 48a2a5ccc7 Remove log level 'log' from JS
Summary: Log level 'log' from JS should be equivalent to 'info'. Also added knowledge of 'trace' log level in RCTLog.

public

Reviewed By: vjeux

Differential Revision: D2615500

fb-gh-sync-id: 7a02f49bf7953c1a075741c21e984470c44b5551
2015-11-05 12:51:41 -08:00
Frédéric Sagnes 8ecac28100 Set ASCII as the default bundle encoding
Reviewed By: davidaurelio

Differential Revision: D2596387

fb-gh-sync-id: deadb8e9a44bbe7b12ce9e6bb5e3c96d4f646074
2015-11-05 07:31:55 -08:00
Christoph Pojer bc9a3eb159 Remove dependency on underscore
Reviewed By: davidaurelio

Differential Revision: D2614853

fb-gh-sync-id: 706fb0db6852f599a1b3dd022dbc22aabb76539a
2015-11-04 19:02:47 -08:00
Christoph Pojer c731001864 Start pulling DependencyResolver apart
Summary: I'm planning to split up `DependencyResolver` into the react-native specific implementation of it and a new, generic resolver that is going to replace `node-haste` for jest and other places where we might need JS dependency resolution.

The plan is to split the two folders up so that:

* `Resolver` is the folder for all the react-native specific resolver code
* `DependencyResolver` will become a standalone library, eventually moving into a package called `node-haste`.

There is still a lot to be figured out. This is just the first diff of likely many. The current goal is to make `DependencyResolver` standalone to be able to create an instance of a resolver and resolve all dependencies for a file. This is when I can start integrating it more seriously with jest.

This diff simply moves a bunch of things around and turns `HasteModuleResolver` into an ES2015 class ( :) ).

bypass-lint
public

Reviewed By: davidaurelio

Differential Revision: D2614151

fb-gh-sync-id: ff4e434c4747d2fb032d34dc19fb85e0b0c553ac
2015-11-04 16:59:30 -08:00
Christoph Pojer 29befc8d1c Update jest to 0.7.1
Reviewed By: frantic

Differential Revision: D2614935

fb-gh-sync-id: 64cc4fb439f0c53f0eb0588c22e0291813a7e334
2015-11-04 14:42:13 -08:00
Tadeu Zagallo e93b1f8411 Convert System.import transform to babel 6
Reviewed By: martinbigio

Differential Revision: D2615286

fb-gh-sync-id: 4f0e8e3359413d972ab4d0da291870768a77e361
2015-11-04 08:53:26 -08:00
Tadeu Zagallo a0dd08e26c Log minification time
Summary: public

Add an activity to log minification time.

Reviewed By: vjeux

Differential Revision: D2604863

fb-gh-sync-id: cbdf0297f0611c87b589b87928af235f9ba81172
2015-11-03 01:20:26 -08:00
Bhuwan Khattar 02c3c465f8 require InitializeJavaScriptAppEngine in bundle
Reviewed By: martinbigio

Differential Revision: D2582794

fb-gh-sync-id: d6cfdda81f556ef0cefb2e9dc58f5978b651bd5b
2015-10-28 21:09:24 -07:00
Martín Bigio c5c4dc94b1 Infer platform from extension
Summary: public
Aparently this used to work on 0.11, lets fix it :)

Reviewed By: foghina

Differential Revision: D2557719

fb-gh-sync-id: dcbca077431c1356c89dfc55b71eecff64c7ad3d
2015-10-27 17:47:28 -07:00
Martín Bigio abeaa5bc9b Improve error logging when rebuild fails
Summary: public

We're seeing intermittent errors on the packager when rebasing. Since this is very hard to repro lets add more logging to the warning we show just before starting to rebuild the entire haste map again

Reviewed By: frantic

Differential Revision: D2585427

fb-gh-sync-id: fbfa953f6c8ae78cbee2f3ab19ad494b084165c8
2015-10-27 10:33:29 -07:00
Christoph Pojer bb7fd5ffa3 Update to 0.6.1
Summary: This version should be more stable and has the `moduleNameMapper` feature that frantic was asking for - I will send a follow-up diff for that. I also fixed an issue with `module.parent` and a module inside of yeoman that thought it was owning the universe.

See https://github.com/facebook/jest/blob/master/CHANGELOG.md#061 for a changelog since 0.5.6.

public

allow-crlf-text

Reviewed By: javache

Differential Revision: D2579041

fb-gh-sync-id: cb918875557f219239f49fc0ad49ac61d0884173
2015-10-26 15:37:23 -07:00
David Aurelio 8c4c679f09 Add `--verbose` flag to react native packager cli
Reviewed By: martinbigio

Differential Revision: D2517347

fb-gh-sync-id: 02e64f99120b6636d6e7649deb11d0b2f58d9285
2015-10-20 11:52:25 -07:00
David Aurelio 8b7342325a Make the modification time of the transformer file relevant for the cache.
Reviewed By: amasad

Differential Revision: D2554956

fb-gh-sync-id: cc76f083594aac04c74a4ef271305238b06710eb
2015-10-20 09:46:23 -07:00
Bhuwan Khattar 897c651fbe fix HasteDependencyResolver
Reviewed By: javache

Differential Revision: D2550444

fb-gh-sync-id: f978efdd73c09e58bcdbc4711ee2a7662a0b1bf3
2015-10-16 11:16:25 -07:00
Adam Miskiewicz d5436af6d8 Adds support for ES6 export syntax to the packager's DependencyResolver.
Summary: This PR includes:
- A regex that allows for the `export` syntax.
- Updated tests.
Closes https://github.com/facebook/react-native/pull/3465

Reviewed By: svcscm

Differential Revision: D2550322

Pulled By: vjeux

fb-gh-sync-id: 7d35f436af13cf5b6b1287835a18a9693ec1be8a
2015-10-16 10:57:32 -07:00
Bhuwan Khattar f58dabc989 Support cyclic dependencies in require polyfill
Reviewed By: @martinbigio

Differential Revision: D2548506

fb-gh-sync-id: fca534179a5f8fcf407917137cdd71d964f145e5
2015-10-16 03:41:08 -07:00
Bhuwan Khattar 87d2c1d95c Simplify require polyfill
Reviewed By: @vjeux

Differential Revision: D2544415

fb-gh-sync-id: ab48b5fba169c43c68dd24dc95ea1d0322ed67c4
2015-10-16 03:40:58 -07:00
Martín Bigio 0a6c851613 Fail loud when module is not resolved correctly
Summary: @​public
We've been forgiving unresolved modules errors in the past but we've realized that doing so makes the codebase a bit unstable as people don't make sure to fix these errors. From now on we'll early fail and stop the packager when any module cannot be resolved (including assets)

Reviewed By: @amasad

Differential Revision: D2518076

fb-gh-sync-id: e170d95b905cc29afbe46e24b65425ddd887f77c
2015-10-13 11:48:23 -07:00
Nick Lockwood 44429dc4f4 Removed references to isStatic from the codebase
Summary: @​public

The legacy 'isStatic' property for image sources is no longer used anywhere in our codebase, but was still being generated by the packager and referenced in the JS in various places.

This diff removes all the remaining references.

Reviewed By: @frantic

Differential Revision: D2531263

fb-gh-sync-id: 0bba0bb8473b1baa908ef7507cbf6d83efb0d9ee
2015-10-13 06:44:30 -07:00
Martín Bigio fc7d01e2ab fix E2E tests
Reviewed By: @mkonicek

Differential Revision: D2526310

fb-gh-sync-id: 1c04f56073dc5b393a36b258c039fdfd85ab83a2
2015-10-09 07:59:02 -07:00
Martín Bigio cc4ab48057 Unbreak packager on oss master
Summary: @​public
This was a hard one, bare with me on the full story of what happened.

We recently started writting additional JS scripts in ES6 for the cli. These code needs to be transformed by babel before we execute it as we don't run node with `--harmony`. To do so we removed the `only` attribute on the `babel-register`. Turns out this broke the packager on oss as if no `only` not `ignore` parameter is specified babel will ignore `node_modules`. Since on oss when a project is created `react-native-github` is located inside of `node_modules` we started getting syntax errors.

The fix is to include separately all the different paths we need to make sure babel transforms each of them. We cannot simply have a single `babel-core/register` as we need to include paths that belong both to oss and internal only. So, we need to have multiple `register` invocations. Since babel does not accumulate the `only` you send on every invocation we need to build a small wrapper to do so.

Reviewed By: @frantic

Differential Revision: D2522426

fb-gh-sync-id: 379a7bb169c7d5cb3002268742de269238bba766
2015-10-08 17:37:27 -07:00
Tadeu Zagallo 2950dd98b2 Fix wrong source map test
Reviewed By: @javache
2015-10-05 11:15:20 -07:00
Martín Bigio 1b8a5fc5fe Move fbobjc bundle command to cli
Reviewed By: @frantic

Differential Revision: D2457072
2015-10-05 09:21:27 -07:00
Tadeu Zagallo a37d8735d7 Fix minified source maps
Summary: @​public

The source maps generated by uglify are already stringified, and therefore were
being stringified twice.

Reviewed By: @martinbigio

Differential Revision: D2498242
2015-10-05 08:48:25 -07:00
Amjad Masad 24b1feae13 Use different cache keys for Package objects (fixes #2949)
Summary: @​public

Dead-lock trying to read package.json because it's both a "module" and a "package". in `Module.getName` it uses the cache key "name" and tries to call `Package.getName` which uses the same cache key and we end up returning the same promise that we're trying to resolve resulting in a dead-lock.

This changes the cache keys for the packages that adds a prefix "package-".

Reviewed By: @vjeux

Differential Revision: D2506979
2015-10-04 12:37:25 -07:00
shlomiatar e5f2e03af2 Fix DependencyResolver to support ES6 multiline imports
Summary: *This is a PR to fix #1939 (DependencyResolver fails to handle ES6 modules import statements with new lines)*

**This PR includes:**
- A fix to the problematic regular expression
- Updated tests that support the new line style.

**Summary:**
We found out that while the packager does its module wrapping thing for lines like this:
```js
import theDefault, { named1, named2 } from 'src/mylib';
```
It fails to do the same for multi line imports:
```js
import theDefault, {
  named1,
  named2
} from 'src/mylib';
```
We've tracked done the issue to a [faulty regular expression in replacePatterns.js](https://github.com/facebook/react-native/blob/master/packager/react-packager/src/DependencyResolver/replacePatterns.js#L12)

You can see various import statements with the problematic regular expression [here](http://regexr.com/3bc8m)

We've figure out a better regular expression (you can play around with it [here](http://regexr.com/3bd3s))Closes https://github.com/facebook/react-native/pull/1940

Reviewed By: @​svcscm

Differential Revision: D2498519

Pulled By: @vjeux
2015-10-01 12:17:21 -07:00
Kyle Corbitt b0145a8803 enable es6 module syntax
Summary: This is an updated copy of #1993, which was approved by @vjeux but hasn't been rebased. It whitelists the es6 module syntax and updates the JS Environment docs to match. cc @ide @​hkjorgensenCloses https://github.com/facebook/react-native/pull/3175

Reviewed By: @​svcscm

Differential Revision: D2498360

Pulled By: @vjeux
2015-10-01 10:57:23 -07:00
Amjad Masad 289989dc3f Error on name collisions
Summary: @​public
This moves us from warnings on name collisions to errors. If the error happens in initialization it will fatal out.

However, if the error happens while working (after initialization) then I did my best to make it recoverable. The rational behind this is that if you're working and you're changing names, you may introduce a duplication while moving things around. It will suck if you have to restart the server every time you do that.

Reviewed By: @frantic

Differential Revision: D2493098
2015-09-30 21:02:50 -07:00
Amjad Masad 4072c564ca Introduce `getOrderedDependencyPaths` that gets all concrete dependecy paths
Summary: @​public
Since we added packager-managed assets -- internally we still think of asset dependency as a single "module". In reality there are multiple files that represent this module. This becomes important with the `getDependencies` API which is used by Buck to inform it on what to rebuild. Since `getDependencies` deals with modules, and is more of an internal API, I've introduced a new one and would go on to deprecate this.

Reviewed By: @frantic

Differential Revision: D2487207
2015-09-29 18:34:21 -07:00
Amjad Masad d9c7205e17 Fix debug namespaces
Summary: @​public
Have a top-level debug namespace: `ReactNativePackager`
And add a couple of debugs in the transformer. This is ground work for adding a verbose option.

Reviewed By: @DmitrySoshnikov

Differential Revision: D2489960
2015-09-29 16:10:22 -07:00
Amjad Masad 40cecf94b3 remove randomness
Reviewed By: @javache

Differential Revision: D2490001
2015-09-29 12:44:22 -07:00
Amjad Masad 2cf80d481b Pass in the platform options when loading dependencies
Reviewed By: @jingc

Differential Revision: D2488262
2015-09-29 09:22:00 -07:00
Pieter De Baets c74f1e9bc9 Don't call originalConsole methods when they don't exist
Reviewed By: @vjeux

Differential Revision: D2485562
2015-09-29 09:21:48 -07:00
yiminghe d4f9750e38 support es6.constants by default. Fixes #2932
Summary: In javascriptcore(ios9), this code will run as expected(output 0 1):

```js
for(let i=0; i<2; i++) {
  const data = i;
  console.log(data);
}
```

But when debug in chrome, the above code will fail without `use strict` prologue (if you add prologue, rn will fail with red screen `Const declarations are not supported in strict mode`): https://code.google.com/p/v8/issues/detail?id=4432.

So it's better to transpile contant by default.

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

Reviewed By: @​svcscm

Differential Revision: D2483398

Pulled By: @vjeux
2015-09-26 15:50:24 -07:00
Amjad Masad 2a1d958251 Fix haste resolution (and better warnings)
Summary: @​public

Fix the haste resolution algorithm. Changed the map data structure from a list of modules, to a list of modules grouped by platform.
This considerably simplifies the "getModule" method and makes it easy to properly warn about colliding module names.
This also fixes a bug where we used to include `.web` files when we shouldn't (see task).

Reviewed By: @vjeux

Differential Revision: D2482969
2015-09-25 20:35:45 -07:00
Justin Spahr-Summers d071cfa7d1 Revert packager randomization revert 2015-09-25 10:24:06 -07:00
Justin Spahr-Summers 7827a02e32 Revert packager module randomization 2015-09-25 07:41:25 -07:00
Amjad Masad 5bb1226b64 Warn and randomize colliding name selection
Summary: @​public

The issue of colliding haste modules have came up many times and have wasted countless engineering hours. This will start warning about it and will also start selecting modules at random so that people don't depend on undefined behavior.

Additionally, this surfaced an issue where with assets we may fatally throw if the directory doesn't exist. This is fixed by checking the existence of the directory before trying to match files in it.

Reviewed By: @jingc

Differential Revision: D2478480
2015-09-25 00:19:27 -07:00
Martin Bigio d475e14cc2 Print to console instead of debug uncaught exceptions
Reviewed By: @jingc

Differential Revision: D2478099
2015-09-24 15:57:26 -07:00
Martin Bigio 3f61a4f846 Log server state when client is unexpetedly closed
Reviewed By: @javache

Differential Revision: D2473036
2015-09-24 08:20:20 -07:00
Jan Kassens ae3bf52f02 Fix for displayName transform
Summary: The `react.displayName` transform was added in 93b9329b758cde3e921b26e11ba91d9700d2a06d.

That diff missed to update the `.babelrc` where the comment says it should stay
in sync (I'm not sure where it's used though). I added a comment in the other
direction so this can be prevented in the future.

I also updated the `cacheVersion` so we actually transform the code again to add
the missing displayName properties to unchanged components.
Closes https://github.com/facebook/react-native/pull/2905

Reviewed By: @vjeux

Differential Revision: D2473447

Pulled By: @kassens
2015-09-24 08:20:02 -07:00
Charlie Cheever c7ec04b253 Also call the original `console` methods if they exist
Summary: Ex. When `console.log` or similar is called, this will call
the original method, which can be quite useful.

For example, under iOS, this will log to the Safari console debugger,
which has an expandable UI for inspecting objects, etc., and is also
just useful if you are using that as a REPL.

I don't believe this incurs a meaningful performance penalty unless
the console is open, but it would be easy to stick behind a flag
if that is a problem.
Closes https://github.com/facebook/react-native/pull/2486

Reviewed By: @​svcscm

Differential Revision: D2472470

Pulled By: @vjeux
2015-09-23 19:29:24 -07:00
Martin Bigio 16a9a5beda Don't swallow client errors
Reviewed By: @​swarr

Differential Revision: D2472285
2015-09-23 12:43:23 -07:00
Amjad Masad 0e8f6e4ed3 Remove server error listener so that it throws
Summary: @​public
We swallow errors like it's nobody's business :(
Having an error handler that `reject`s after the promise has been resolved is a no-op. In node, if there is no `error` event handler then the error would throw.

So after we start listening and we want to resolve the promise, we remove the error listener so that we make sure errors actually throw.

Finally, I made the `uncaughtError` handler log `error.stack` so we can get an idea of what's going on.

Reviewed By: @martinbigio

Differential Revision: D2468472
2015-09-22 15:48:29 -07:00
Amjad Masad 0671b2b6f2 Return concrete file paths to the client
Reviewed By: @martinbigio

Differential Revision: D2465182
2015-09-22 15:45:25 -07:00
Martín Bigio a2b8762e4d Add logging information when client's socket gets closed unexpetedly
Reviewed By: @amasad

Differential Revision: D2468293
2015-09-22 15:21:35 -07:00
Amjad Masad 06b6ef4d84 Simplify over-engineered Activity module
Summary: @​public
I've noticed that the logs can be sometimes misleading, as when an Activity ends it doesn't log immediatly. A sync `console.log` would log before it although the Acitivity should've finished before.

Turns out we wait before writing out the logs to the console. I don't see any reason for this. Looking at the `Activity` module it's over-engineered. This diff makes logging sync and simplfies the module.

Reviewed By: @martinbigio

Differential Revision: D2467922
2015-09-22 14:25:37 -07:00
Amjad Masad 45d07e4f77 Log exit code
Reviewed By: @martinbigio

Differential Revision: D2467457
2015-09-22 12:40:25 -07:00
Christoph Pojer e3f7a3933c Fix tests + enable inline requires on react-native
Reviewed By: @sahrens, @vjeux

Differential Revision: D2456607
2015-09-21 14:39:44 -07:00
Martin Bigio fe2d48ea12 Log uncaught exceptions on the socket server
Reviewed By: @frantic

Differential Revision: D2462114
2015-09-21 12:08:29 -07:00