Commit Graph

1430 Commits

Author SHA1 Message Date
Jean Lauliac c03a76b01a packager: TransformCaching: make choice of cache explicit in the API
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
2017-05-25 04:25:35 -07:00
Christoph Pojer 5db8ac9d48 Remove setupBabel call from main entry point
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
2017-05-24 11:59:46 -07:00
David Aurelio f0e629b8bf Move packager core logic from `local-cli` to `packager`
Summary: Moves packager core logic to `packager/...` to prepare the open source split.

Reviewed By: cpojer

Differential Revision: D5116162

fbshipit-source-id: 06ee2406026686789f67acc88df41773866c3cd3
2017-05-24 08:10:56 -07:00
David Aurelio 3e8991548b Add support for RAM bundle groups
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
2017-05-24 08:10:56 -07:00
Jean Lauliac 502f24a266 packager: TransformCache: extract choice of root path outside of class
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
2017-05-24 07:52:32 -07:00
Christoph Pojer 20f7633d53 Fix DependencyGraph-test in OS.
Reviewed By: davidaurelio

Differential Revision: D5113955

fbshipit-source-id: 892331815393ca314e84112551f516a20126068f
2017-05-23 16:25:48 -07:00
David Aurelio 06bb33eba0 Move packager launcher scripts outside of `packager/`
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
2017-05-23 16:08:29 -07:00
Jean Lauliac 607268001a packager: ResolutionRequest: refactor _loadAsDir and dependents
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
2017-05-23 12:37:24 -07:00
Jean Lauliac d012a1fc84 packager: ResolutionRequest: use _loadAsFile from _loadAsDir
Summary: We can switch that case easily since it was already discarding the error if any would happen.

Reviewed By: davidaurelio

Differential Revision: D5103851

fbshipit-source-id: a0991f626e94a45efbf666561041af258fdbef0a
2017-05-23 12:37:24 -07:00
David Aurelio 05936a53d4 Covariant properties for `ModuleTransportLike`
Summary:
Make all properties of `ModuleTraansportLike` covariant to enforce read-only behavior at all sites using it.
The type only exists for compatibility reasons between old and new output functionality, and covariant properties give us stronger guarantees.

Reviewed By: jeanlauliac

Differential Revision: D5111667

fbshipit-source-id: 674658b07eb3a229cbc4344cb636e4a9ea4126d1
2017-05-23 10:37:40 -07:00
David Aurelio 132d71f0a3 Simplify `File` type: `map` is nullable, but not optional
Summary:
Simplifies the `File` type by making `map` a non-optional, but nullable property.
Also adds helper functions for empty/virtual modules

Reviewed By: jeanlauliac

Differential Revision: D5111580

fbshipit-source-id: 9cab6634a9bdb0522dc36aec2abccaef9cf35339
2017-05-23 10:37:40 -07:00
David Aurelio 7b5d91f359 Create an `OutputFn` that can build indexed RAM bundles
Summary: Adds functionality to assemble an indexed source map to the new Buck integration. This implementation supports startup section optimisations. Hooking it up, and grouping optimisations will be in follow-ups.

Reviewed By: jeanlauliac

Differential Revision: D5106985

fbshipit-source-id: cc4c6ac8cfe4e718fc8bb2a8a93cb88914c92e0b
2017-05-23 10:37:40 -07:00
Jean Lauliac 20d7a7cdc8 packager: add missing dep
Reviewed By: davidaurelio

Differential Revision: D5111613

fbshipit-source-id: bf3b574e6166601d52127540e7970839d7019b6c
2017-05-23 09:26:05 -07:00
Jean Lauliac 3529a955d1 add custom Promise def that accepts null arg for then() 2017-05-23 15:44:17 +01:00
Christoph Pojer f2572cf7b5 Minor lint fixes
Reviewed By: jeanlauliac

Differential Revision: D5111517

fbshipit-source-id: 5cf8884334b881fb9a2b1b490972faf45c0c569b
2017-05-23 06:53:42 -07:00
Jean Lauliac 926e42c1fc ignore specific node_module flow error 2017-05-23 13:52:20 +01:00
Christoph Pojer 4ebe1e70fc Properly mock `path` in DependencyGraph-test
Reviewed By: jeanlauliac

Differential Revision: D5111337

fbshipit-source-id: ceca2ec8917eda9ca34d65324d8b8c2a468eed1c
2017-05-23 05:11:29 -07:00
Christoph Pojer f8a724121b Add @format to a few files
Reviewed By: davidaurelio

