Commit Graph

1115 Commits

Author SHA1 Message Date
Jean Lauliac 0eeafae9be 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:30:51 -07:00
Jean Lauliac e6bc8ea10a 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:30:51 -07:00
David Aurelio cce99f44fd 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:32:40 -07:00
Jean Lauliac 44955dfa17 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:15:48 -07:00
Jean Lauliac c0e8d67e01 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:03:41 -07:00
Jean Lauliac b98c33f1b4 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:03:41 -07:00
Jean Lauliac 98fc4373fc 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:19:36 -07:00
David Aurelio 280ec6e1eb 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:16:28 -07:00
Jean Lauliac 40a53918ec packager: TransformCache: trivial optimization wins
Reviewed By: davidaurelio

Differential Revision: D5068811

fbshipit-source-id: 74e4c3218581b2cb081cb7da7639356d0a7d0430
2017-05-16 05:16:28 -07:00
Jean Lauliac 2f5524d04e 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:48:03 -07:00
David Aurelio dc783d97e8 Make `postMinifyProcess` non-optional
Reviewed By: cpojer

Differential Revision: D5052315

fbshipit-source-id: 4c3573fc6e97b4f561f371179ea2dd6f89fac05a
2017-05-12 11:45:37 -07:00
Jean Lauliac 4ae8e5e21a 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:37:03 -07:00
Jean Lauliac ffe18867f2 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:37:03 -07:00
Jean Lauliac 174f84cc8a packager: getInverseDependencies: @flow
Reviewed By: davidaurelio

Differential Revision: D5052190

fbshipit-source-id: ebfa2a698233e914b016fe50f790ee8aa758c4f2
2017-05-12 10:37:03 -07:00
Jean Lauliac d0c2b068d7 packager: DependencyGraph: remove re-exported functions
Reviewed By: davidaurelio, cpojer

Differential Revision: D5052149

fbshipit-source-id: 43f3877ceea038762ded6c42ab0481d215db2118
2017-05-12 10:37:03 -07:00
Jean Lauliac 2b5b729bbb packager: remove getPlatformExtension default platforms
Summary: Default arguments are dangerous, and it shows here again. `Server` was calling that function without passing down the platforms, meaning custom platform would not be accounted for, possibly causing all kinds of bugs for OSS use cases. Additional, the typing of `platform` across the stack was wrong: it can be `null`, in which case we resolve the files without extension. The reason Flow didn't detect that issue before is because we use `Object.assign` to re-export the function from `DependencyGraph`, but Flow is not smart enough to propagate the types in that particular case. I'll remove all the other re-export, as it may uncover further type errors.

Reviewed By: davidaurelio

Differential Revision: D5052070

fbshipit-source-id: 7b427ec036ca74b5dcd7c88f7dfa0df541b8eb6b
2017-05-12 10:37:03 -07:00
David Aurelio e1306565db Use `this` rather than `global` in prelude
Summary: in new-style builds, the prelude is not wrapped into an IIFE, so `global` is not available. Since the bundle as a whole is not running in strict mode, we can access the global object with `this`.

Reviewed By: jeanlauliac

Differential Revision: D5051731

fbshipit-source-id: 4003b5e57ba8626e38e68e92d5778c2c59ca69a5
2017-05-12 09:46:04 -07:00
Dominic Gannaway 56e44a7fdd Change packager project root path so RNTester can start
Summary:
A quick fix to ensure RNTest works. This PR changes the process root for where packager is run, resulting in the right `cwd` directory path when RN launches RNTester.
Closes https://github.com/facebook/react-native/pull/13947

Differential Revision: D5052093

Pulled By: davidaurelio

fbshipit-source-id: 506a8cd63f1709c948bcc4586467020d380ba85e
2017-05-12 09:02:41 -07:00
Jean Lauliac afe19d8ac5 packager: never allow platform-specific asset resolution
Summary: I stumbled on this while refactoring that function, and i realised that, I believe it doesn't make sense to take into account the platform extension of the "potiential" file path. The reason is, if you try to require "foo.ios.png", the returned asset name would be "foo", and thus we'd try to find "foo.${ext}.png" where `ext` could actually be `android` or anything else! So it's confusing. There's no reason we should allow callsites to specify platform anyway I think. With this changeset we're not losing any functionality, but it might require people to fix some incorrect callsites.

Reviewed By: cpojer

Differential Revision: D5051791

fbshipit-source-id: 2a1ec7a8bfa6791b6016213305a72bc0b81f23b9
2017-05-12 07:39:10 -07:00
Jean Lauliac 3bf3c83a5b packager: add transform-class-properties transform
Summary: I found myself a few times wanting that transform, that makes it slightly simpler to have bound method. So I propose we add it. Not a big deal though. Note it also allows static properties with the same syntax, that is handy.

