Commit Graph

333 Commits

Author SHA1 Message Date
Nick Lockwood 5b425278bb Removed references to isStatic from the codebase
Summary: @​public

The legacy 'isStatic' property for image sources is no longer used anywhere in our codebase, but was still being generated by the packager and referenced in the JS in various places.

This diff removes all the remaining references.

Reviewed By: @frantic

Differential Revision: D2531263

fb-gh-sync-id: 0bba0bb8473b1baa908ef7507cbf6d83efb0d9ee
2015-10-13 06:44:30 -07:00
Martín Bigio 5196ad102d fix E2E tests
Reviewed By: @mkonicek

Differential Revision: D2526310

fb-gh-sync-id: 1c04f56073dc5b393a36b258c039fdfd85ab83a2
2015-10-09 07:59:02 -07:00
Martín Bigio 32b62ef055 Unbreak packager on oss master
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
2015-10-08 17:37:27 -07:00
Tadeu Zagallo ad622f20f2 Fix wrong source map test
Reviewed By: @javache
2015-10-05 11:15:20 -07:00
Martín Bigio 7ad418a396 Move fbobjc bundle command to cli
Reviewed By: @frantic

Differential Revision: D2457072
2015-10-05 09:21:27 -07:00
Tadeu Zagallo 753cc7683c Fix minified source maps
Summary: @​public

The source maps generated by uglify are already stringified, and therefore were
being stringified twice.

Reviewed By: @martinbigio

