Commit Graph

676 Commits

Author SHA1 Message Date
David Aurelio 9d80ce2898 Use `version` from `packager/package.json` for cache key
Reviewed By: jeanlauliac

Differential Revision: D4380910

fbshipit-source-id: 25d980bdf46046c3d53a4b2e120fd86a5534af6a
2017-01-04 06:58:35 -08:00
Jean Lauliac 9676468f78 packager: enable @flow in node-haste types.js
Reviewed By: cpojer

Differential Revision: D4377132

fbshipit-source-id: 5a1c0fb34c85974135c326065fd0c54f44282286
2017-01-04 05:28:42 -08:00
Jean Lauliac 754e7015d9 packager: AssetModule: @flow
Reviewed By: cpojer

Differential Revision: D4377137

fbshipit-source-id: 991619c0a42319a3bb4bf28dab4dd0fe1a474def
2017-01-03 09:58:35 -08:00
Jhen 033e7a0d6f Fix the `path.sep` replacement of node-haste for Windows
Summary:
Fix the `path.sep` replacement for Windows, currently it just replace one segment:

```js
// Result: './lib/random\random-byte.js'
'./lib\\random\\random-byte.js'.replace(path.sep, '/')
```

Change to regex will work fine:

```js
// Result: './lib/random/random-byte.js' (correct)
'./lib\\random\\random-byte.js'.replace(new RegExp('\\' + path.sep, 'g'), '/')
```
Closes https://github.com/facebook/react-native/pull/11641

Differential Revision: D4368402

fbshipit-source-id: 46f456359d1cd2ca790881773e8a76af8616cd21
2016-12-27 14:43:32 -08:00
Chris Hopman 8e9549fb2b make the RN packager output more deterministic
Reviewed By: davidaurelio

Differential Revision: D4357109

fbshipit-source-id: bc9ef04d81223299fe7708aeb0fe654647330ab7
2016-12-22 15:58:30 -08:00
Jean Lauliac b5dae70e61 packager: TerminalReporter: properly reporting bundle updates
Reviewed By: cpojer

Differential Revision: D4357298

fbshipit-source-id: 89c70bb4bee103ad5a6301ac2b0c8712f190ba73
2016-12-21 05:58:32 -08:00
Jean Lauliac 3c3e3b8529 packager: TerminalReporter: remove underline/emoji
Reviewed By: cpojer

Differential Revision: D4357225

fbshipit-source-id: 05d6b4fd9b79616a68e5fa3c4700aeac2f3552a9
2016-12-21 05:58:32 -08:00
Jean Lauliac 4c98641537 packager: Fix typing of more Resolver options
Reviewed By: davidaurelio

Differential Revision: D4351879

fbshipit-source-id: aab3eb031ae3137d43d88ad1853aa7e6f5d165c5
2016-12-21 03:43:36 -08:00
Jean Lauliac 23261a6745 packager: Fix typing of Resolver options
Summary:
`declareOpts` is weakly typed. Since the callsite of Resolver constructor is itself flowifyed, we can get rid of `declareOpts`, and this provides us with much better typing.

Eventually I'd like to get rid of most of the defaults in the packager's inner code (ex. `watch` being false, `dev` being true). The reason is that defaults everywhere are prone to causing inconsistencies (for ex. some other code could have `dev` as false by default), problems that cannot be caught by Flow. Instead of having non-required options, I believe it is more sensible to provide helper functions that build sets of default options.

Reviewed By: davidaurelio, cpojer

Differential Revision: D4351874

fbshipit-source-id: 38653063f8939b4282c7c27cb6d5e3f3a25a9484
2016-12-21 03:43:36 -08:00
Connor McEwen 771606fc12 Fix babelHelpers.typeof is not a function
Summary:
We started encountering the error described in #5747 (`babelHelpers.typeof is not a function) after switching from npm to yarn. [This comment](https://github.com/facebook/react-native/issues/5747#issuecomment-192356656) led to [this comment](https://github.com/facebook/react-native/issues/4844#issuecomment-191282653) which contains a solution we've been using successfully in our production app.

Maybe I didn't look in the right place but it doesn't seem anyone had actually PR'd this change before (if so and I didn't find it, I apologize).

