Summary:
${REACT_NATIVE_DIR} needs to be quoted as "${REACT_NATIVE_DIR}" otherwise projects paths with spaces in, will fail to build.
e.g. a project in `/home/me/some folder` will fail to build with:
```
../node_modules/react-native/packager/react-native-xcode.sh: line 37: cd: /home/me/some: No such file or directory
```
Closes https://github.com/facebook/react-native/pull/11487
Differential Revision: D4336281
Pulled By: lacker
fbshipit-source-id: c5d19fbd21978714c7af44c305ba854477118e1d
Summary:
Keep track of the number of cache misses. If we have a series of misses but then we
start seeing hits, then we progressively reset the counter. If there are too many misses, we just give up on the global cache.
Reviewed By: cpojer
Differential Revision: D4326689
fbshipit-source-id: 5606fc860cbb9d7e9e877c0d1dc4e6a6a1cbcd98
Summary: This adds the machinery necessary to create a bundling function, and adds different reusable parts around generating code and maps for bundles. Used for the new integration with Buck
Reviewed By: cpojer
Differential Revision: D4299272
fbshipit-source-id: 59ebe39a454ebf56c2159717c2881088d6d3308a
Summary: Rather than using relative paths from the build root, this switches all paths to absolute paths from the build root. This makes integration with a lot of tooling easier.
Reviewed By: jeanlauliac
Differential Revision: D4285474
fbshipit-source-id: 80d20e0f6dc61a310e72112b9654628bff81a4f0
Summary: Adds the necessary functionality to serialize a series of `Module`s to a bundle and a source map in the context of the new Buck/Packager integration
Reviewed By: cpojer
Differential Revision: D4265867
fbshipit-source-id: f2d3e4ffed64a3dca817101faad7bced9f16edc7
Summary: Since all paths are relative when building with the new Buck integration, `HasteMap` needed support for these.
Reviewed By: cpojer
Differential Revision: D4265888
fbshipit-source-id: 2d454bfd3866028d8d2c268c0fd318b148951dc9
Summary: Adds a helper to produce index source maps for Buck builds
Reviewed By: cpojer
Differential Revision: D4265911
fbshipit-source-id: 9ca3c49876df5db039bae823c0458c98e6e05619
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
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
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
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
Summary: Removes the `shouldThrowOnUnresolvedErrors` option, as now it is only ever `() => true`
Reviewed By: davidaurelio
Differential Revision: D4237711
fbshipit-source-id: 9460f0f0c50dc0d08d17cb7bdeb995825f7051f3
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
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
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
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
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
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
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
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
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
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
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
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
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