Differential Revision: D2498242
2015-10-05 08:48:25 -07:00
Amjad Masad 8356b609a5 Use different cache keys for Package objects (fixes #2949)
Summary: @​public

Dead-lock trying to read package.json because it's both a "module" and a "package". in `Module.getName` it uses the cache key "name" and tries to call `Package.getName` which uses the same cache key and we end up returning the same promise that we're trying to resolve resulting in a dead-lock.

This changes the cache keys for the packages that adds a prefix "package-".

Reviewed By: @vjeux

Differential Revision: D2506979
2015-10-04 12:37:25 -07:00
shlomiatar 535ee40818 Fix DependencyResolver to support ES6 multiline imports
Summary: *This is a PR to fix #1939 (DependencyResolver fails to handle ES6 modules import statements with new lines)*

**This PR includes:**
- A fix to the problematic regular expression
- Updated tests that support the new line style.

**Summary:**
We found out that while the packager does its module wrapping thing for lines like this:
```js
import theDefault, { named1, named2 } from 'src/mylib';
```
It fails to do the same for multi line imports:
```js
import theDefault, {
  named1,
  named2
} from 'src/mylib';
```
We've tracked done the issue to a [faulty regular expression in replacePatterns.js](https://github.com/facebook/react-native/blob/master/packager/react-packager/src/DependencyResolver/replacePatterns.js#L12)

You can see various import statements with the problematic regular expression [here](http://regexr.com/3bc8m)

We've figure out a better regular expression (you can play around with it [here](http://regexr.com/3bd3s))Closes https://github.com/facebook/react-native/pull/1940

Reviewed By: @​svcscm

Differential Revision: D2498519

Pulled By: @vjeux
2015-10-01 12:17:21 -07:00
Kyle Corbitt 9c4b476679 enable es6 module syntax
Summary: This is an updated copy of #1993, which was approved by @vjeux but hasn't been rebased. It whitelists the es6 module syntax and updates the JS Environment docs to match. cc @ide @​hkjorgensenCloses https://github.com/facebook/react-native/pull/3175

Reviewed By: @​svcscm

Differential Revision: D2498360

Pulled By: @vjeux
2015-10-01 10:57:23 -07:00
Amjad Masad 502d277ff2 Error on name collisions
Summary: @​public
This moves us from warnings on name collisions to errors. If the error happens in initialization it will fatal out.

However, if the error happens while working (after initialization) then I did my best to make it recoverable. The rational behind this is that if you're working and you're changing names, you may introduce a duplication while moving things around. It will suck if you have to restart the server every time you do that.

Reviewed By: @frantic

Differential Revision: D2493098
2015-09-30 21:02:50 -07:00
Amjad Masad 9211b9b3cf Introduce `getOrderedDependencyPaths` that gets all concrete dependecy paths
Summary: @​public
Since we added packager-managed assets -- internally we still think of asset dependency as a single "module". In reality there are multiple files that represent this module. This becomes important with the `getDependencies` API which is used by Buck to inform it on what to rebuild. Since `getDependencies` deals with modules, and is more of an internal API, I've introduced a new one and would go on to deprecate this.

Reviewed By: @frantic

Differential Revision: D2487207
2015-09-29 18:34:21 -07:00
Amjad Masad 42b5cd59e4 Fix debug namespaces
Summary: @​public
Have a top-level debug namespace: `ReactNativePackager`
And add a couple of debugs in the transformer. This is ground work for adding a verbose option.

Reviewed By: @DmitrySoshnikov

Differential Revision: D2489960
2015-09-29 16:10:22 -07:00
Amjad Masad 256fa18ab2 remove randomness
Reviewed By: @javache

Differential Revision: D2490001
2015-09-29 12:44:22 -07:00
Amjad Masad ca007aabb4 Pass in the platform options when loading dependencies
Reviewed By: @jingc

Differential Revision: D2488262
2015-09-29 09:22:00 -07:00
Pieter De Baets e885628245 Don't call originalConsole methods when they don't exist
Reviewed By: @vjeux

Differential Revision: D2485562
2015-09-29 09:21:48 -07:00
yiminghe 4978855d72 support es6.constants by default. Fixes #2932
Summary: In javascriptcore(ios9), this code will run as expected(output 0 1):

```js
for(let i=0; i<2; i++) {
  const data = i;
  console.log(data);
}
```

But when debug in chrome, the above code will fail without `use strict` prologue (if you add prologue, rn will fail with red screen `Const declarations are not supported in strict mode`): https://code.google.com/p/v8/issues/detail?id=4432.

So it's better to transpile contant by default.

Closes https://github.com/facebook/react-native/pull/2955

Reviewed By: @​svcscm

Differential Revision: D2483398

Pulled By: @vjeux
2015-09-26 15:50:24 -07:00
Amjad Masad fa0da5682b Fix haste resolution (and better warnings)
Summary: @​public

Fix the haste resolution algorithm. Changed the map data structure from a list of modules, to a list of modules grouped by platform.
This considerably simplifies the "getModule" method and makes it easy to properly warn about colliding module names.
This also fixes a bug where we used to include `.web` files when we shouldn't (see task).

Reviewed By: @vjeux

Differential Revision: D2482969
2015-09-25 20:35:45 -07:00
Justin Spahr-Summers 1487ebfe01 Revert packager randomization revert 2015-09-25 10:24:06 -07:00
Justin Spahr-Summers e2fdd59784 Revert packager module randomization 2015-09-25 07:41:25 -07:00
Amjad Masad 9293e54085 Warn and randomize colliding name selection
Summary: @​public

The issue of colliding haste modules have came up many times and have wasted countless engineering hours. This will start warning about it and will also start selecting modules at random so that people don't depend on undefined behavior.

Additionally, this surfaced an issue where with assets we may fatally throw if the directory doesn't exist. This is fixed by checking the existence of the directory before trying to match files in it.

Reviewed By: @jingc

Differential Revision: D2478480
2015-09-25 00:19:27 -07:00
Martin Bigio bf88e46ebb Print to console instead of debug uncaught exceptions
Reviewed By: @jingc

Differential Revision: D2478099
2015-09-24 15:57:26 -07:00
Martin Bigio eee11eaeed Log server state when client is unexpetedly closed
Reviewed By: @javache

Differential Revision: D2473036
2015-09-24 08:20:20 -07:00
Jan Kassens 974ec059e8 Fix for displayName transform
Summary: The `react.displayName` transform was added in 93b9329b75.

That diff missed to update the `.babelrc` where the comment says it should stay
in sync (I'm not sure where it's used though). I added a comment in the other
direction so this can be prevented in the future.

I also updated the `cacheVersion` so we actually transform the code again to add
the missing displayName properties to unchanged components.
Closes https://github.com/facebook/react-native/pull/2905

Reviewed By: @vjeux

Differential Revision: D2473447

Pulled By: @kassens
2015-09-24 08:20:02 -07:00
Charlie Cheever dc7681e946 Also call the original `console` methods if they exist
Summary: Ex. When `console.log` or similar is called, this will call
the original method, which can be quite useful.

For example, under iOS, this will log to the Safari console debugger,
which has an expandable UI for inspecting objects, etc., and is also
just useful if you are using that as a REPL.

I don't believe this incurs a meaningful performance penalty unless
the console is open, but it would be easy to stick behind a flag
if that is a problem.
Closes https://github.com/facebook/react-native/pull/2486

Reviewed By: @​svcscm

Differential Revision: D2472470

Pulled By: @vjeux
2015-09-23 19:29:24 -07:00
Martin Bigio 407247fe1e Don't swallow client errors
Reviewed By: @​swarr

Differential Revision: D2472285
2015-09-23 12:43:23 -07:00
Amjad Masad 45ed000d4b Remove server error listener so that it throws
Summary: @​public
We swallow errors like it's nobody's business :(
Having an error handler that `reject`s after the promise has been resolved is a no-op. In node, if there is no `error` event handler then the error would throw.

So after we start listening and we want to resolve the promise, we remove the error listener so that we make sure errors actually throw.

Finally, I made the `uncaughtError` handler log `error.stack` so we can get an idea of what's going on.

Reviewed By: @martinbigio

Differential Revision: D2468472
2015-09-22 15:48:29 -07:00
Amjad Masad 30cca276fa Return concrete file paths to the client
Reviewed By: @martinbigio

Differential Revision: D2465182
2015-09-22 15:45:25 -07:00
Martín Bigio c4cb95f2d7 Add logging information when client's socket gets closed unexpetedly
Reviewed By: @amasad

Differential Revision: D2468293
2015-09-22 15:21:35 -07:00
Amjad Masad f39e3fe113 Simplify over-engineered Activity module
Summary: @​public
I've noticed that the logs can be sometimes misleading, as when an Activity ends it doesn't log immediatly. A sync `console.log` would log before it although the Acitivity should've finished before.

Turns out we wait before writing out the logs to the console. I don't see any reason for this. Looking at the `Activity` module it's over-engineered. This diff makes logging sync and simplfies the module.

Reviewed By: @martinbigio

Differential Revision: D2467922
2015-09-22 14:25:37 -07:00
Amjad Masad 7806c0875b Log exit code
Reviewed By: @martinbigio

Differential Revision: D2467457
2015-09-22 12:40:25 -07:00
Christoph Pojer d088750163 Fix tests + enable inline requires on react-native
Reviewed By: @sahrens, @vjeux

Differential Revision: D2456607
2015-09-21 14:39:44 -07:00
Martin Bigio 8f5b2ccbe0 Log uncaught exceptions on the socket server
Reviewed By: @frantic

Differential Revision: D2462114
2015-09-21 12:08:29 -07:00
Pieter De Baets d94ed42e1c Enable Jest tests
Reviewed By: @amasad

Differential Revision: D2422290
2015-09-20 16:48:35 -07:00
Christoph Pojer fa01b2e4cb Codemod tests to use top-level-requires
Reviewed By: @DmitrySoshnikov

Differential Revision: D2456250
2015-09-19 15:41:29 -07:00
DengYun 450cd5c406 Generate module name seperated by '/' on Windows.
Summary: I think packager on different platform should generate same output if possible. So packager should replace '\\' in module name with '/' on Windows.

Closes https://github.com/facebook/react-native/pull/2813

Reviewed By: @​svcscm

Differential Revision: D2458634

Pulled By: @martinbigio
2015-09-18 15:15:28 -07:00
mqli f5409c1a51 Fixing the packager infinite loop on Windows
Summary: The issue here https://github.com/facebook/react-native/issues/2787

The root path '/' dosn't match windows root path
Closes https://github.com/facebook/react-native/pull/2789

Reviewed By: @​svcscm

Differential Revision: D2452718

Pulled By: @martinbigio
2015-09-18 06:05:22 -07:00
facebook-github-bot-6 0d09f22dbf Get back 100% in sync with fb codebase 2015-09-16 10:30:53 -07:00
Martín Bigio 41850a962f defeat race condition when replying to client
Summary: @​public

The server dies after 30 seconds if it has no jobs on it's queue. The problem is that the jobs counter gets decreased before returning the bytes to the client. As a consequence, it's possible that the server dies while it's returning the bytes to the client, or just after it finished returning the bytes to the client.

To avoid both issues lets move the counter decrease a few lines below and bump the timer to make sure we have time to fully write the bytes on the socket and let the client close the connection before the server dies.

Reviewed By: @vjeux

Differential Revision: D2445264
2015-09-15 16:25:25 -07:00
Amjad Masad 1bf7887322 Refactor DependencyResolver into request/response
Reviewed By: @martinbigio

Differential Revision: D2425842
2015-09-11 17:01:35 -07:00
Christopher Chedeau e9e3cd304b Revert internal files that didn't get pulled internally first
See all the packager files in this commit:
f83675d191 (diff-7b5603771e245e5b0cd7223277db3db4)

cc @foghina
2015-09-11 16:59:28 -07:00
Amjad Masad d5bce33f69 Fix server tests
Summary: @​public
Invoking an extra promise caused failures in the promise-based tests. This fixes them.

Reviewed By: @vjeux

Differential Revision: D2432431
2015-09-11 13:30:33 -07:00
Amjad Masad 9b27116798 Client should throw when server unexpectedly closes the connection
Reviewed By: @natthu

Differential Revision: D2425357
2015-09-09 16:35:25 -07:00
Amjad Masad 3cfac35fd8 Handle EEXIST error when starting the server
Reviewed By: @cpojer

Differential Revision: D2426373
2015-09-09 16:10:33 -07:00
Amjad Masad 3ee65225be Protect against races in deleting corrupt cache
Reviewed By: @cpojer

Differential Revision: D2426450
2015-09-09 16:05:39 -07:00
Amjad Masad cd4e8a9fae Pass in platform argument in offline building
Summary: how did this ever work?
All build jobs must pass in the platform argument.
This also turns the "platform" argument into a required one.

I added a task to infer the platform argument from the filename here: t8306875

Reviewed By: @martinbigio

Differential Revision: D2425114
2015-09-09 14:45:58 -07:00
Christopher Chedeau d3800c6615 Fix declareOpts test
Summary: When we updated joi, the error message was changed. I removed the content to prevent similar errors in the future.

Reviewed By: @amasad

Differential Revision: D2424048
2015-09-09 11:25:28 -07:00
Tadeu Zagallo c4305fe9af Move systrace helper out of the packager
Summary: @​public

The profiler helper shouldn't live inside the packager itself, move
it to the packager.js file with other middlewares.

Reviewed By: @martinbigio

Differential Revision: D2424878
2015-09-09 11:25:24 -07:00
Christopher Chedeau c71c940803 Revert "unbreak tests"
This reverts commit f9b2709c8d.
2015-09-09 11:10:50 -07:00
Christopher Chedeau f9b2709c8d unbreak tests 2015-09-08 20:00:42 -07:00
Christopher Chedeau a9607901e2 Updates from Tue 8 Sep 2015-09-08 16:54:44 -07:00
Alex Kotliarskyi fb7d7d6880 [ReactNative] Pipe `platform` option all the way to the asset server 2015-09-08 11:37:38 -08:00
Martín Bigio 817bf1f50f [react-packager] Bump ipc timeout 2015-09-08 04:50:25 -08:00
Amjad Masad bceab6c1c2 [react-packager] Allow a longer startup time before the server dies
Summary:
1. When the server starts up, it only gives itself 30 second to live before receiving any connections/jobs
2. There is a startup cost with starting the server and handshaking
3. The server dies before the client has a chance to connect to it

Solution:
1. While the server should die pretty fast after it's done it's work, we should have a longer timeout for starting it
2. I also added accompanying server logs with client connection errors
2015-09-07 10:31:49 -08:00
Amjad Masad 936e1d4a11 [react-packager] Support platform extensions in image requires
Summary:
We don't currently support platform extensions in asset modules.
This adds supports for it:

```
require('./a.png');
```

Will require 'a.ios.png' if it exists and 'a.png' if it doesn't.
2015-09-04 15:17:14 -08:00
Tadeu Zagallo 90409770c9 [RectNative][Packager] Cache minification result
Summary:
The packager just cached the result of the bundle, but would minify
it on every request. Change it to cache the minification result.
2015-09-04 12:22:50 -08:00
Amjad Masad 54f91bd951 [react-packager] Socket Server should not die while there active connections
Summary:
Saw an issue with a build because of an ENONT error: https://fb.facebook.com/groups/716936458354972/permalink/923628747685741/

My hypothesis:

1. We issue a ping to the socket (in SocketInterface/index.js) a decides if the available socket is alive
2. We see that it's alive but by the time we actually connect to it the server would've died

Solution:

1. The server shouldn't die as long as there are clients connected to it (currently it only stay alive as long as there are jobs)
2. The "ping" should only disconnect once the client is connected
3. Finally, have a better error message than ENOENT
2015-09-03 14:48:19 -08:00
Tadeu Zagallo 7bb0ff535c [ReactNative][Packager] Fix source maps for minified sources
Summary:
The packager was ignoring minification for source map requests.
2015-09-03 12:01:57 -08:00
Spencer Ahrens d7b13fb32b Updates from Thu Sep 3rd. 2015-09-03 12:55:40 -07:00
Amjad Masad 62f9059f85 [react-packager] Sourcemap url should include the same args as the bundle url
Summary:
Sourcemap urls were generated as just the pathname (no options) which meant that they generated source for the wrong bundle.

Even worse, there exists a race condition when multiple request to the same bundle has different types of paltform arguments (in this case one could be 'ios' and the other is undefined). The fix will this will come later as it's more involved -- will need to refactor the dependency resolver to have a per-request state.
2015-09-02 15:34:54 -08:00
Amjad Masad b17b328aed [react-packager] Fix cache issues 2015-09-01 16:43:17 -08:00
Amjad Masad 39ae5daec3 [react-pacakger] Max idle time for socket server is too long 2015-09-01 11:40:47 -08:00
Spencer Ahrens 465f539057 Updates from Mon Aug 31st. 2015-08-31 16:31:41 -07:00
Amjad Masad d87480e9ac [react-pacakger] Fix failing test
Summary:
Fix failing test that matches the exact error string to match using `contains`.

I was under the impression that jest tests were running in CI -- turns out not yet.
2015-08-31 12:42:29 -08:00
Amjad Masad 250494acd3 [react-packager] Fail loudly with errors from the transformer 2015-08-31 09:27:26 -08:00
Martín Bigio 7fed668841 [react-packager] Cache BundlesLayout 2015-08-31 07:13:35 -08:00
Martín Bigio 5dbde93ec6 [react-packager] `System.import` transform 2015-08-27 09:28:48 -08:00
Amjad Masad 34b5aa2a57 [react-packager] Fix races
Summary:
A few potential races to fix:

1. Multiple clients maybe racing to delete a zombie socket
2. Servers who should die because other servers are already listening are taking the socket with them (move `process.on('exit'` code to after the server is listening
3. Servers which are redundant should immediatly die
2015-08-27 01:41:11 -08:00
Amjad Masad 1598cc6979 [react-packager] bump create server timeout to 60s 2015-08-26 23:11:44 -08:00
Alex Kotliarskyi c7b1509615 [react-native] Fix tests and re-enable CI 2015-08-26 20:58:24 -08:00
Martín Bigio ac5c1e9cc4 [react-packager] Make sure server is listening on socket 2015-08-26 16:25:17 -08:00
Martin Konicek 5526533f51 Updates from Wed 26 Aug 2015-08-26 14:04:01 +01:00
Amjad Masad 074069e465 [react-packager] Cleanup socket interface code 2015-08-25 17:36:08 -08:00
Amjad Masad 2b7dd4650f [react-native] bump create server timeout 2015-08-25 17:13:13 -08:00
Martin Konicek 0203f87ea3 Add chalk mock 2015-08-25 22:02:19 +01:00
Martin Konicek da7ac11c53 Updates from Tue 25 Aug 2015-08-25 19:21:59 +01:00
Martin Konicek 4f87ec5ce7 [ReactNative] Unbreak OSS packager JS tests 2015-08-25 10:18:39 -08:00
Natansh Verma 8d65367fbc Revert "[packager] Unbreak Bundler test" 2015-08-25 09:53:45 -08:00
Amjad Masad 54026024cc [react-packager] Expose a socket interface
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
2015-08-25 09:37:08 -08:00
Martin Konicek 245a5b8e8c [packager] Unbreak Bundler test 2015-08-25 09:24:42 -08:00
Krzysztof Magiera 27a67c2434 [ReactNative] Respect --assets-dest in "download from server" mode 2015-08-25 07:22:05 -08:00
Martín Bigio 9ba4697f02 [react-packager] Fix OSS tests 2015-08-24 18:49:05 -08:00
Amjad Masad eb248e0b58 [react-packager] Implement transformer progress bar
Summary:
The transform step in currently the longest one in the bundling process. This adds a progress bar to track the transform progress.

{F23096660}
2015-08-24 16:09:34 -08:00
Christopher Chedeau f3a165db4f [Logs] Name fs step
Summary:
There are two fs steps and it wasn't clear why. This now puts the right label:

```
[9:38:25 PM] <START> Building in-memory fs for JavaScript
[9:38:27 PM] <END>   Building in-memory fs for JavaScript (2030ms)
[9:38:27 PM] <START> Building in-memory fs for Assets
[9:38:27 PM] <END>   Building in-memory fs for Assets (615ms)
```
2015-08-21 14:29:05 -07:00
Martin Bigio 677f96c60e [react-packager] unbreak tests 2015-08-21 09:38:37 -07:00
Martín Bigio 320a9207f4 [react-packager] Avoid referring `Module` like objects in `BundlesLayout`
Summary:
The `BundlesLayout` will be used as a persistent index. As such, it would be easier to avoid having dependencies to `Module`, `Package`, `Asset`, etc. We're not using that information for now and if we happen to need to use it we could always fetch it using the `ModuleCache`.
2015-08-21 08:13:58 -07:00
Martín Bigio d2f82b1dfd [react-packager] Move async dependencies to `System.import`
Summary:
We've decided to move the syntax for asynchronously requiring async dependencies. The new syntax works better with promises and therefore withe async/await as well. The new syntax looks like this: `System.import('moduleA').then(moduleA => {...});` or if you're using async/await you could simply do:
  let moduleA = await System.import('moduleA');
  new moduleA().someFunction();

If you need to require multiple dependencies just do:
  Promise
    .all([System.import('moduleA'), System.import('moduleB')])
    .then((moduleA, moduleB) => {...})

or the equivalent using async/await
2015-08-21 07:56:19 -07:00
Amjad Masad 6debfce374 [react-native] Update graceful-fs and use it in _build_bundle.js 2015-08-20 23:58:51 -07:00
Amjad Masad 3bfa90e433 [react-packager] Fix error in template string and bump timeout
Summary:
Fix error in the template string (no plus, thinks it's a function).
And bump the timeout to 30 seconds because a file is taking more than 10 seconds `js/RKJSModules/Libraries/FBComponents/FBFed/FeedStoryFragments.js`
2015-08-20 15:29:38 -07:00
Martín Bigio c1f90c1ecf [react-packager] Integration test for `runServerHere.sh` 2015-08-20 12:00:06 -07:00
Martín Bigio 5de0796126 [react-packager] Introduce bundle IDs and keep track of parent/child
Summary:
Since JS doesn't have the guarantee that once a bundle is loaded it will stay in memory (and this is something we actually don't want to enforce to keep memmory usage low), we need to keep track of parent/child relationships on the packager to pass it down to native. As part of this diff, we also introduced an ID for each bundle. The ID for a child bundle is shynthetized as the bundleID of the parent module + an index which gets incremented every time a new bundle is created. For instance given this tree:

       a,b
    c       f
  d   e       g

the ID for `d` will be `bundle.0.1.2`, the one for e will be `bundle.0.1.3` and the one for `g` will be `bundle.0.5.6`. This information will be useful to figure out which bundles need to be loaded when a `require.ensure` is re-written.
2015-08-20 10:19:09 -07:00
Amjad Masad ec82ffa52b [react-packger] Add a timeout on transform jobs
Summary:
There's been a case where Babel can hang indefinitely on a file parse/transform. Possibly related to https://github.com/babel/babel/issues/2211

This adds a timeout to transform jobs and throws an error informing the user of the offending file. The timeout interval defaults to 10 seconds, but can be changed via an option.
2015-08-19 17:42:28 -07:00
Amjad Masad 24689006ab [react-packager] Remove unnecessary 'chalk' module mock 2015-08-19 17:28:18 -07:00
Amjad Masad e76e60f88d [react-packager] Make the fs mock async 2015-08-19 17:17:15 -07:00
Amjad Masad b4100b8332 [react-packager] Wait for haste map before accepting any requests
Summary:
D2319999 introduced a regression where we stopped waiting for the "build haste map" step to finish before we accept any requests. This makes sure that we block on that.

Need to unbreak with this, but will follow up with a test to catch this in the future.
2015-08-19 16:17:37 -07:00
Martín Bigio f4c7bb1103 [react-packager] Fix bug on Bundles Layout algorithm
Summary:
The layout algorithm wasn't getting deep into the sync dependencies recursively to async dependencies.
2015-08-19 14:20:38 -07:00
Alex Kotliarskyi b18d73b568 [RN] Unbreak packager 2015-08-18 18:29:32 -07:00
Martín Bigio 291c8ff9ec [react-packager] Modernize Activity to ES6 2015-08-18 15:25:18 -07:00
Martín Bigio 51596f8674 [react-packager] Modernize AssetServer to ES6 2015-08-18 14:38:40 -07:00
Ben Alpert 65692b7235 [ReactNative] Don't redbox for React warnings when not using Chrome executor 2015-08-17 16:02:10 -07:00
Felix Oghină f0dd9fb358 Merge pull request #2298 from foghina/yo
[cli] convert project generation to use yeoman
2015-08-17 13:51:24 +01:00
Amjad Masad 3388d8fe79 [reat-packager] Switch platform resolution based on query param
Summary:
Currently the platform selection is controlled by the blacklist. However, since we want to use the same server instance for cross-platform development, we need this to be controlled per request.

One outstanding issue, is that the DependencyGraph class wasn't designed that way and it doesn't have a per-request state. This means that with the current design race conditions is possible. If we got a request for a different platfrom while processing the previous request, we may change the outcome of the previous request.

To fix this a larger refactor is needed. I'll follow up a diff to do that.

Finally, so I don't break the universe like last time, I'll leave it up to the RN guys to update the call sites.
2015-08-15 13:28:18 -07:00
Alex Kotliarskyi 324d154cf7 [ReactNative] Add ability to listen for Packager events 2015-08-14 14:28:45 -08:00
Martín Bigio 3be2b1d966 [react-packager] Modernize `Server` to ES6 2015-08-14 12:34:23 -08:00
Martín Bigio 0623371814 [react-packager] Cache in which bundle is each module
Summary:
Not that at the moment a module can be present in multiple bundles, so the new API will return only one of them. In the near future we'll impose the invariant that a module can only be present in a single bundle so this API will return the exact bundle in which it is.
2015-08-14 12:30:30 -08:00
Martín Bigio 76e37c4423 [react-packager] Modernize `Server-test` by using ES6 features 2015-08-14 12:23:02 -08:00
Amjad Masad bc28a35bda [react-packager] Use module objects across the codebase (rid of getPlainObject etc)
Summary:
Instead of using plain objects and having to convert to and from them we just use the `Module` class across the codebase.
This seems cleaner and can enforce the type as opposed to fuzzy objects.
2015-08-13 15:52:31 -08:00
Amjad Masad abce124198 [react-packager] Remove horribly outdated example_project
Summary:
Removes some old unused code.
2015-08-13 13:02:52 -08:00
Martín Bigio 5cad2e9370 [react-packager] Introduce Bundler
Summary:
Introduce a Bundler capable of generating the layout of modules for a given entry point. The current algorithm is the most trivial we could come up with: (1)it puts all the sync dependencies into the same bundle and (2) each group of async  dependencies with all their dependencies into a separate bundle. For async dependencies we do this recursivelly, meaning that async dependencies could have async dependencies which will end up on separate bundles as well.

The output of of the layout is an array of bundles. Each bundle is just an array for now with the dependencies in the order the requires where processed. Using this information we should be able to generate the actual bundles by using the `/path/to/entry/point.bundle` endpoint. We might change the structure of this json in the future, for instance to account for parent/child bundles relationships.

The next step will be to improve this algorithm to avoid repeating quite a bit dependencies across bundles.
2015-08-13 12:57:55 -08:00
Amjad Masad 7750db05e6 [react-packager] Set a lifetime on workers to avoid memory leaks 2015-08-12 19:26:26 -08:00
Martín Bigio cfcf604b3d [react-packager] Introduce `require.ensure`
Summary:
This is the first step to add support for splitting the JS bundle into multiple ones. This diff adds support for keeping track of the async dependencies each module has. To do so we introduce the following syntax:

  require.ensure(['dep1', 'dep2, ..., 'depN'], callback);

Where the callback function is asynchronously invoked once all the indicated modules are loaded.

Internally, the packager keeps track of every set of async dependencies a module has. So for instance if a module looks like this:
  require.ensure(['dep1'], () => {...});
  require.ensure(['dep2'], () => {...});

the `Module` object will keep track of each set of dependencies separately (because we might want to put them on separate bundles).
2015-08-12 12:23:42 -08:00
Amjad Masad 309326db2e [react-packager] Rename 'Package' to 'Bundle'
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.
2015-08-12 12:09:01 -08:00
Felix Oghină f83675d191 [cli] convert project generation to use yeoman 2015-08-12 12:04:27 +01:00
Martín Bigio 70624dc347 [react-packager] Fix Cache-test 2015-08-11 11:27:15 -08:00
Christopher Chedeau 5ebe0ed717 Bust jest caching and fix tests 2015-08-11 11:02:19 -07:00
Evan Solomon 51ccdfa36a [Babel] Upgrade babel and regenerator to the latest version
Summary:
See c0fd4c1f9e
Closes https://github.com/facebook/react-native/pull/1753
Github Author: Evan Solomon <evan@evanalyze.com>

@allow-crlf-text
2015-08-10 20:37:39 -08:00
Martín Bigio a303a42e28 [react-packager] Add more granular Activity logging 2015-08-10 16:25:04 -08:00
Martín Bigio 2afeb8fbe6 [react-packager] Promote Cache to top level
Summary:
The cache is only used for JSTransformer at the moment. We're doing IO and some computation to get each module's name, whether is a haste or node module and it's dependencies. This work happens on startup so by caching this value we shouldbe able to reduce the start up time. Lets promote the Cache to the Packager level to be able to use it by any of the components of the packager. For now, on this diff we'll start using it to cache the mentioned fields.

Also we had to introduce the concept of fields in the cache as manually merging the date we had for each path is not possible as we're using promisses all around. With the new API, each field is a promise.

@amasad and I did some manual testing to measure the impact of this change and looks like it's saves 1 second when building the haste map (which represents 50% of the time). Overall this reduces 1 second of start up time which was currently about 8s on my mac book pro.
2015-08-10 16:25:03 -08:00
Martín Bigio aefdf82cdc [JSAppServer] Don't keep track of not found packages 2015-08-06 11:34:56 -08:00
Thomas Aylott a6ff11f1d2 [react-packager] Fixes stack traces
Summary:
TransformErrors weren't showing stack traces, making it hard to debug problems in transformer code.
2015-08-05 12:46:30 -08:00
James Ide 47e1d1aef8 [Async] Enable async/await and update UIExplorer and tests
Summary:
- Enables async/await in .babelrc and transformer.js
- Adds regenerator to package.json. Users still need to explicitly require the regenerator runtime -- this is so that you only pay for what you use.
- Update AsyncStorage examples in UIExplorer to use async/await
- Update promise tests in UIExplorer to use async/await in addition to the promise API

Closes https://github.com/facebook/react-native/pull/1765
Github Author: James Ide <ide@jameside.com>
2015-08-04 05:35:13 -08:00
Amjad Masad 18452940f0 [react-packager] Add support for platform in the resolver
Summary:
Teach the resolver about platform-based resolution. The platform extension is inferred from the entry point.
It works for haste modules, as well as node-based resolution.
2015-08-03 18:29:20 -08:00
James Ide 53222f0dda [Packager] Include Content-Type headers with bundle and source maps
Summary:
The packager did not send back the Content-Type headers. Adding these.

Closes https://github.com/facebook/react-native/pull/2029
Github Author: James Ide <ide@jameside.com>
2015-07-24 18:46:17 -08:00
Dave Sibiski 70feab9d50 [Packager] Fix when loading a path that can't be handled
Summary:
[Packager] Adds `NotFoundError` when loading a path that can't be handled

Resolves https://github.com/facebook/react-native/issues/1944
Closes https://github.com/facebook/react-native/pull/1948
Github Author: Dave Sibiski <dsibiski@gmail.com>
2015-07-15 08:25:31 -08:00
Amjad Masad b45e2ed7ed [react-packager] fix test 2015-07-01 17:37:51 -08:00
James Ide 5aa27586f0 [Tests] Update tests to run on io.js with the latest version of jest
Summary:
[This is a preview diff for getting RN's tests to pass with a future version of jest that supports io.js and other future versions of Node. This can be merged once the diff to update jest is merged upstream and published.]

Updates the tests in small ways so they run on io.js with two updates:

 - The Cache test which relies on Promises uses `runAllImmediates` for modern versions of Node because bluebird uses `setImmediate` instead of `process.nextTick` for Node >0.10.

Closes https://github.com/facebook/react-native/pull/1382
Github Author: James Ide <ide@jameside.com>

Test Plan:  Run `npm test` with the latest version of jest.
2015-07-01 13:02:29 -08:00
Amjad Masad 7d184adf1a [react-packager] Use latest babel-core in place of babel (40% perf improvement) 2015-06-30 03:55:21 -08:00
Amjad Masad 73b032ab87 [react-packager] Update sane to get a new version of fb-watchman (perf) 2015-06-26 17:48:39 -08:00
Amjad Masad de020b44c9 [react-packager] Enable watchman fs crawl
Summary:
@public
Now that watchman perf issue was fixed we can enable watchman-based fs crawling which is faster than node.
This showed an existing issue with some files missing from the blacklist which I addressed.

Test Plan:
./fbrnios.sh run
click around and scroll all the apps
2015-06-26 16:20:50 -08:00
Amjad Masad 1109ce3b8c [react-packager] Injectible file crawlers (2x crawl speedup) 2015-06-24 18:04:57 -08:00
Jing Chen c157051da7 [events] Add JS require time and fix up some existing logs 2015-06-24 16:59:00 -08:00
Amjad Masad 4ac5c7e19e [react-packager] Fix the confused node_modules detection function
Summary:
@public

We have a function that detects whether a give file is to be treated as a node_modules. If so it doesn't have access to the haste module map. There is an exception to this rule which is a few modules that are allowed to do that. Currently thats react-native, react-tools, and parse.

The current implementation had a bug where if you had `react-native` (or react-tools etc) in the name before the actual package root then the detection will be off. This fixes the problem by starting from the `lastIndexOf('node_modules')` directory, that way nothing confuses us.

Test Plan:
./runJestTests.sh
export OSS, patch, run e2e test
2015-06-24 15:20:35 -08:00
Christopher Chedeau eb9c7235e2 [ReactNative] Bring in node console.log formatting
Summary:
@public

The current output of console.log is extremely bad. If you pass NaN, it shows up as null (super confusing I know -_-), if you pass a cyclical object, it just says that it is cyclic and that's it. It doesn't print up the first few levels which are NOT cyclical and would be really helpful.

It turns out that nodejs console.log pretty printer is really awesome and can be easily extracted as a few hundred lines. This is going to be such a productivity boost that I think it's the right tradeoff to embed it like this

Test Plan:
```
var a = {kikoo: {lol: 1}}
a.kikoo.nice = a;

console.log(a);
> { kikoo: { lol: 1, nice: [Circular] } }

console.log(NaN)
> NaN
```
2015-06-24 14:11:55 -08:00
Forbes Lindesay fccea2f365 Replace bluebird with promise 2015-06-22 08:44:03 -08:00
Bill Fisher 5aee4cec98 [ReactNative][easy] fix server 500 response typo
Summary:
@public
corrected small typo in the 500 response from the packager server

Test Plan: add throw to promise function prior to error handler, run packager, cache a bundle with bundle extension URI, open /debug/packages, see clean 500 error
2015-06-20 16:43:18 -08:00
Amjad Masad 2845e78080 [react-packager] Cache in-memory file lookups (~200ms win on file change) 2015-06-19 22:47:26 -08:00
Amjad Masad 2d4055e513 [react-packager] Rewrite dependency graph (support node_modules, speed, fix bugs etc)
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
2015-06-19 18:05:18 -08:00
Amjad Masad 0fec355076 [react-packager] Cache based on options, not url
Summary:
@public

We cached based on url, which wasn't unique becuase some options would be defaulted. This was obvious when starting the server via fbrnios which tries to warmup the bundle.
And then when the device woke up it will send a request (that is identical in reality) but would miss the cache.

This changes the cache key into a JSON stringification of the options.

Test Plan:
* ./runJestTests.sh
* ./fbrnios.sh run
2015-06-19 15:14:31 -08:00
Amjad Masad 9998337220 [react-packager] Add tests to ensure we return all dependency types 2015-06-18 21:27:55 -08:00
Amjad Masad 477360b8c9 [react-packager] Make it safe to include files without a newline at the end
Summary:
@public
Fixes #1431
Fixes #1005
Files with no newlines and a comment at the end of the file would've caused a syntax error in the bundle:

```js
__d('module', function() {
hi();
// wow })
```

This fixes the issue by inserting a new lines before `})`.

Test Plan:
* ./runJestTests.sh
* ./runJestTests.sh PackagerIntegration
* open app to the playground app
* add an error
* observe that the redbox has the correct lines
2015-06-16 12:02:49 -08:00
Tadeu Zagallo ae9e4089fc [ReactNative] Revert packager ignoring node_modules 2015-06-11 10:45:32 -08:00
Spencer Ahrens 6c6b8bec7e [ReactNative] Fix require-time redboxes 2015-06-09 15:42:47 -08:00
Eric Vicenti f90fa53df9 Revert [react-packager] Add support for nested node_modules 2015-06-05 08:44:06 -08:00
Amjad Masad 30fc7389d1 [react-packager] Fix more node_modules resolution rules
Summary:
@public
Fixes #773
This fixes `.json` name resolution. And also reads `package.json` when doing a directory module resolution.
The algorithm can be found here: https://nodejs.org/api/modules.html
I'll probably start including the node (or browserify) modules test in later diffs to make sure we're fully compliant.

Test Plan:
* ./runJestTests.sh
* ./runJestTests.sh PackagerIntegration
* open playground and require a json file
* test redbox
2015-06-04 15:07:03 -08:00
Amjad Masad 856469a24b [react-packager] Support packages with '.' in the name
Summary:
@public
Fixes issue #1055
For some historical reason we used to strip the extension of the module name before passing it to `resolveDependency` which is completly capable of handling all kinds of names. The fix is one line, but added a few tests for this.

Test Plan:
* ./runJestTests.sh
* ./runJestTests.sh PacakgerIntegration
* Open app and click around
2015-06-03 14:07:31 -08:00
Amjad Masad 5a191dadfc [react-packager] Add support for nested node_modules
Summary:
@public
The packager's resolver started out imitating node-haste, which meant that we didn't support nested modules. Now this is a problem. Bigger projects are bound to have versions of different versions of the same package at different levels of the dependency tree. This
makes loading dependencies lazy for node_modules and implements the node resolution algorithm. However, it also mantains that some
modules are still "haste" format, which currently defaults to "react-native" and "react-tools".

Finally, this means ~5 seconds speed up on every server start. This should also have a big impact on open source users with projects with big node_modules.

Test Plan:
1- test the app with --reset-cache
2- click around test and production apps
3- update the OSS library
4- create a new project
5- npm install multiple modules
6- create some version conflict in your project
7- make sure we do the "right" thing
8- test file changes to make sure it works
2015-06-03 11:35:48 -08:00
Tadeu Zagallo ebae151f24 [ReactNative] Update sane fork + FileWatcher config 2015-05-28 07:12:41 -08:00
Tadeu Zagallo 21b3304a95 [ReactNative] Add option to file watcher to ignore node_modules 2015-05-28 01:18:47 -08:00
Amjad Masad 82a082a794 [react-packager] Introduce buildPackage API 2015-05-22 17:28:27 -08:00
Amjad Masad bd11de1b51 [react-packager] Use actual error types
Summary:
@public
Previously, we had to use errors as a property on the result object because there was no way to pass custom props between
the child worker and the parent. This has been fixed in node-worker-farm (D2092153) and now we can use regular errors.
This also adapts the transformer to babel-specific errors. Generic errors, however, should still work and render readable
info.

Additionally, I deprecated, but maintained backwards compatiblity for people in OSS that are using custom transformers.

Test Plan:
1. `./runJestTests.sh`
2. `./runJestTests.sh PackagerIntegration`
3. open the playground app
4. Add a syntax error. Say `1=x` somewhere in the file
5. Reload and see error message 'SyntaxError <filename> description (line:col)'
6. Make sure that the stack trace is clickable and it attempts to open the editor to the location
2015-05-22 10:21:26 -08:00
Amjad Masad 9a76f224af [react-packager] Add first class support to popular image formats
Summary:
@public
1. Default to first class support of popular image formats
2. Add tests to make sure we support other than png

Test Plan:
1. ./runJestTests.sh
2. Add test.png and test.jpg images in the Playground app dir
3. require both images and render then in the playground app
4. they render
2015-05-20 15:28:29 -08:00