Commit Graph

160 Commits

Author SHA1 Message Date
Amjad Masad 802ad3feb3 [react-packager] fix test 2015-07-01 17:37:51 -08:00
James Ide 62431c7f62 [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 70dde863ae [react-packager] Use latest babel-core in place of babel (40% perf improvement) 2015-06-30 03:55:21 -08:00
Amjad Masad 6b2c12e300 [react-packager] Update sane to get a new version of fb-watchman (perf) 2015-06-26 17:48:39 -08:00
Amjad Masad 15a0f07c5f [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 737a32417f [react-packager] Injectible file crawlers (2x crawl speedup) 2015-06-24 18:04:57 -08:00
Jing Chen 693fd0bbe5 [events] Add JS require time and fix up some existing logs 2015-06-24 16:59:00 -08:00
Amjad Masad 95800d1564 [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 fef3c7294d [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 bc1f94b7b2 Replace bluebird with promise 2015-06-22 08:44:03 -08:00
Bill Fisher 050f0b3558 [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 695a5c2fbc [react-packager] Cache in-memory file lookups (~200ms win on file change) 2015-06-19 22:47:26 -08:00
Amjad Masad 8faa406e96 [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 0405c82798 [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 4b9d5f8ad0 [react-packager] Add tests to ensure we return all dependency types 2015-06-18 21:27:55 -08:00
Amjad Masad 253544cb45 [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 24026b6c25 [ReactNative] Revert packager ignoring node_modules 2015-06-11 10:45:32 -08:00
Spencer Ahrens 712c52609b [ReactNative] Fix require-time redboxes 2015-06-09 15:42:47 -08:00
Eric Vicenti a2396a6446 Revert [react-packager] Add support for nested node_modules 2015-06-05 08:44:06 -08:00
Amjad Masad db842e2c23 [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 581673ff3a [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 e4da97c24a [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 65103e0c63 [ReactNative] Update sane fork + FileWatcher config 2015-05-28 07:12:41 -08:00
Tadeu Zagallo fddc50b98b [ReactNative] Add option to file watcher to ignore node_modules 2015-05-28 01:18:47 -08:00
Amjad Masad a6a8432100 [react-packager] Introduce buildPackage API 2015-05-22 17:28:27 -08:00
Amjad Masad 61efe8a34b [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 2271166a83 [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
Amjad Masad c9c61222cf [react-packager] Implement getJSModulePaths API 2015-05-20 13:38:46 -08:00
Amjad Masad 46e1404a76 [react-native] Fix source map issue with virtual modules 2015-05-15 15:49:11 -08:00
Amjad Masad e5b939d623 [react-packager] Use transformer name in cache name
Summary:
@public
Shouldn't confuse the cache from files transformed by different transformers. This takes into account the transformer in the cache hash name.

Test Plan:
* start server with --babel
* generate bundle
* start server with --jstransform
* generate bundle
* compare them and they're different
2015-05-13 14:49:28 -08:00
Spencer Ahrens ac49f8ca99 [ReactNative] differentiate fatal and soft exceptions 2015-05-13 13:24:37 -07:00
Nick Lockwood a91b293682 decode pathName when extracting from url 2015-05-13 13:24:36 -07:00
Dmitry Soshnikov 5663456373 [jest] Update to v0.4.2 2015-05-13 13:24:35 -07:00
Alex Kotliarskyi 2f4dcae505 [ReactNative] Register assets with AssetRegistry 2015-05-07 17:27:42 -08:00
Amjad Masad b05ca45244 [react-packager] Use gracful-fs to avoid EMFILE errors
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
2015-05-05 14:30:43 -08:00
Spencer Ahrens 95a120b663 [ReactNative] improve console logging a little bit 2015-05-04 18:57:03 -08:00
Amjad Masad 830646529a [react-packager] Combine source maps coming from transformer
Summary:
@public
Fixes [#393](https://github.com/facebook/react-native/issues/393). Currently the transformer assumes line-preserving compilers and defaults to a super-fast source map generation process. However, we need to support compilers that aren't preserving lines.
I had feared this wuold slow down the server but I came about a little known peace of the spec that defines an "indexed source map" just for the purpose of concating files: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit

Test Plan:
1. runJestTests.sh
2. run server and click around example apps
3. add a custom transporter like babel
4. add a custom file and a debugger statement
5. debug in chrome and make sure it works

redbox still works
2015-05-01 16:59:14 -08:00
Tim Yung 0fde2c2583 JS: Use Object.defineProperty for Array Polyfills 2015-04-28 15:56:40 -08:00
Alex Kotliarskyi fca69ad9d5 [ReactNative] Bump watchman timeout to 25s 2015-04-27 19:30:02 -08:00
Kevin Gozali 2115b67bd9 [ReactNative][madman] Reverted D2014357 2015-04-23 16:04:16 -08:00
Philipp von Weitershausen 0b3ca1c53e [ReactNative] Back out D2014163 entirely 2015-04-23 12:02:47 -08:00
Amjad Masad f635db3b6d [react-packager] Change uri to name 2015-04-23 11:52:00 -08:00
Amjad Masad 91b320cf35 [react-packager] Fix jest tests 2015-04-23 11:39:41 -08:00
Philipp von Weitershausen 240424714e [ReactNative] Disable console.error => redboxes to unwedge Android 2015-04-23 09:56:15 -08:00
Spencer Ahrens 4e96edb8b1 [ReactNative] console.error shows RedBox with pretty stack trace 2015-04-22 15:51:41 -08:00
Amjad Masad d4b5f2e514 [react-packager] Additional data to asset modules 2015-04-22 10:59:37 -08:00
Amjad Masad 2645ffb69a [react-packager] bump watchman watch timeout to 10 seconds 2015-04-21 10:59:29 -08:00
Amjad Masad f91f7084ec [react-packager] Allow json files as modules 2015-04-21 10:51:15 -08:00
Amjad Masad 201d65dead [react-packager] Implement Packager::getAssets 2015-04-20 16:01:15 -08:00
Alex Kotliarskyi f7e2e4114b [ReactNative] Dim packager output 2015-04-17 16:12:25 -08:00
Amjad Masad ed3aaadc39 [react-packager] Add more information to deprecated asset requires 2015-04-17 15:14:13 -08:00
James Ide a68cc06f0b [Errors] Fix Red Box by fixing providesModule parsing
Summary:
cc @amasad

An error occurred while trying to display the Red Box since loadSourceMap was not included in the JS
bundle. This is because node-haste was treating its docblock as a multiline directive which doesn't make sense for `@providesModule`.

In loadSourceMap.js's case, the directive's value was parsed as "loadSourceMap -- disabled flow due to mysterious validation errors --".

There are two fixes: add a newline under the `@providesModule` directive, and change the module ID code to look at only the first token of the directive. I opted for the latter so we avoid this class of bugs entirely and AFAIK it's nonsensical to have multiple `@providesModule` values anyway.

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

Test Plan:  Run the packager, trigger an error in an app, see the red box now show up again.
2015-04-17 09:45:35 -08:00
Peter Cottle 83ee7ad9dd [ReactNative|Easy] Change watchman too-long error message
Summary:
@wez Mentioned this in Issue #239 -- right now when watchman takes too long we recommend you run `watchman` from your terminal which actually expects some arguments, so it prints out the following:

```
[pcottle:~/Desktop/react-native:changeErrorMessage]$ watchman
{
    "error": "invalid command (expected an array with some elements!)",
    "cli_validated": true,
    "version": "3.0.0"
}
```

basically this ends up being more confusing since the command we recommend you run errors out, so lets change it to `watchman version` which at least exists cleanly.

I kept the troubleshooting link as https://facebook.github.io/watchman/docs/troubleshooting.html since it sounds like we will update that with the issue people run into in #239
Closes https://github.com/facebook/react-native/pull/825
Github Author: Peter Cottle <pcottle@fb.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-17 09:16:22 -08:00
Amjad Masad 2fabfdae11 [react-packager] Add asset extensions to file watch glob in the project root 2015-04-17 09:03:41 -08:00
Tadeu Zagallo 4b52f2eacc [ReactNative] Send batched calls from objc to js every frame + add bridge profiling 2015-04-17 04:01:02 -08:00
Amjad Masad f45d032659 [react-packager] Remove links to internal wiki 2015-04-16 13:14:41 -08:00
Amjad Masad 852f8533a1 [react-packager] implement /assets endpoint to serve assets 2015-04-16 13:00:48 -08:00
Amjad Masad a998049c08 [react-packager] Add Array.prototype.es6 polyfill 2015-04-14 15:15:53 -08:00
Amjad Masad 4a3e69ec74 [react-packager] Support @nx resolution postfix for assets 2015-04-14 10:43:39 -08:00
Tim Yung 39da8034dd React Native: Add String.prototyp.es6 Polyfill 2015-04-13 13:25:35 -08:00
Amjad Masad 4b9ec6c5f7 [react-packager] Correct module extension regexp 2015-04-09 12:07:23 -08:00
Amjad Masad 21f1497418 [react-packager] Implement the browser field package.json spec 2015-04-09 11:59:48 -08:00
Amjad Masad 408160de7d [react-packager] Don't depend on error.stack being available 2015-04-08 14:23:18 -08:00
Amjad Masad f88167157c [react-packager] Implement new style asset packaging (with dimensions) 2015-04-08 13:11:21 -08:00
Spencer Ahrens 061de15c1c [ReactNative] Do flow check when running packager 2015-04-07 21:40:05 -08:00
Amjad Masad 31e0018c1c [react-packager] Deprecate global image namespace in favor of CommonJS resolution 2015-04-03 17:19:10 -08:00
Amjad Masad e22b4e000b [react-packager] Don't cache rejected promise 2015-04-03 15:47:26 -08:00
Pilwon Huh d476461120 react-packager: Add ES6 import statement support to DependencyGraph.
Summary:
This PR teaches packager's `DependencyGraph` how to extract dependencies written with ES6 `import` statements.

It fixes the issue where you are not able to write your app with ES6 `import` statements when your custom transformer (replacing the default [JSTransform](https://github.com/facebook/jstransform), for example, [babel](http://babeljs.io/)) already supports the ES6 `import` syntax.

It will also be useful for [JSTransform](https://github.com/facebook/jstransform) later on once it implements `import` feature too.
Closes https://github.com/facebook/react-native/pull/386
Github Author: Pilwon Huh <pilwon@gmail.com>

Test Plan: runJestTests.sh
2015-04-03 11:40:54 -08:00
Amjad Masad bedd4029c8 [react-packager] Ignore dotfiles in file watching 2015-04-02 06:11:16 -08:00
Jacob Gable ab9f78496f Do not expose define references in require polyfill
Summary:
See #406

Made sure the jest tests pass but didn't know a good unit test to add for this.
Closes https://github.com/facebook/react-native/pull/427
Github Author: Jacob Gable <jacob.gable@gmail.com>

Test Plan:
* ./runJestTests
* start app and click around
2015-03-31 22:32:39 -08:00
Pilwon Huh 7f6255b16f [react-packager] Switch from Q to Bluebird as promises library
Summary:
This PR improves performance of `react-packager` by switching the promises library from the [Q](https://github.com/kriskowal/q) to [Bluebird](https://github.com/petkaantonov/bluebird).

[Here is the test result](https://github.com/facebook/react-native/issues/361#issuecomment-87829808) showing a noticeable difference. (2x speed improvement)

Please refer to [this issue](https://github.com/facebook/react-native/issues/361) for more details.
Closes https://github.com/facebook/react-native/pull/516
Github Author: Pilwon Huh <pilwon@gmail.com>

Test Plan:
./runJestTests
start app and click around
2015-03-31 21:24:13 -08:00
Amjad Masad 69ae1bb3b7 [react-packager] Fix EISDIR error 2015-03-31 19:49:05 -08:00
daviskoh 28a0a2586d Bugfix/require module regexp
Summary:
Resolves https://github.com/facebook/react-native/issues/316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome!
Closes https://github.com/facebook/react-native/pull/368
Github Author: daviskoh <koh.davis.0@gmail.com>

Test Plan: ./runJestTests
2015-03-31 17:37:39 -08:00
Amjad Masad e306f4e8d5 [react-packager] Inherit from Error correctly 2015-03-27 21:47:19 -08:00
Amjad Masad 4a67c84426 [react-packager] Watch asset roots for changes to update dependency graph 2015-03-27 09:18:00 -08:00
Amjad Masad b2eba1072b [react-packager] Fix node v0.11.14 query parse bug 2015-03-26 14:33:33 -08:00
Amjad Masad f68c24069e [react-packager] better error when main file not found 2015-03-26 10:38:50 -08:00
Amjad Masad ec1b9ec735 [react-packager] kill non-standard RAW_SOURCE_MAP 2015-03-24 17:17:02 -08:00
Amjad Masad bef3d46cee [react-packager] Fix more issues with node modules 2015-03-24 16:07:56 -08:00
Amjad Masad fc92348d8b [react-packager] Fix regression with transform errors 2015-03-23 18:55:36 -08:00
Alex Kotliarskyi 7e2b9bfd77 [ReactNative] Remove `arc build` instructions from require 2015-03-23 17:18:19 -08:00
Amjad Masad 81634084bc [react-packager] Default to index.js from main if it's a dir 2015-03-23 14:55:52 -08:00
Christopher Chedeau a2c32d4d29 [ReactNative] Expanded license on js packager files 2015-03-23 11:28:51 -08:00
Amjad Masad 375797ae36 [react-packager] Pick up package changes while running 2015-03-23 11:15:52 -08:00
Amjad Masad 01c8933949 [react-packager] Allow entry point extensions like .ios.js 2015-03-20 17:24:51 -08:00
Amjad Masad 2e2f3b3d9b [react-packager] Hash cache file name information to avoid long names 2015-03-19 16:40:35 -08:00
Amjad Masad 566a177464 [react-packager] Fix OOM 2015-03-19 11:50:27 -08:00
Amjad Masad ace7e3613f [react-packager] Add assetRoots option 2015-03-18 18:26:35 -08:00
Martin Kosiba 8a1b71c287 [react_native] JS files from D1919491: Improve JS logging 2015-03-18 07:30:18 -08:00
Amjad Masad be992c90e9 [react-packager] small fixes to image loader 2015-03-16 14:45:40 -08:00
Christopher Chedeau 6dfa8c0e4d [ReactNative] Fix File Watcher test 2015-03-14 16:50:54 -08:00
Amjad Masad d2cf0de12e [react-packager] Implement image loading i.e. ix('img') -> require('image!img'); 2015-03-13 16:10:58 -08:00
Amjad Masad 7874698b6b [react-packager] onchange endpoint that informs of changes 2015-03-06 15:28:32 -08:00
Amjad Masad 50220f1384 [react-packager] dev option needs to default to true for backwards compat 2015-03-06 14:45:23 -08:00
Amjad Masad 3d92dd422c [react-packager] Add minify option as query param 2015-03-05 12:12:42 -08:00
Amjad Masad a4d041ce62 [react-packager] Make dev a query param option 2015-03-04 21:24:08 -08:00
Amjad Masad 5bd8155f0b [react-packager] Start converting options to query params 2015-03-04 19:06:51 -08:00
Amjad Masad 41743e5987 [react-packager] Recover and warn from corrupted cache file 2015-03-03 17:49:42 -08:00
Amjad Masad 37cab152b5 [react-packager] check-in node_modules and update tests 2015-03-03 02:02:51 -08:00
Amjad Masad c289844144 [react-packager] Implement bundle minification 2015-03-02 23:19:41 -08:00