Commit Graph

520 Commits

Author SHA1 Message Date
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
Louis Pilfold a065510ec8 Add support for nodenv with xcode
Summary:
Hello!

I'm a fan of the *env family of version managers over the *vm family as I find them simpler and less obtrusive, but it seems that they don't currently work so well with react-native on OSX. See #4645

I've made a small addition to the xcode script that resolves the issue for me. Hopefully others will find this useful too :)

If I've not made the right move here, what is the correct way to get react-native projects building in xcode when the binary is not in the $PATH used by the script?

Cheers,
Louis
Closes https://github.com/facebook/react-native/pull/4801

Reviewed By: svcscm

Differential Revision: D2770726

Pulled By: androidtrunkagent

fb-gh-sync-id: 3b0f9e466549b3012a68c94738d2556173f4c21e
2015-12-17 14:10:36 -08:00
Martin Konicek 29b735fdc1 Merge pull request #4809 from isair/patch-2
[packager][README] "find can more" -> "can find more"
2015-12-16 14:06:50 +00:00
Tim Yung f14863dd9b RN: Install Updated `fbjs` Downstream
Reviewed By: cpojer

Differential Revision: D2754195

fb-gh-sync-id: 67b628fdfa34da379ab5fdad03b1baaf767c7f21
2015-12-16 01:49:15 -08:00
Baris Sencan 3a5b8b5abe [README] "find can more" -> "can find more" 2015-12-15 18:34:19 -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
Billy Lamberta ab09248540 Add the npm global prefix to PATH.
Summary:
Related to issue https://github.com/facebook/react-native/issues/4034#issuecomment-164134543.
The npm global install path may be set to a non-standard location. `react-native` is assumed to be in `PATH` but doesn't take into account the user's environment so building in Xcode fails:
~~~
react-native bundle --entry-file index.ios.js --platform ios --dev true --bundle-output [...]

../node_modules/react-native/packager/react-native-xcode.sh: line 48: react-native: command not found
Command /bin/sh failed with exit code 127
~~~
This fix uses `npm prefix -g` to get the bin location and adds it to `PATH`.
Closes https://github.com/facebook/react-native/pull/4749

Reviewed By: svcscm

Differential Revision: D2753215

Pulled By: androidtrunkagent

fb-gh-sync-id: 964d1a71ac1bf204545a594a9fa433a7bc367f35
2015-12-12 13:08:31 -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
Brian Leonard da0ad0ce4c Allow other Xcode configurations with DEV=false
Summary:
Updates build script to fix https://github.com/facebook/react-native/issues/4362
Closes https://github.com/facebook/react-native/pull/4520

Reviewed By: svcscm

Differential Revision: D2730607

Pulled By: mkonicek

fb-gh-sync-id: 2fc4a9815f19ab867a6a3dc77cf1b6eac8a25616
2015-12-09 04:41:28 -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
James Ide b025a8d946 Support plugins that conform to ES6 modules
Summary:
ES6 modules export an object with a property called `default`. See Babel itself for how this is handled: b5b7e346a0
Closes https://github.com/facebook/react-native/pull/4513

Reviewed By: svcscm

Differential Revision: D2715512

Pulled By: mkonicek

fb-gh-sync-id: 40e5ea35adcdb66806a4895578d637cd72538619
2015-12-04 07:45:29 -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
Sebastian McKenzie b0b2a27b75 Ensure correct Babel plugin locations in packager transform
Summary: Manually resolve all default Babel plugins. `babel.transform` will attempt to resolve all base plugins relative to the file it's compiling. This makes sure that we're using the plugins installed in the react-native package.

**NOTE:** Haven't tested this. Please don't merge until Travis has done CI.
Closes https://github.com/facebook/react-native/pull/4248

Reviewed By: svcscm

Differential Revision: D2679651

Pulled By: davidaurelio

fb-gh-sync-id: 0cdef1e738ba28c09c811432a71047f80540ed7b
2015-11-20 07:54:29 -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
Tadeu Zagallo a0cc7d3ee0 Update oss transformer
Summary: public

The inline-requires transform (from `fbjs-scripts`) is only used for oss tests, and wasn't updated, fix it.

Reviewed By: mkonicek

Differential Revision: D2641711

fb-gh-sync-id: 90a084082b9c55c5bcb776346f4655451a8a61f7
2015-11-12 07:05:07 -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