Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.
This mechanism is only used when building development bundles to improve the debugging experience in Chrome.
The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.
Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.
The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.
In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.
Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.
Reviewed By: jeanlauliac
Differential Revision: D4382290
fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
Summary:
Adds a high performance source map builder that has certain restrictions compared to the `'source-map'` package:
- mappings have to be in the order of the generated source
- source files have to be started/ended separately on the generator. That means building up mappings is optimized for blocks of mappings that all belong to the same source file (or no file)
The implementation avoids allocation of complex value, i.e. strings and objects as much as possible by preallocating a buffer and using numeric character values throughout. The buffer is converted to a string only at the end.
This implementation is ~5✕ faster than using `'source-map'`.
Reviewed By: jeanlauliac
Differential Revision: D4392260
fbshipit-source-id: 406381302d951b919243a2b15e8bb75981e9f979
Summary: Remove the validateOpts() that prevents full Flow typing. In turn, having full Flow typing will allow us to remove 'defaults' across the codebase, that are source of inconsistencies.
Reviewed By: davidaurelio, cpojer
Differential Revision: D4377823
fbshipit-source-id: 8bb0a6b5069de64a9bb9d63892cd08854da91777
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
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
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
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
Summary:
${REACT_NATIVE_DIR} needs to be quoted as "${REACT_NATIVE_DIR}" otherwise projects paths with spaces in, will fail to build.
e.g. a project in `/home/me/some folder` will fail to build with:
```
../node_modules/react-native/packager/react-native-xcode.sh: line 37: cd: /home/me/some: No such file or directory
```
Closes https://github.com/facebook/react-native/pull/11487
Differential Revision: D4336281
Pulled By: lacker
fbshipit-source-id: c5d19fbd21978714c7af44c305ba854477118e1d
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
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
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
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
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
Summary: Adds a helper to produce index source maps for Buck builds
Reviewed By: cpojer
Differential Revision: D4265911
fbshipit-source-id: 9ca3c49876df5db039bae823c0458c98e6e05619
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
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
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
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