Reviewed By: davidaurelio

Differential Revision: D5051579

fbshipit-source-id: 7ebf7c709bf52a30a525550c1eda1a6a2f7b8e1e
2017-05-12 07:39:10 -07:00
David Aurelio 2fbe3b799e Pass local paths to transformers
Summary:
Pass `localPath` to transformers to allow usage of plugins like `transform-react-jsx-source` that don’t conflict with x-machine caches, e.g. Buck or our own global cache.
These caches don’t work properly if paths local to a specific machine are part of cached outputs.

Reviewed By: jeanlauliac

Differential Revision: D5044147

fbshipit-source-id: 1177afb48d6dd9351738fcd4da8f9f6357e25e81
2017-05-11 16:47:43 -07:00
David Aurelio 143beaf95d Use local paths for global cache
Summary:
Changes the global cache to use *local paths* rather than base names of files for the cache key. This is to enable correct usage of babel transforms like `transform-react-jsx-source` that use file paths in their output.

It remains a responsibility of the transform implementer to pass relative paths to babel if the global cache is being used.

Reviewed By: jeanlauliac

Differential Revision: D5044028

fbshipit-source-id: 2ef1e1545e510a18ab49a307053d91b4f40269b2
2017-05-11 16:47:43 -07:00
David Aurelio ee8e721c33 Add glossary, some renames
Reviewed By: jeanlauliac

Differential Revision: D5043919

fbshipit-source-id: ba6f47102747c0762a153cd860f8f61f090cf5d7
2017-05-11 16:47:43 -07:00
David Aurelio c44e37bf74 Require transformer options to be present throughout
Summary: `transformModulePath` used to be an optional string, because `ConfigT` allowed for an optional `getTransformModulePath` method. Effectively, we required it to be present. This builds on top of the cleanups around `ConfigT` and gets rid of the flow error suppressions

Reviewed By: jeanlauliac

Differential Revision: D5037466

fbshipit-source-id: bc5c9cbc566e7aa74e7f6397e69fa87cdac7bc00
2017-05-11 16:47:43 -07:00
David Aurelio 58337c9032 BREAKING: Pass parameters to `transformer.transform` as object
Reviewed By: jeanlauliac

Differential Revision: D5037155

fbshipit-source-id: fbd18bd62254d7e1522f659ea62055e66748a951
2017-05-11 08:35:07 -07:00
Sebastian McKenzie c15a6b6202 Use absolute locations for plugins and presets in packager babel config
Reviewed By: davidaurelio

Differential Revision: D5044244

fbshipit-source-id: ab1af28d0158c22d0426a7a3b3f1bb0a63abac4e
2017-05-11 06:51:52 -07:00
Jean Lauliac c286da0195 packager: ResolutionRequest: keep track of tentative resolution paths
Summary: That's a bit of an experimental changeset, I wanted to experiment how we can track with more precision the resolution and this is what I come with. That allows us to know what has been tested if we canot find a match. It also uses a simpler control flow with early `return`s all across. Finally, this reflect the strategy I want to apply for the rest of the resolution. (Right now the error is still not great, as it may be deeply nested, as in the case of packages resolution.)

Reviewed By: davidaurelio

Differential Revision: D5044040

fbshipit-source-id: 2e256174506f80d90ee83175057666d530785788
2017-05-11 06:35:36 -07:00
Jean Lauliac e379b84545 packager: Module: tweak isHaste return type
Reviewed By: cpojer

Differential Revision: D5036181

fbshipit-source-id: 6042beb44bc67e64dd57c8dd6043f8dd690e9382
2017-05-11 05:04:05 -07:00
Jean Lauliac 3e46c051d3 packager: ResolutionRequest: @format
Summary: Add `prettier` before I continue some refactorings.

Reviewed By: davidaurelio

Differential Revision: D5036276

fbshipit-source-id: 590e1b23864f28c51d337204df3281dd8bd311cd
2017-05-11 03:50:52 -07:00
Jean Lauliac 8f6d040c23 packager: trying out @format
Summary: Internally when adding `format` we have a lint rule that automatically reformat using `prettier` and the project rule. I'm concerned how we can ensure this stays consistent when merging PRs though. It's not a big issue because the volume of PRs is low, but we'll have to figure it out later on.

Reviewed By: davidaurelio

Differential Revision: D5035830

fbshipit-source-id: 6f2bc9eb8212938ff785a34d2684efd1a9813e1a
2017-05-10 06:03:06 -07:00
Jean Lauliac 9b06205f82 packager: remove unused declareOpts module
Summary: That module is not used anymore, remove it and its dependency `joi`.

Reviewed By: cpojer

Differential Revision: D5028909

fbshipit-source-id: 90b9b156fbfe642cce93a530faf8ce91c5b848f5
2017-05-10 05:31:31 -07:00
David Aurelio f1a220b3cf Fixes issues with uglify.js usage
Summary: Adds flow type defs for uglify, and fixes the two issues found