Differential Revision: D5111297

fbshipit-source-id: bde11df412dd694edca78d6a61f4c69e5abba60a
2017-05-23 05:11:29 -07:00
cpojer 0eccb5ebf4 Add more packages. 2017-05-23 11:58:55 +01:00
cpojer 3d45d3c5d0 Update packages. 2017-05-23 11:40:47 +01:00
Jean Lauliac 71e6312e01 packager: DependencyGraph: @format
Reviewed By: davidaurelio

Differential Revision: D5103697

fbshipit-source-id: 43e2adc9bfd5902a95ad85333da1df323bddf755
2017-05-22 11:55:35 -07:00
Jean Lauliac 91fdb10abf packager: ResolutionRequest: empty module is special case
Summary: Because we don't want to test for `empty-module.ios.js`, etc. We know the module is supposed to be here. This simpler version makes it easier for me to switch the rest of the `loadAsFile` callsites to the "candidates" system to the "candidates" system.

Reviewed By: davidaurelio

Differential Revision: D5103816

fbshipit-source-id: 7e7d9be27573a1f33d562aeb850759e073fbc72f
2017-05-22 11:39:27 -07:00
Jean Lauliac 307eede076 packager: add preprocess for buck worker
Summary: For the Buck integration (work-in-progress), we want to add the ability to do some custom preprocessing similar to the packager server. The signature is different so I prefer to have a separate function for that. Also we don't need the transform options right now, I suggest we don't add them for now and add them later if necessary.

Reviewed By: davidaurelio

Differential Revision: D5094632

fbshipit-source-id: 1775ddef90b331deabc5be3e57a67436bce06c82
2017-05-22 09:08:45 -07:00
Christoph Pojer 8e8daabf3f Update package.json
Reviewed By: jeanlauliac

Differential Revision: D5103378

fbshipit-source-id: 64acdc767372a166460859ffba729710d5bf4b80
2017-05-22 07:52:44 -07:00
cpojer a7983ebcc8 Modernize scripts. 2017-05-22 11:54:20 +01:00
cpojer bc03c8d231 Update package.json. 2017-05-22 11:39:13 +01:00
Sebastian Bargmann 29c6548961 Run packager.sh using '.' instead of 'source'.
Summary:
'source' is not available in all shells on Linux (e.g. dash) and will silently fail launchPackager.command when called from runAndroid.js.

react-native run-android will thus silently fail to start the developement server ('JS server').

What existing problem does the pull request solve?

When running "react-native run-android" on the below reasonably vanilla Ubuntu system, the development server / packager script fails to start. It fails because sh defaults to dash (not bash) which doesn't know the command 'source'. dot (.) does the same as source, but works in all shells.

$ uname -a
Linux dallas 4.8.0-52-generic #55~16.04.1-Ubuntu SMP Fri Apr 28 14:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

$ which sh
/bin/sh

$ readlink -f /bin/sh
/bin/dash

react-native-cli: 2.0.1
react-native: 0.44.0

$ ps aux | grep packager
(nothing)

ps aux | grep packager
sh /home/xxx/code/react-native/AwesomeProject/node_modules/react-native/packager/launchPackager.command
node /home/xxx/code/react-native/AwesomeProject/node_modules/react-native/packager/../local-cli/cli.js start
Closes https://github.com/facebook/react-native/pull/14040

Differential Revision: D5096298

Pulled By: hramos

fbshipit-source-id: 88466e802c9bc4358840391edb37e153f0a6b1f7
2017-05-19 14:51:27 -07:00
David Aurelio 1c77e4a79f Change `sourceMappingURL` to line comment
Summary: Changes the `sourceMappingURL` comment from multi line to single line.

Reviewed By: johnislarry

Differential Revision: D5094791

fbshipit-source-id: f8fa2efd7f173290cac985564c06b4a118a80aae
2017-05-19 13:51:22 -07:00
David Aurelio 62f7f7607e Separate build modules from require calls when bundling
Summary: separates modules of the dependency graph from the generated require calls to kick of the app. This is required to make RAM bundle generation work properly'

Reviewed By: jeanlauliac

Differential Revision: D5094635

fbshipit-source-id: fca69a3e2d9b030cdc4d4405c2b5e795b0d55f87
2017-05-19 07:56:24 -07:00
David Aurelio 7cafb53b7b Add `"node"` env to packager `.eslintrc`
Reviewed By: cpojer

