Commit Graph

1105 Commits

Author SHA1 Message Date
David Aurelio 8cbc403700 Add source map helper
Summary: Adds a helper to produce index source maps for Buck builds

Reviewed By: cpojer

Differential Revision: D4265911

fbshipit-source-id: 9ca3c49876df5db039bae823c0458c98e6e05619
2016-12-05 16:43:45 -08:00
David Aurelio d80f231ef8 Don’t use spaces when amending module wrapper
Summary: since we use the same module wrapper amendment function for dev and prod builds, and code is already minified at this point, we minify ourselves by leaving out space.

Reviewed By: cpojer

Differential Revision: D4265967

fbshipit-source-id: 719a3bbfbc02c9af1bb3fa08317b2f1b92c141a5
2016-12-05 16:43:45 -08:00
David Aurelio b3ad054424 ModuleGraph: Also call back with module objects of entry points
Summary:
This changes the callback value of `Graph` function so that it also contains a separate property with `Module` instances of the entry points.

Having references to the entry point modules allows to e.g. create require calls to them dynamically to kick of bundle execution.

The commit also contains a refactoring of the `Graph` function and its helpers that reduces the need for extensive parameter passing and long nested functions.

Reviewed By: cpojer

Differential Revision: D4250772

fbshipit-source-id: 2edca77bbef2308d3176a62123b8cecd70e2c8c7
2016-12-05 16:43:45 -08:00
Jean Lauliac f585a9ea63 packager: Server/index.js: moar @flow
Summary:
Let's continue to bring Flow goodness to the codebase, as it will facilitate future refactorings.

I fixed a few of the typing issues by changing the local logic at times, but in a way that should not cause any difference globally.

Reviewed By: cpojer

Differential Revision: D4265347

fbshipit-source-id: a2a7afd7d93cf00ba58e8c9879a9bb6d5bf30358
2016-12-02 10:58:31 -08:00
Andrew Imm f4b738ff8e Allow custom platforms for the RN Packager on a per-project basis
Reviewed By: cpojer

Differential Revision: D4255979

fbshipit-source-id: bf900b67ee30e2f994e96c9a6103ed2e53a87f88
2016-12-02 09:43:31 -08:00
Jean Lauliac 7014885067 packager: make legocastle script to write to the global cache
Reviewed By: davidaurelio

Differential Revision: D4251001

fbshipit-source-id: bde1e50c82c2cb8f2c2577139061498c809aa37e
2016-12-02 06:58:29 -08:00
Janic Duplessis a1f4dac064 Fix packager asset requests on windows
Summary:
6554ad5983ae85212684a09869e2ea2e0b743dd3 broke assets on windows, this fixes it and add a test to avoid regressions.

Ideally we'd run all the Dependency graph tests on both posix and win32 filesystems but that would probably require doing some sort of factory function to create the tests because I don't think we want to duplicate every test (file is big enough already :)). So for now I just copied that one test and changed the paths manually.

**Test plan**
Run the new test without the fix -> fails
Run the new test with the fix -> succeeds
Closes https://github.com/facebook/react-native/pull/11254

Differential Revision: D4265157

Pulled By: cpojer

fbshipit-source-id: 511470276bd950c2943e94c2dce6840df0fe6d69
2016-12-02 04:58:34 -08:00
Charles Dick 336376e018 Pull aggrow from facebookincubator/tracery-prerelease
Reviewed By: bnham

Differential Revision: D4250937

fbshipit-source-id: b5f2cfdeb06c04399670e463b8b2498e2fe0074b
2016-11-30 12:58:35 -08:00
Christoph Pojer 17ccb9b8c4 kill `shouldThrowOnUnresolvedErrors` option
Summary: Removes the `shouldThrowOnUnresolvedErrors` option, as now it is only ever `() => true`

Reviewed By: davidaurelio

Differential Revision: D4237711

fbshipit-source-id: 9460f0f0c50dc0d08d17cb7bdeb995825f7051f3
2016-11-30 10:13:36 -08:00
Jean Lauliac 1b4bdf0bac packager: Module: gives global cache more retries
Reviewed By: cpojer

Differential Revision: D4250880

fbshipit-source-id: c2d215d4dad10705bc24bec758aed85ef13607ba
2016-11-30 07:43:42 -08:00
Jean Lauliac 6d26816cc6 packager: GlobalTransformCache: globalized keyOf
Reviewed By: davidaurelio