Reviewed By: jeanlauliac

Differential Revision: D5029190

fbshipit-source-id: eb5947b051844938da241e002b727edc1384e3a6
2017-05-10 05:16:06 -07:00
Jean Lauliac eb19904cec packager: ResolutionRequest: check dir existence only on error
Reviewed By: davidaurelio

Differential Revision: D5028476

fbshipit-source-id: 848d7f6a7b6ab046a5e489a56dc224f3296cea02
2017-05-10 05:16:06 -07:00
Jean Lauliac c0babb2731 packager: make TransformCache a stateful class
Summary: This removes the single-use "garbage collection" class and make a single `TransformCache` instead. The reason for doing this is that I'd like to experiment with using a local dir based on the root path instead of the `tmpdir()` folder, because on some platform using the temp dir is subject to permissions problem, sometimes it is empty, and on all platform it is vulnerable to concurrency issues.

Reviewed By: davidaurelio

Differential Revision: D5027591

fbshipit-source-id: e1176e0e88111116256f7b2b173a0b36837a887d
2017-05-10 04:45:44 -07:00
Jean Lauliac 0216e87616 packager: ResolutionRequest: skip dirExists in loadAsDir
Summary: I'm continuing my changes to avoid `lstat`-ing the folders when we don't really need to. That changeset in particular proposes to remove the check in `_loadAsDir`. The rationale is that right after that we try for the presence of the `package.json`. If that file exists, the folder necessarily exist so we can switch these two `if` blocks for sure without changing the logic. Finally, at the end we look for the "index" file. By removing the folder check, packager would now report "file `foo/index` does not exist" rather than "directory `foo` does not exist" if the folder does not exist. I think it's not much worse, especially as both of these are unhelpful for what I believe to be a large number of cases already anyway. Indeed, the whole algo is based on a series of try/catch, and only the very last try will see its error surfaced. But, most often, it'd be useful for earlier tries to be surfaced to the user. I do want to improve that; meanwhile, however, I sense it's not a big deal to remove that folder check for all these reasons. If you don't agree, I do have another proposition: we could catch errors generated by the last `_loadAsFile` call, and rethrow them as directory errors instead (if `dirExists` return `true`). That way, the call to `dirExists` would only happen in case of errors (but that could still happen quite a lot as a result).

Reviewed By: davidaurelio

Differential Revision: D5028341

fbshipit-source-id: 2d4c99c0f352b71599482aa529728559466b76fd
2017-05-10 04:45:44 -07:00
Jean Lauliac 76f74a55c2 packager: ResolutionRequest: simplify asset resolution
Summary: I think we don't really need to check the directory beforehand, the function to find asset will just return an empty array. As for the error message, I tried adding a require of an asset file somewhere, but due to the way the ResolutionRequest algo work, it generates a final error message that unrealted ("Directory ... does not exist", instead of the "asset does not exist"). I plan to revamp the way errors are handled such as the error message clearly identifies what file paths have been inspected.

Reviewed By: davidaurelio

Differential Revision: D5028118

fbshipit-source-id: 496472001c0a3d4192bfef4a0c8a0dc8a9a0fa82
2017-05-10 04:45:44 -07:00
Jean Lauliac cb3b744d08 packager: remove unused imurmurhash
Summary: This is not used by live code anymore.

Reviewed By: cpojer

Differential Revision: D5029114

fbshipit-source-id: 9ab9f6075407623debfe23bc121cc48ae8903917
2017-05-10 03:48:32 -07:00
Jean Lauliac c948ae8168 packager: rename node-haste/index to DependencyGraph
Summary: I've been confused for a long time by this, and I think it's better late than never. I propose we rename that file to make it more explicit where that class lives, and so that it's consistent with the test file, name `DependencyGraph-test.js`

Reviewed By: davidaurelio

Differential Revision: D5020556

fbshipit-source-id: d54a501c3995f3fea16a5bfc6ca72993f73c4873
2017-05-10 03:48:32 -07:00
David Aurelio 8533c0d816 Custom build options: Move transform options into own property
Summary: Moves custom transform options into their own property when returning custom properties. This helps both transitioning to a `select` function as well as implementing RAM bundle support for the new buck integration

Reviewed By: jeanlauliac

Differential Revision: D5028075

fbshipit-source-id: 25fe3072023cc063deef537a12012d4bb3173579
2017-05-09 13:45:46 -07:00
David Aurelio 73fc439bc0 Stronger typing for transformers
Reviewed By: jeanlauliac

Differential Revision: D5006679

fbshipit-source-id: 795c60db363fb53bc74697e4befe50995e9b97a7
2017-05-09 08:02:36 -07:00
Jean Lauliac fbe6d9321e packager: worker-farm: isolate stdout/stderr
Reviewed By: davidaurelio

