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:
This is the next incremental step to rewrite node-haste. I apologize for the size of this diff but there is really no smaller way to do this. The current architecture passes a single file watcher instance into many classes that each subscribe to file changes. It's really hard to keep track of this. The new implementation reduces the listeners to two (will eventually be just one!) - one in DependencyGraph and one in it's parent's parent's parent (ugh! This doesn't make any sense). This should make it much more straightforward to understand what happens when a file changes.
I was able to remove a bunch of tests because jest's watcher takes care of things like ignore patterns. Some of the tests were specifically testing for whether the change events were invoked and they are now much more straightforward as well by manually invoking the `processFileChange` methods.
(Relanding a fixed version of D4161662)
Reviewed By: kentaromiura
Differential Revision: D4194378
fbshipit-source-id: 8c008247a911573f6b5f6b0b374d50d38f62a4f5
Summary: I originally added fastpath to node-haste to speed up `path` operations by an order of magnitude. Now we are exclusively using Node 6 at FB so we don't need to ship this thing any more.
Reviewed By: bestander
Differential Revision: D4029092
fbshipit-source-id: 064cf67f4f79ce4f2774fb4e430d22eef4a95434
Summary: Removes code that is no longer used
Reviewed By: matryoshcow
Differential Revision: D4021932
fbshipit-source-id: d73dc8450478288afd71eab451a30a505e7de945
Summary:
Since jest stopped using node-haste a while ago, we are the only client left.
This brings back node-haste back to fbsource to allow us to iterate faster.
Reviewed By: bestander
Differential Revision: D3641341
fbshipit-source-id: a859f8834765723a3515e2cf265581b9dd83997c
Summary:This is the last bits needed to fix Windows compatibility on master, most of the work was done in node-haste.
**Test plan**
Run npm test
Run the packager using Windows and Mac
cc cpojer davidaurelio
Closes https://github.com/facebook/react-native/pull/6260
Reviewed By: dmmiller, bestander
Differential Revision: D3005397
Pulled By: davidaurelio
fb-gh-sync-id: e16847808ebfa8b234315b2093dba204c9c1e869
shipit-source-id: e16847808ebfa8b234315b2093dba204c9c1e869
Summary:
Rather than specifying Babel plugins in the `.babelrc` packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native).
This allows for a much better user experience for those who want (or need) to override options in their project's `.babelrc`.
Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the `.babelrc` in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own `.babelrc`. Note - the custom transformer was necessary because without it, RN's `.babelrc` options would supersede the options defined in the project's `.babelrc`...potentially causing issues with plugin ordering.
This PR makes the transformer check for the existence of a project-level `.babelrc`, and if it it's there, it _doesn't_ use the react-native `.babelrc`. This prevents any oddities with Babel plug
Closes https://github.com/facebook/react-native/pull/5214
Reviewed By: davidaurelio
Differential Revision: D2881814
Pulled By: martinbigio
fb-gh-sync-id: 4168144b7a365fae62bbeed094d8a03a48b4798c
Summary:
public
This diff introduces an internal transforms pipeline that integrates with the external one. This has been a feature we've been looking to implement for a long time to use babel instead of `replace` with regexps on many parts of the packager.
Also, to split the bundle we'll need to run one transform. Internally for Facebook we can run the system-import transform altogether withe the other ones. For OSS we offer `transformer.js` which people can use out of the box if they're writing ES6 code. For those people, `transformer.js` will also run the internal transforms`. However they might want to tune the transforms, or even write the code on another language that compiles to Javascript and use a complete different transformer. On those cases we'll need to run the external transforms first and pipe the output through the internal transforms. Note that the order it's important as the internal transforms assume the code is written in JS, though the original code could be on other scripting languages (CoffeeScript, TypeScript, etc).
Reviewed By: davidaurelio
Differential Revision: D2725109
fb-gh-sync-id: d764e209c78743419c4cb97068495c771372ab90
Summary:
Adds support for multiple packager servers, which could be used to hot-reload dependencies in response to a change in the `cacheVersion`.
Currently, there is no way to:
- Create multiple `ReactPackager` servers.
- Instantiate more than one `FileWatcher` constructor (due to the "single instance" invariant).
public
Reviewed By: martinbigio
Differential Revision: D2713455
fb-gh-sync-id: 9be0f0cb2b846baf088d0cf14650cc8b9e950815
Summary: This adds a build option for using Prepack (an experimental packager) to
build a bundle. It doesn't actually take on the npm package dependency
because it's not published/open source (yet).
This will be used while we experiment and should be maintained as the
build system changes so that we can continue getting fresh builds.
I found that saveBundleAndMap and processBundle were over abstracted and
got in my way so I inlined it and removed the unit tests because the unit
test was testing trivial code that is likely to change interface.
I went with a separate build phase and a separate Bundle class even though
there are a lot of commonalities. I imagine that the requirements for
Prepack will continue to diverge. Especially for source maps but a larger
refactor could try to unify these a bit more. The fact that modules are
wrapped before the write phase seems to be an unfortunate architecture
that makes this difficult.
Closes https://github.com/facebook/react-native/pull/4226
Reviewed By: amasad
Differential Revision: D2673760
Pulled By: sebmarkbage
fb-gh-sync-id: 299ccc42e4be1d9dee19ade443ea3388db2e39a8
Summary: @public
This was a hard one, bare with me on the full story of what happened.
We recently started writting additional JS scripts in ES6 for the cli. These code needs to be transformed by babel before we execute it as we don't run node with `--harmony`. To do so we removed the `only` attribute on the `babel-register`. Turns out this broke the packager on oss as if no `only` not `ignore` parameter is specified babel will ignore `node_modules`. Since on oss when a project is created `react-native-github` is located inside of `node_modules` we started getting syntax errors.
The fix is to include separately all the different paths we need to make sure babel transforms each of them. We cannot simply have a single `babel-core/register` as we need to include paths that belong both to oss and internal only. So, we need to have multiple `register` invocations. Since babel does not accumulate the `only` you send on every invocation we need to build a small wrapper to do so.
Reviewed By: @frantic
Differential Revision: D2522426
fb-gh-sync-id: 379a7bb169c7d5cb3002268742de269238bba766
Summary:
Buck (our build system) currently starts multiple packager instances for each target and may build multiple targets in parallel. This means we're paying startup costs and are duplicating the work. This enables us to start one instance of the packager and connect to it via socket to do all the work that needs to be done.
The way this is structured:
1. SocketServer: A server that listens on a socket path that is generated based on the server options
2. SocketClient: Interfaces with the server and exposes the operations that we support as methods
3. SocketInterface: Integration point and responsible for forking off the server
Summary:
The word Package is overloaded, it may mean npm package, or may mean a collection of bundles. Neither is what we mean. We mean `bundle`.
This renames it and modernize some of the Bundler code.
Summary:
@public
Fixes#773, #1055
The resolver was getting a bit unwieldy because a lot has changed since the initial writing (porting node-haste).
This also splits up a large complex file into the following:
* Makes use of classes: Module, AssetModule, Package, and AssetModule_DEPRECATED (`image!` modules)
* DependencyGraph is lazy for everything that isn't haste modules and packages (need to read ahead of time)
* Lazy makes it fast, easier to reason about, and easier to add new loaders
* Has a centralized filesystem wrapper: fast-fs (ffs)
* ffs is async and lazy for any read operation and sync for directory/file lookup which makes it fast
* we can easily drop in different adapters for ffs to be able to build up the tree: watchman, git ls-files, etc
* use es6 for classes and easier to read promise-based code
Follow up diffs will include:
* Using new types (Module, AssetModule etc) in the rest of the codebase (currently we convert to plain object which is a bit of a hack)
* using watchman to build up the fs
* some caching at the object creation level (we are recreating Modules and Packages many times, we can cache them)
* A plugin system for loaders (e.g. @tadeuzagallo wants to add a native module loader)
Test Plan:
* ./runJestTests.sh react-packager
* ./runJestTests.sh PackagerIntegration
* Export open source and run the e2e test
* reset cache
* ./fbrnios.sh run and click around
Summary:
@public
Currently, every time we call into the packager we have to change the ulimit to make sure
we don't hit the EMFILE error (the packager uses as much concurrency as possible).
Using graceful-fs, the fs module -- with monkey patching -- becomes intelligent enough to recover
from EMFILE errors.
Test Plan:
* set `ulimit -n 256*
* start server
* request from your browser: http://localhost:8081/RKJSModules/MainBundle/CatalystBundle.includeRequire.bundle
* it works