Differential Revision: D4243863

fbshipit-source-id: 917a8a116baf67c838c062b7b713dd4660d9f673
2016-11-30 07:43:42 -08:00
Jean Lauliac 76c0b8351d packager: GlobalTransformCache: better aggregation
Reviewed By: davidaurelio

Differential Revision: D4238279

fbshipit-source-id: 3b79a3e87d0eb975efce6adc11b13862c7138e1b
2016-11-30 07:43:42 -08:00
Jean Lauliac 937dc7ca17 packager: Bundler: hash all the cache key components
Reviewed By: davidaurelio

Differential Revision: D4238061

fbshipit-source-id: 2ad79a85a5da3026afd508557b3b29457f472bb2
2016-11-30 07:43:42 -08:00
Christoph Pojer 771e60235a Kill fastfs
Summary:
This kills fastfs in favor of Jest's hasteFS. It gets rid of a ton of code, including the mocking code in ResolutionRequest which we don't need any more. Next step after this is to rewrite HasteMap, ModuleCache, Module/Package. We are getting closer to a nicer and faster world! :)

Here is what I did:
* Use Jest's HasteFS instead of fastfs. A fresh instance is received every time something changes on the FS.
* HasteFS is not shared with everything any more. Only one reference is kept in DependencyGraph and there are a few smaller functions that are passed around (getClosestPackage and dirExists). Note: `dirExists` now does fs access instead of an offline check. This sucks but stat calls aren't slow and aren't going to be a bottleneck in ResolutionRequest, I promise! When it is time to tackle a ResolutionRequest rewrite with jest-resolve, this will go away. "It gets worse before it gets better" :) The ModuleGraph equivalent does *not* do fs access and retains the previous way of doing things because we shouldn't do online fs access there.
* Add flow annotations to ResolutionRequest. This required a few tiny hacks for now because of ModuleGraph's duck typing. I'll get rid of this soon.
* Updated ModuleGraph to work with the new code, also created a mock HasteFS instance there.
* I fixed a few tiny mock issues for `fs` to make the tests work; I had to add one tiny little internal update to `dgraph._hasteFS._files` because the file watching in the tests isn't real. It is instrumented through some function calls, therefore the hasteFS instance doesn't get automatically updated. One way to solve this is to add `JestHasteMap.emit('change', …)` for testing but I didn't want to cut a Jest release just for that. #movefast

(Note: I will likely land this in 1.5 weeks from now after my vacation and I have yet to fully test all the product flows. Please give me feedback so I can make sure this is solid!)

Reviewed By: davidaurelio

Differential Revision: D4204082

fbshipit-source-id: d6dc9fcb77ac224df4554a59f0fce241c01b0512
2016-11-30 04:28:32 -08:00
David Aurelio 2151936b80 Add utilities for bundle creation
Summary: Adds utilities needed for bundle creation: `completeModuleWrapper` appends numeric IDs for the module itself and its dependencies to a module wrapped. `createGetModuleId` returns a function that returns sequential numeric IDs for strings, and is idempotent.

Reviewed By: cpojer

Differential Revision: D4240334

fbshipit-source-id: c165482ebcf0e81ebb83ba6ff634de095ffb6bf0
2016-11-30 03:13:40 -08:00
David Aurelio 269d1e10fa change `isPolyfill` to `type = 'module' | 'script'`
Summary: When building, we will process modules in a special way, *not* polyfillys. We will also add more types of (virtual) files that are not modules. That’s why a “type” property makes more sense.

Reviewed By: cpojer

Differential Revision: D4244583

fbshipit-source-id: 92a0b4a0a2026d0b97ba88034483a6ce4e0c1ebb
2016-11-30 03:13:40 -08:00
David Aurelio ee607f8ecf Fix double callback invocation in `ModuleGraph/Graph`
Summary:
The logic in `ModuleGraph/Graph` allowed the callback to be invoked twice, if two invocations of `resolve` call back with errors asynchronously.

This fixes that problem by always calling `queue.kill()` on the asynchronous queue, and only invoke the main callback from the `drain` and `error` queue callbacks.

Reviewed By: jeanlauliac

Differential Revision: D4236797

fbshipit-source-id: c30da7bf7707e13b11270bb2c6117997fd35b029
2016-11-30 03:13:40 -08:00
Tim Yung 5396a15559 RN: Move `core` to Shared
Reviewed By: cpojer