Differential Revision: D5094630

fbshipit-source-id: 6ecb97da78d6cd5b7f61d1b2073d31309ded0932
2017-05-19 07:36:26 -07:00
Jean Lauliac 2b4d417488 packager: ResolutionRequest: factor error handling in resolution
Reviewed By: davidaurelio

Differential Revision: D5086995

fbshipit-source-id: a377c86b64c3ae458a12937d9302ac0cf69854d4
2017-05-19 04:50:24 -07:00
David Aurelio 516367f971 require.js: Delete dependency map after factory ran
Summary: Releases the dependency map of modules after running the factory in release mode in order to save memory.

Reviewed By: cpojer

Differential Revision: D5086693

fbshipit-source-id: 68c57a2f98182ed1a732e1336e6d4fe5ce27abc3
2017-05-19 03:37:24 -07:00
David Aurelio b1eb0bbee5 Call minification post-processing hook
Summary: RN configuration allows to specify a post-minify hook. This wasn’t called in the new Buck integration so far. Added here.

Reviewed By: cpojer

Differential Revision: D5087325

fbshipit-source-id: 74b58bd3a203716d8f01b5d7ba552b6ad1b575ce
2017-05-19 03:08:36 -07:00
Gabe Levi a3237f641e Fix react-native function call arity errors
Reviewed By: zertosh

Differential Revision: D5081816

fbshipit-source-id: 5978770c30a69fb287d03aa7511999ce30f856a1
2017-05-18 16:56:35 -07:00
Jean Lauliac 5bdaf4697d packager: do not use slashes in key
Summary: Internally we use `multipart/form-data` to upload transformed files to the global cache, using the keys as file names. Unfortunately the server would read that and consider only the basename as the key, not the full path. So we wouldn't store the data under the right key. This is definitely a bug in the way upload is implemented: we should transmit the keys separately. But, this changeset offers a quick mitigation by avoiding slashes in the key, so that the whole key is a valid base file name.

Reviewed By: davidaurelio

Differential Revision: D5087780