Differential Revision: D5011034

fbshipit-source-id: 81d3d49156775f9781427d3c103d768ccc30fe20
2017-05-08 11:31:20 -07:00
Jean Lauliac 7d6fec0a39 packager: optimize assets' JS
Reviewed By: davidaurelio

Differential Revision: D5010186

fbshipit-source-id: 3c26d8b8792df1dbc24e5200f28f63e017cb0173
2017-05-08 11:31:20 -07:00
Jean Lauliac 2a5959ae6e packager: buck assets: wrap in __d
Reviewed By: davidaurelio

Differential Revision: D5003464

fbshipit-source-id: 59800dded389d133394b60530eb97642d67a5c89
2017-05-08 11:31:20 -07:00
Jean Lauliac e69b81313f packager: ModuleGraph: include all possible asset types
Summary: Afaik. the list of asset types is hardcoded for the Buck worker so far, and I'm not sure how that would be customizable. For now, let's include all the default asset extensions.

Reviewed By: davidaurelio

Differential Revision: D5002607

fbshipit-source-id: 41069e817d2b73156bca684bc2f73077132928a7
2017-05-08 11:31:20 -07:00
Janic Duplessis 074fd33725 Packager - Fix symbolicate on windows
Summary:
There was an error with packager symbolization on Windows because it looks like `allowHalfOpen: true` doesn't work properly when using named sockets. This uses a random port on localhost for the connection instead on Windows as a workaround.

**Test plan**
Tested that symbolization works on both mac and windows by triggering a warning in UIExplorer.
Closes https://github.com/facebook/react-native/pull/13828

Differential Revision: D5019537

Pulled By: davidaurelio

fbshipit-source-id: 62c5b5f270e553a7d413bb4d1bab2406380f1d4f
2017-05-08 11:31:20 -07:00
Kevin Old 7932b93fef Properly handle babel ignored files, returning only the contents
Summary:
- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.

I have a need to bundle a pre-optimized external lib with my RN application. Until RN 0.42 I had been using a .babelignore to prevent the packager from trying to optimize this file and choke.

It seems in 0.42 and higher I'm no longer allowed to ignore the file.

This issue has also been reported as #12071

Details on the reasoning for this patch can be found in the issue I originally filed: https://github.com/facebook/react-native/issues/13168

What existing problem does the pull request solve?

This PR restores the functionality with babel ignoring files that existed in 0.41 before this patch:

0849f84df2 (diff-4676ea0b3c55c65c3929aa993144f07f)

Here's a screenshot of this patch properly ignoring the file I referenced in https://github.com/facebook/react-native/issues/13168 to be ignored.

![screen shot 2017-04-27 at 12 48 32 am](https://cloud.githubusercontent.com/assets/21967/25469653/524dbc0c-2ae3-11e7-81a6-faca2f4d21fe.png)

The patch relies on the `ignored` value of the call to `babel.transform` and if true returns the src in a object per instruction from loganfsmyth from BabelJS core team.

To test, add a file to the `ignore` array of a `.babelrc` file in a React Native project with this fork.

I was unable to locate a test file for the transformer.js

Fixes #12071, #13168
Closes https://github.com/facebook/react-native/pull/13681

Differential Revision: D5017565

Pulled By: davidaurelio

fbshipit-source-id: 421f57b5ce192eedd46fae4285d8a741cb5f8e71
2017-05-08 11:31:19 -07:00
Jean Lauliac bc4de008d3 worker-farm: pass explicit execArgv to workers
Reviewed By: davidaurelio

Differential Revision: D5002197

fbshipit-source-id: 8f556626321963c103d38ec9865110a39f1a5109
2017-05-04 10:20:19 -07:00
Jean Lauliac 2de6e546bd worker-farm/lib/fork.js: cleanup
Reviewed By: davidaurelio

Differential Revision: D5002190

fbshipit-source-id: 07230f3e4fb059430124f44a82a928921904ed7b
2017-05-04 10:20:19 -07:00
Jean Lauliac 76d6f904b1 packager: faster terminal feedback
Summary: Well that's silly but I noticed with faster terminal progress updates, packager *feels* a bit faster :D

Reviewed By: davidaurelio

Differential Revision: D5002528

fbshipit-source-id: 8a3d5e929dd7fb09ebafda3422886c631016a40f
2017-05-04 09:20:55 -07:00
David Aurelio 1a0e78c4e4 Fix release / minified bundle builds
Summary: Fixes building release builds with the new buck integration.

Reviewed By: jeanlauliac

Differential Revision: D5002441

fbshipit-source-id: e7716324c7c8dd0bfcaf5b39cf716ac589e948e8
2017-05-04 08:31:10 -07:00