Differential Revision: D4250233

fbshipit-source-id: 8c42bed47559c477be039d47e3f4fd1fac503152
2016-11-29 23:13:50 -08:00
Jean Lauliac 2322db4f81 packager: Bundler: use stable paths for cache key
Summary: For having a global cache, we need cache keys that are the same from different machines, so we cannot include user/machine-specific information. In that regard, I suggest we consider the paths relatively to the install directory of the React Native instead of being absolute, so that they are more chances they stay stables between different installations, users, machines.

Reviewed By: davidaurelio

Differential Revision: D4237840

fbshipit-source-id: d864b9739550ac2c95d5693db12bd1592411f80a
2016-11-29 11:58:35 -08:00
Jean Lauliac d4008ab33c packager: Bundler: use transform module hash instead of mtime
Summary: mtime is a problem for the global cache, because everyone has different times at which they rebased/cloned the repo. Use the actual content instead. Of course, the file could depend on other files we don't take into account... but the mtime solution was already problematic in that regard, so I assume this is a safe change.

Reviewed By: davidaurelio

Differential Revision: D4237826

fbshipit-source-id: 9dc18eb422cddd4d5ed097d1ebeef4b8c361ff39
2016-11-29 11:58:35 -08:00
Jean Lauliac 305c6ed6f9 packager: Module: better type for transformOptions
Reviewed By: davidaurelio

Differential Revision: D4237808

fbshipit-source-id: 8ca40bc9f8e7ec7cea2aaa8a8562dc63d423cea4
2016-11-29 04:28:36 -08:00
Tim Yung 0b7a6d830f Packager: Shorter + Consistent-Width Timestamps
Summary: Sets some options on `toLocaleString()` so that the server debug output's timestamps are shorter and have a consistent width (zero-padded).

Reviewed By: cpojer

Differential Revision: D4235074

fbshipit-source-id: 72dcf35ffd182eb70afc20d2b266314787433c4a
2016-11-28 13:13:35 -08:00
Tim Yung 90197e919b Packager: Print Debug Fields on Separate Lines
Summary:
When printing fields in the packager server debug output, this revision breaks the fields up onto multiple lines.

As it currently exists, the fields are printed immediately after the log entry label which can seem unnecessarily repetitive and unintuitive.

Reviewed By: davidaurelio

Differential Revision: D4235038

fbshipit-source-id: 2d59afa70c74f19afab221dfa58f437913c6dc2c
2016-11-28 13:13:35 -08:00
Gabe Levi 368ef3ef4b Deploy v0.36.0
Reviewed By: zertosh

Differential Revision: D4237912

fbshipit-source-id: cc251884350ffa3c8715a4920f90bd301e8a9b7f
2016-11-28 10:13:31 -08:00
David Aurelio 64c1205838 BREAKING: expose `getTransformOptions` directly in configuration
Summary:
Instead of exposing a `getTransformOptionsModulePath` function in configurations, we can simply expose a `getTransformOptions` *function*. The necessity of exposing a path comes from the olden days, where we had a server listening on a socket, and a client, talking to that server.

Since that architectural gem no longer exists, we can use functions directly, rather than passing paths to modules around.

Reviewed By: cpojer

Differential Revision: D4233551

fbshipit-source-id: ec1acef8e6495a2f1fd0911a5613c144e8ffd7c3
2016-11-28 07:28:33 -08:00
David Aurelio fb9d114861 Simplify contract of `getTransformOptionsModulePath`
Summary:
instead of passing the `Bundler` instance, the transform options module now receives a `getDependencies()` function.
The idea is to make the contract stricter, to integrate more easily with the new `ModuleGraph` system.

Reviewed By: cpojer

Differential Revision: D4233529

fbshipit-source-id: 1c6d462c7dae1c61cbf45fd13989ce77f76e7384
2016-11-28 07:28:33 -08:00
Pieter De Baets 2be362b017 Stop silently failing for requires on Android
Reviewed By: bestander

Differential Revision: D4237195

fbshipit-source-id: 51266664a3693d8e942e97ffd0b0ddc7ada74819
2016-11-28 05:58:27 -08:00
penx 59f870b0f6 Fix to spelling in error message
Summary: Closes https://github.com/facebook/react-native/pull/11149

Differential Revision: D4234240