fbshipit-source-id: 9e4a698c1f57c4c3b91b56b43eef82c1c7dd862b
2017-05-18 11:51:52 -07:00
Jean Lauliac 79ff67320f packager: HMRBundle: @flow
Summary: Better to have *some* Flow coverage (I'd like 100% of packager covered from when we split it apart) than none.

Reviewed By: davidaurelio

Differential Revision: D5077757

fbshipit-source-id: b23169b3edf2bd3eb0e8a399d099151aa705b198
2017-05-17 09:29:25 -07:00
Jean Lauliac c3430956df packager: MapWithDefaults: @flow
Summary:
It was hard to type the resolution main algo, I had to put type annotations explicitely everywhere, otherwise Flow would get in some kind of loop and do weird errors. I think it's because the algo is recursive and Flow tries to infer types too deeply because of the generics.

Anyway, apart from that it's good to get this extra type security in the few other places. We require Node v4 minimum, that according to the internets supports the `class` syntax without transform, and I verified that inheriting from `Map` actually works as expected.

Reviewed By: davidaurelio

Differential Revision: D5078023

fbshipit-source-id: 05dfc4acf5b07cdda8a7b36ec9cba216d1810643
2017-05-17 09:29:23 -07:00
David Aurelio 9ffddb1b32 Output `.meta` files for plain bundles
Summary: Outputs `.meta` files for plain text bundles just like “old packager” did.

Reviewed By: jeanlauliac, cpojer

Differential Revision: D5077649

fbshipit-source-id: eb87999dd899066adeb9756333adb4d79ce04832
2017-05-17 07:25:19 -07:00
Jean Lauliac b512cf62af packager: AssetResolutionCache: tests + fix bug
Summary: Or, a case in point that Flow doesn't saves us from all the ills. I think it didn't complain because `MapWithDefaults` doesn't have proper typing. I'll deal with that separately.

Reviewed By: davidaurelio

Differential Revision: D5077707

fbshipit-source-id: c43623c5046d2dea9964685a44ad4877d060232e
2017-05-17 05:21:15 -07:00
Jean Lauliac 6f61f74e4e packager: server.js: @flow
Summary: I'd like to start typing the front-end so that it's easier to track adding new options, etc.

Reviewed By: davidaurelio

Differential Revision: D5069868

fbshipit-source-id: 9a18dca52efd486ca18f17d0ec434a5ec1c1649c
2017-05-17 05:08:20 -07:00
Jean Lauliac 218cab5e88 packager: runServer: @flow
Summary: This makes it easier to verify correctness when adding new config/args.

Reviewed By: davidaurelio

Differential Revision: D5069537

fbshipit-source-id: 4d8058851900b23163d0f2744e91dd14dfcdd461
2017-05-17 05:08:20 -07:00
Jean Lauliac 2482fa8956 packager: ResolutionRequest: unify asset resolution
Summary:
The existing resolution logic of assets:

* goes over all the files of the asset's directory for every resolution request;
* duplicates the parsing logic of `AssetPaths` by building up a custom regex for each resolution request.

This changeset proposes to tweak this by building an index for each particular directory in which we're looking for assets, so that we don't have to crawl a single directory twice, and so that it reuses the logic of `AssetPaths.tryParse()` for determining variants.

Reviewed By: davidaurelio

Differential Revision: D5062435

fbshipit-source-id: 708fc5612f57b14565499fad741701269438c806
2017-05-16 09:05:58 -07:00
David Aurelio cb6bace9c6 Append `sourceMappingURL` in bundle building function
Summary:
We appended a `sourceMappingURL` in the same place where we write out the files. This will break output that is not a plain text file, like Random Access Bundles.
This moves the corresponding logic into the function that builds the bundle.

Reviewed By: cpojer

Differential Revision: D5061039

fbshipit-source-id: 17fadb5a687c8d4b1f29439e8bf946bae58eb2d9
2017-05-16 05:26:40 -07:00
Jean Lauliac c5dfa2dbd5 packager: TransformCache: trivial optimization wins
Reviewed By: davidaurelio

Differential Revision: D5068811

fbshipit-source-id: 74e4c3218581b2cb081cb7da7639356d0a7d0430
2017-05-16 05:08:54 -07:00
Jean Lauliac ab81cb02f1 packager: simplify getAssetDataFromName?
Summary:
Not only is this function is building a custom Regex for every single file, but it's also duplicating some of the work of the inner function, that is already splitting up the platform/extension. This changeset refactors both function to have a more strict and legible logic to extract asset information. We extract the base name first, then we extract the resolution from it, instead of rematching platform and extension.

I stumbled on this while looking into refactoring the asset resolution logic of `ResolutionRequest#_loadAsAssetFile()`. The next step would be to reuse the exact same function for resolving assets instead of using a custom regex there as well.

Reviewed By: davidaurelio

Differential Revision: D5060589

fbshipit-source-id: b48d9a5d8e963be76cad5384c6bfb3e214a73587
2017-05-15 06:53:07 -07:00
David Aurelio 1c2ef1833f Make `postMinifyProcess` non-optional
Reviewed By: cpojer

Differential Revision: D5052315

fbshipit-source-id: 4c3573fc6e97b4f561f371179ea2dd6f89fac05a
2017-05-12 11:37:45 -07:00
Jean Lauliac a948fdb31b packager: HasteMap: @flow + fixes
Summary: Add Flow types, revealing a few problems, such as `isHaste` having the wrong return value in the "pseudo-mocks". But since the buck worker is in fact working, I guess these functions were never called... The point of typing this file is that I'm going to start aggressively pruning dead code in `node-haste` and hopefully, eventually, get rid of `Moduleish` and `Packageish`.

Reviewed By: davidaurelio

Differential Revision: D5052379

fbshipit-source-id: dab3f18f05fcf43fbbc48b589170b1cf367d6a48
2017-05-12 10:39:32 -07:00
Jean Lauliac 6e5730601a packager: remove replacePatterns module
Summary: This does not appear to be used anywhere anymore.

Reviewed By: cpojer

Differential Revision: D5052224

fbshipit-source-id: 142fdcdf48f4ad16a04bb747b41d623f214f7a68
2017-05-12 10:39:32 -07:00
Jean Lauliac 2068e661a5 packager: getInverseDependencies: @flow
Reviewed By: davidaurelio

Differential Revision: D5052190

fbshipit-source-id: ebfa2a698233e914b016fe50f790ee8aa758c4f2
2017-05-12 10:39:31 -07:00
Jean Lauliac 02d57294fe packager: DependencyGraph: remove re-exported functions
Reviewed By: davidaurelio, cpojer

Differential Revision: D5052149

fbshipit-source-id: 43f3877ceea038762ded6c42ab0481d215db2118
2017-05-12 10:39:31 -07:00