An alternative solution it seems is to add a [different .babelrc](http://stackoverflow.com/questions/35563025/new-react-native-app-has-typeerror-babelhelpers-typeof-is-not-a-function-ios), but this seems easier to me.
Closes https://github.com/facebook/react-native/pull/11093

Differential Revision: D4353977

fbshipit-source-id: 3e45de29ef5d0e046219a32df6530dcf838b9fd9
2016-12-20 15:28:29 -08:00
Jean Lauliac 79e12e59bd packager: Module: remove too-many-misses codepath
Summary:
This code is a bit sloppy, I need to rethink about it. So I prefer to remove it altogether for now.
The problem with this is that it is disabling the global cache "put" operations at the same time, so the script supposed to update the cache actually doesn't do the job past the fist few hundred files. This defeats the purpose of the global cache.

Reviewed By: cpojer

Differential Revision: D4346927

fbshipit-source-id: 5b668e66b1909f53783772c613781753ac605546
2016-12-20 03:13:32 -08:00
Jean Lauliac 379daeb0d1 packager: make output simpler, more legible
Reviewed By: cpojer

Differential Revision: D4339417

fbshipit-source-id: f174ee11bc220de5e8da1d8227e9a9ceb5319e8d
2016-12-19 10:58:32 -08:00
David Aurelio 0410c6f714 Improve source map quality when inserting numeric module IDs
Summary:
This changes the way that module identifiers are replaced with numeric ids so that ids are padded with spaces on the right to take up the same space as the original string literal.
By doing this, we keep the mappings for the generated source line intact.

```
// original source
const React = require('react');
// old replacement
const React = require(12 /* react */);
// new replacement
const React = require(12     ); // 12 = react
```

The remaining edge case are module names that are replaced with numeric IDs that are longer than the replaced string, e.g.:

```
const Q = require('q');
const Q = require(1234);
```

Reviewed By: cpojer

Differential Revision: D4346092

fbshipit-source-id: ef3bb879495f388c4a7448a2f810b83c204e8984
2016-12-19 06:13:29 -08:00
Cristian Carlesso 2668ad7ace Update RN to Jest 18
Reviewed By: cpojer

Differential Revision: D4335580

fbshipit-source-id: c48b6882b89aa20f9f58783b5a17edf94df22223
2016-12-19 04:43:30 -08:00
Alan Norbauer d398030b69 Replace jest.resetModuleRegistry() with jest.resetModules()
Reviewed By: cpojer

Differential Revision: D4344961

fbshipit-source-id: 45453ec7ee3211743946ab9156f51430322b5832
2016-12-18 17:13:38 -08:00
David Aurelio c486c707de Add `deps` param to `js_library`
Reviewed By: cpojer

Differential Revision: D4334383

fbshipit-source-id: 96f0d6ba5ed8ddab25087edd6381a6e6449ff63a
2016-12-16 11:13:35 -08:00
Adam Miskiewicz 330bff1323 Resolve single flow error in node-haste
Summary:
Makes flow pass.
Closes https://github.com/facebook/react-native/pull/11465

Differential Revision: D4328094

Pulled By: ericvicenti

fbshipit-source-id: 5eb60831145ade00eb2d504f4958f0a683eef686
2016-12-15 00:28:31 -08:00
Jean Lauliac 9340ae44fb packager: slightly more complete progress message.
Reviewed By: cpojer

Differential Revision: D4326391

fbshipit-source-id: 134e09f1db6e21165c4af78a9e1266d7f9d046c8
2016-12-14 10:13:29 -08:00
Jean Lauliac efabd49cb3 packager: don't keep on using global cache forever if it misses
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
2016-12-14 08:28:42 -08:00
Jean Lauliac 9919940807 packager: Terminal abstraction to manage TTYs
Reviewed By: cpojer

Differential Revision: D4293146

fbshipit-source-id: 66e943b026197d293b5a518b4f97a0bced8d11bb
2016-12-14 05:14:06 -08:00
Jeff Morrison 4130afcf19 fbsource
Reviewed By: samwgoldman

Differential Revision: D4314897

fbshipit-source-id: fbe11da4c63bf34d010220d74177cb3ca4cbee6d
2016-12-13 18:58:34 -08:00
Christoph Pojer c383638e5e Remove `pit` and `mockImpl`
Reviewed By: dmitriiabramov

Differential Revision: D4321635

fbshipit-source-id: 460889a1f956f3733e7e49883dd97c9a8a561b86
2016-12-13 15:13:39 -08:00
David Aurelio 5da19878c4 install `node_modules` into `buck-out`
Reviewed By: cpojer

Differential Revision: D4312220

fbshipit-source-id: 1449a194c557071bb5f0be6bc00dccef26c62b47
2016-12-13 09:13:39 -08:00
David Aurelio 4843500e9e Add `bundle` command
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
2016-12-13 07:28:31 -08:00
Jean Lauliac d556e5824a packager: Resolver&co: @flow
Reviewed By: davidaurelio

Differential Revision: D4285448

fbshipit-source-id: ec9bc6fd3c6d6eae89347762bff8b5b24662394b
2016-12-08 05:13:40 -08:00
David Aurelio 2ce1f0cf79 Add fbjs definitions to flow config
Reviewed By: zertosh

Differential Revision: D4291805

fbshipit-source-id: 3dcb8ffe6132bd04a3048edae64e9d273c2dcae4
2016-12-08 02:43:25 -08:00
David Aurelio 548733e7e0 Use absolute paths from repo root
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
2016-12-06 16:58:33 -08:00
David Aurelio c00e669cf5 Add bundle building logic
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
2016-12-05 16:43:45 -08:00
David Aurelio a3b6ed81ed Support relative paths in haste map
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
2016-12-05 16:43:45 -08:00
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
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
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