fbshipit-source-id: 8664f9950d4ab78a87f1d23c84073e74b21a5126
2016-11-26 14:58:26 -08:00
Jean Lauliac 158da01d26 packager: add GlobalTransformCache
Reviewed By: davidaurelio

Differential Revision: D4175938

fbshipit-source-id: 1f57d594b4c8c8189feb2ea6d4d4011870ffd85f
2016-11-24 09:58:31 -08:00
David Aurelio a810087624 BREAKING kill deprecated asset support
Summary:
This removes support for `require('image!…')`, which has been deprecated for a long time.

It is still possible to use images that are already bundled by the native app using the `nativeImageSource` module.
Check http://facebook.github.io/react-native/docs/images.html for detailed documentation.

Reviewed By: matryoshcow

Differential Revision: D4231208

fbshipit-source-id: 05ec4c1ca0fabdc3fbb652f8ad1acdf240a67955
2016-11-24 05:43:38 -08:00
Ovidiu Viorel Iepure 1b8582a2d1 Packager version in logs
Summary: Add Packager version to log entries.

Reviewed By: davidaurelio

Differential Revision: D4212961

fbshipit-source-id: 96036eb2dc70d959108ef5a3a14c58643aba5349
2016-11-24 04:43:26 -08:00
David Aurelio bb1279694b Bring back programmatic packager API
Summary:
Brings back parts of the programmatic API removed in 7762f374d50d3b1df8513c826862c2056e8718f9. This is used by a few people. Also updates the docs accordingly.

cc akaila

Reviewed By: jeanlauliac

Differential Revision: D4226348

fbshipit-source-id: e5c0794f9c5415f14b54d16c6f35f902eafc3064
2016-11-23 06:28:28 -08:00
alex 719126bae2 Caching assets only for production environment
Summary:
**Motivation**

In the context of a webview, one may extract assets (javascript or any types really), and relates to them through the html.

The packager `Server` serves this files correctly but also applies a cache based on time (a year). During development, this cache is actually bad as we need to re-iterate the process of editing/testing quickly.

I don't believe it is necessary to cache, and still wanted to make sure we would if process.env.NODE_ENV is 'production'.

**Test plan**

Run jest on impacted files:
```
node_modules/.bin/jest packager/react-packager/src/Server/__tests__/Server-test.js
```
Closes https://github.com/facebook/react-native/pull/10919

Differential Revision: D4226350

Pulled By: davidaurelio

fbshipit-source-id: d4bbff5b1a5b691aab197bcddb8fa9d2e43caa16
2016-11-23 04:58:31 -08:00
David Aurelio 7d998e6f58 Add flow types for output modules
Summary: Adds flow types for output functionality for easier maintenance and interop with new code

Reviewed By: matryoshcow

Differential Revision: D4211863

fbshipit-source-id: 591407d3a6d49536054ae94ba31125c18a1e1fa1
2016-11-21 13:28:30 -08:00
Ovidiu Viorel Iepure 038cfa8ebe Logger API error handling improvement
Summary: Defer Logger calls to the next tick queue so as to avoid potential Logger errors from falling under the purview of Promise error handling, which would degrade development experience by "swallowing" legitimate runtime errors within rejected promises, to the infuriation of us all :D

Reviewed By: davidaurelio

Differential Revision: D4197869

fbshipit-source-id: 10a44904be1404ad2534d06ddc56048c1c24f32b
2016-11-21 05:58:27 -08:00
Tim Yung 40c3857d23 RN: Cleanup OSS JS & Flow Declarations
Reviewed By: vjeux

Differential Revision: D4210763

fbshipit-source-id: 5abaa547100b8badd13bcf311ceffc5b4098d252
2016-11-20 17:58:29 -08:00
David Aurelio 4c74a3fe2e Handle transform problems correctly
Summary: This fixes a piece of promise code that didn’t handle nested rejections. This caused the packager not to recover from transform errors, as the server was waiting for an in-limbo promise forever.

Reviewed By: cpojer

Differential Revision: D4207138

fbshipit-source-id: 8e94ddebd033073f90b79b1c4820c09ac98a4932
2016-11-18 20:43:28 -08:00
David Aurelio 2c0a1e1f00 Updates to node-haste adapter
Reviewed By: matryoshcow

Differential Revision: D4197864

fbshipit-source-id: 31bc4b0fb51ea77fac09fdd0f8180e984e05087a
2016-11-17 11:13:30 -08:00
David Aurelio 1c16124e1c Add tests for worker code
Summary: This adds unit tests for the new buck worker code, including a test for source map generation.

