Summary: I wanted to settle #18056064 once and for all. This solution both uses (1) random generation of temp dir, and (2) minimal overhead in the repo. The reason random generation of temporary folder directory names should always be used is the same as why [`mktemp(3)` should never be used](http://man7.org/linux/man-pages/man3/mktemp.3.html#BUGS). The reason we don't want the cache to be fully stored locally (2) is because watchman would catch too many change events we don't care about, hitting performance. Additionally, (1) has the benefit that when one clones the repo from fresh, it'll also always start with a fresh cache. (1) uses a function equivalent to [`mkdtemp(3)`](http://man7.org/linux/man-pages/man3/mkdtemp.3.html), that we cannot use here because it's POSIX and not exposed by the Node.js API.
Reviewed By: davidaurelio
Differential Revision: D5199698
fbshipit-source-id: a660ebbc470e1fe90ed1ab9d0c9fda063b06f90c
Summary: Puts all invocations of `uglify.minify` into one place to facilitate the upgrade to Uglify 3
Reviewed By: cpojer
Differential Revision: D5218415
fbshipit-source-id: 8085255205f80bfda06e0092c9e268a85947763b
Summary: The 'class' suffix was just to workaround case-insensitivity on macOS.
Reviewed By: cpojer
Differential Revision: D5208747
fbshipit-source-id: 46bff156145880b9a894ff70b0c3dff0895a6d6c
Summary:
The 'fs' mock was set up to require 'graceful-fs', which used to delegate to the corresponding mock. After turning off automocking, this no longer necessarily works.
This moves the mock to `fs.js` and makes the mock for graceful-fs require the fs mock via a relative path.
Reviewed By: cpojer
Differential Revision: D5209130
fbshipit-source-id: d468577e09d18382d0b9602ad0964dd880ec2366
Summary: That should improve the hit rate a little bit, notably for the cache-filling script. On OSS side, this changeset only adds the sleep() function as `FBGlobalTransformCache` is not exposed.
Reviewed By: cpojer
Differential Revision: D5201196
fbshipit-source-id: c2d8e1a1b03edd9e7747b3202c574b0783f4117d
Summary: We don't actually need this object anymore, just the function to test a file existence. This simplification allows us to phase out the 'old' HasteFS object easier, as well as adding retry logic using the real filesystem.
Reviewed By: cpojer
Differential Revision: D5208550
fbshipit-source-id: a03317e4385d793643e2dbee5d6782491d20e33c
Summary: We are flipping the switch all over Facebook, now that this part of the code is isolated we can do it in Metro as well.
Reviewed By: davidaurelio
Differential Revision: D5199449
fbshipit-source-id: 20c1bacc6dd2d314bd76bc5cc0ecd13266bf81c6
Summary: This is a basic README for the new repo. We'll eventually expand on this as more pieces get open sourced and we'll evolve the three identifying tags over time.
Reviewed By: jeanlauliac
Differential Revision: D5172314
fbshipit-source-id: 8e5dd8567eadbcb839ee9860a22929fd6a77ee2e
Summary:
The packager dependencies CLI command always operates on --dev=true today. This means any tooling that needs to get the production dependencies (--dev=false) will always get the dev-mode list instead. For instance:
```
if (__DEV__) {
require('Foobar');
}
```
Previously, `Foobar.js` will always be listed in the CLI output. With this change, setting `--dev false` option will correctly skip `Foobar.js` in the output.
Reviewed By: cpojer
Differential Revision: D5163184
fbshipit-source-id: 203221ee5d6ecb7df575442f12f6c4c489bfbd46
Summary: This should fix the e2e test for OSS.
Reviewed By: cpojer
Differential Revision: D5164267
fbshipit-source-id: d858b4811f0eb80ca7363177f4f384b66af13994
Summary: I want to untangle `ResolutionRequest` once and for all, that starts by pulling stuff out :-)
Reviewed By: cpojer
Differential Revision: D5155316
fbshipit-source-id: a46ee9b40c6705edcac169adcfdffe25058ec810
Summary: This fixes a longstanding bug that happens when 2 bundles with the same entry path but different options (dev, minify, etc.) get mixed up in the reporting. To prevent that we just use a unique build ID for each bundle that the Server handles separately.
Reviewed By: cpojer
Differential Revision: D5147049
fbshipit-source-id: da5c9cfe8c6a5d888b5be737947800d213081d86
Summary: By getting rid of callbacks, we get a code that's pretty halved in size, and much easier to read, but we also fix bugs! When some of the code of Module would throw, we wouldn't catch it, meaning that packager would crash entirely. That's the case for when we have a Haste name mistach, for example. This changeste fixes that by instead capturing exceptions through the Promise chain, that bubble up all the way to the `Server` and reasonnably handled. People can then fix the Haste nane mismatch and refresh right away, and it'll work as expected.
Reviewed By: davidaurelio
Differential Revision: D5137408
fbshipit-source-id: b9e938b93e8d23738af49106bbae1fce97d7a5db
Summary: I'd like us to start having some decent testing at the packager/bundler level to check that there are no major breakage hapenning. This changeset introduce a simple test that just test the `buildBundle` public API. On the same model, I'd like to test the server API and behavior, and things such as hot module reloading. I hope this will also highlight the gross inconsistencies of the API, for example the Bundle/BundleBase hierarchy, that we can proceed to fix later.
Reviewed By: davidaurelio, cpojer
Differential Revision: D5121817
fbshipit-source-id: e0f3758c7fbb7a85cf51fb3cbc34c12d5374b7d3
Summary:
Code generation for indexed RAM bundles did not append module ID and dependencies. This fixes that.
Eventually, we only want to have the call to `addModuleIdsToModuleWrapper` in one place.
Reviewed By: jeanlauliac
Differential Revision: D5129255
fbshipit-source-id: 7f6148dd607bbf7c97e9df7936a07bde3f05b3aa
Summary: This allows us to get the new fix for recovery on duplicate modules.
Reviewed By: cpojer
Differential Revision: D5128975
fbshipit-source-id: 5a2b60430bbca1806a97798c482af8522366e071
Summary:
This changeset moves the creation of the transform cache at the top-level of the bundler so that:
* we can use alternative folders, such as the project path itself, that I think will be more robust especially for OSS;
* we can disable the cache completely, that is useful in some cases (for example, the script that fills the global cache).
The reasons I believe a local project path is more robust are:
* there are less likely conflicts between different users and different projects on a single machine;
* the cache is de facto cleaned up if you clone a fresh copy of a project, something I think is desirable;
* some people have been reporting that `tmpDir` just returns nothing;
* finally, it prevents another user from writing malicious transformed code in the cache into the shared temp dir—only people with write access to the project have write access to the cache, that is consistent.
Reviewed By: davidaurelio
Differential Revision: D5113121
fbshipit-source-id: 74392733a0be306a7119516d7905fc43cd8c778e
Summary:
* Internally, we already set up babel before calling into metro-bundler.
* Externally, I moved the setup calls to outside the packager/ folder.
If somebody has a custom integration with RN, they would need to setup babel themselves up until we make the open source split. By the time this is released in open source, an npm version of metro-bundler will be available for use.
Next step: also do this for the worker and remove setupBabel from the metro repo.
Reviewed By: davidaurelio
Differential Revision: D5121429
fbshipit-source-id: e77c6ccc23bef1d13fd74c4727be2d7e09d2d0ca
Summary: Adds support for “RAM bundle groups” (common section for module groups) to the new Buck integration
Reviewed By: jeanlauliac
Differential Revision: D5112065
fbshipit-source-id: 038c06b8f4133c7fcd39aba8bb04a5ef42594f3e
Summary: This is a first step towards doing an experiment I was talking about, that is, using the local directory (the directory where the config file lives) instead of the tmp dir, that is fragile.
Reviewed By: davidaurelio
Differential Revision: D5112326
fbshipit-source-id: 819636209972115e41213867f3eb78fbdf6ed9df
Summary: in order to prepare open sourcing React Native Packager, we have to move scripts specific to React Native to a directory that will continue to exist.
Reviewed By: javache
Differential Revision: D5112193
fbshipit-source-id: eac77d0d981aecef7ee52365a6856340420a5638
Summary:
Working on refactoring error handling in `_loadAsDir` I figured out it was oftentimes problematic to pass on the candidates out of the functions as an array, as in practice there's always a single "candidates" object passed out. Also, using an array prevented nice Flow typing and forced additional invariants to be added. So I replaced that by a return value that explicitely can be either a module, or resolution candidates. That way the semantic is more clear: we don't get any candidates if we did resolve properly, and at the same time we enforce returning candidates if we could not resolve any module.
At first I wanted to just have type `{module: TModule} | {candidate: TCandidate}`, but Flow would hit edge cases, so instead I added a field `type` that make it explicit what is the result of the resolution, and allows Flow to refine the type fully after we test that field. This allows us to remove the extraneous invariants. Also, a nice thing is that at a few places, even if the type of the candididate is different, Flow allows us to return the "resolved" object just as it is, that prevents using more memory and causing more garbage collection than necessary.
Since we're creating more objects with that solution, this will be slightly less performant than returning `Module` objects directly, but I don't think it is worth micro optimizing this at that point. If really we see this to be causing trouble later, I'd try to find solutions such as reusing a pool of objects. Ex. we could pass the result `Resolution` object as argument instead of returning a fresh one, but that would make the code less legible, more complex.
Reviewed By: davidaurelio
Differential Revision: D5111501
fbshipit-source-id: f41cdab00640124081cfdf07668169bb2d5c00be