Reviewed By: cpojer

Differential Revision: D4193657

fbshipit-source-id: 06f7bfb5efa4f411178543a728ac7e42511caa3c
2016-11-17 08:58:55 -08:00
David Aurelio 7181a2d436 add flow
Summary: This adds flow types to new code written for the Buck/Packager integration.

Reviewed By: cpojer

Differential Revision: D4175156

fbshipit-source-id: 38c3d2c9176c7b3cf22b8baed7d445a75d033d04
2016-11-17 08:58:55 -08:00
David Aurelio 907f08a794 Use array lookup for localized dependency IDs
Summary:
The current transform for require calls replaces strings with module-local IDs. That means that each module would need a local require function.
To save hundreds of closure allocations, we can just use an array that maps local IDs to global IDs.

This diff changes the dependency collection and replacement transform to change a call like `require('React')` to something like `require(_dependencyMap[0])` rather than `require(0)`.

Reviewed By: cpojer

Differential Revision: D4153714

fbshipit-source-id: a63455834c6c2a75da6977cacb9aac9f2cb1b3aa
2016-11-17 08:58:55 -08:00
Jean Lauliac 06de9b9a93 packager: DependencyGraphHelpers: @flow
Reviewed By: cpojer

Differential Revision: D4190148

fbshipit-source-id: 320496bb683288a19605bd667de1472c7fc9c6b4
2016-11-17 05:13:27 -08:00
Christoph Pojer d96e125d39 New file watching implementation
Summary:
This is the next incremental step to rewrite node-haste. I apologize for the size of this diff but there is really no smaller way to do this. The current architecture passes a single file watcher instance into many classes that each subscribe to file changes. It's really hard to keep track of this. The new implementation reduces the listeners to two (will eventually be just one!) - one in DependencyGraph and one in it's parent's parent's parent (ugh! This doesn't make any sense). This should make it much more straightforward to understand what happens when a file changes.

I was able to remove a bunch of tests because jest's watcher takes care of things like ignore patterns. Some of the tests were specifically testing for whether the change events were invoked and they are now much more straightforward as well by manually invoking the `processFileChange` methods.

(Relanding a fixed version of D4161662)

Reviewed By: kentaromiura

Differential Revision: D4194378

fbshipit-source-id: 8c008247a911573f6b5f6b0b374d50d38f62a4f5
2016-11-16 20:13:26 -08:00
Jean Lauliac dfd9713fce packager worker: more @flow
Reviewed By: matryoshcow

Differential Revision: D4160528

fbshipit-source-id: 5f43cb47717288c5344c1204cf435ec727ca752e
2016-11-16 10:43:25 -08:00
Martin Konicek 855a74d2b1 Revert D4161662: [RNP] New file watching implementation
Differential Revision: D4161662

fbshipit-source-id: 00604387b4f4b808f95275458f1c653981f91b86
2016-11-16 10:28:31 -08:00
Christoph Pojer f50b4d7876 New file watching implementation
Reviewed By: davidaurelio

Differential Revision: D4161662

fbshipit-source-id: 9a2a399304c83b411a8b0b74ea015c18b599fbaf
2016-11-16 01:13:40 -08:00
Christoph Pojer d207bc32ec Update Jest + jest-haste-map
Reviewed By: voideanvalue

Differential Revision: D4180887

fbshipit-source-id: f6ee6901e63206824f0639c81b64167b66da2168
2016-11-15 06:58:45 -08:00
Andres Suarez 91a409afe6 Remove parse
Reviewed By: davidaurelio

Differential Revision: D4174312

fbshipit-source-id: 024ae3da56c1afd882f808c15a3b90db35627587
2016-11-15 04:59:48 -08:00
Jean Lauliac 77d1ca470d packager: JSTransformer/index.js: @flow
Reviewed By: cpojer

Differential Revision: D4167006

fbshipit-source-id: db0deb2262fe2c53735cb46d9de6e6da1b375180
2016-11-15 04:28:53 -08:00
Jean Lauliac ece4a18d7c packager: DependencyGraph-test: require extractDependencies only once
Reviewed By: davidaurelio

Differential Revision: D4182071

fbshipit-source-id: 622cb3e011b67c2a7df0c6308fbcb7a9ea1ebb96
2016-11-15 03:43:42 -08:00