2015-09-16 17:30:53 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2017-05-09 15:02:08 +00:00
|
|
|
*
|
2017-07-13 02:22:43 +00:00
|
|
|
* @flow
|
2015-09-16 17:30:53 +00:00
|
|
|
*/
|
2017-07-12 20:48:49 +00:00
|
|
|
|
|
|
|
/* eslint-env node */
|
|
|
|
|
2015-09-16 17:30:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2016-07-15 13:25:27 +00:00
|
|
|
const babel = require('babel-core');
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2017-06-25 00:04:27 +00:00
|
|
|
const babelRegisterOnly = require('metro-bundler/src/babelRegisterOnly');
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2015-09-19 22:20:25 +00:00
|
|
|
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
|
2015-09-16 17:30:53 +00:00
|
|
|
|
2017-07-13 02:22:43 +00:00
|
|
|
const nodeFiles = RegExp([
|
|
|
|
'/local-cli/',
|
|
|
|
'/metro-bundler/',
|
|
|
|
].join('|'));
|
2016-07-15 13:25:27 +00:00
|
|
|
const nodeOptions = babelRegisterOnly.config([nodeFiles]);
|
|
|
|
|
create better debuggable source maps
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
2017-01-12 22:21:59 +00:00
|
|
|
babelRegisterOnly([]);
|
|
|
|
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2017-06-25 00:04:27 +00:00
|
|
|
const transformer = require('metro-bundler/src/transformer.js');
|
2015-09-16 17:30:53 +00:00
|
|
|
module.exports = {
|
2017-07-13 02:22:43 +00:00
|
|
|
process(src/*: string*/, file/*: string*/) {
|
|
|
|
if (nodeFiles.test(file)) { // node specific transforms only
|
|
|
|
return babel.transform(
|
|
|
|
src,
|
|
|
|
Object.assign({filename: file}, nodeOptions)
|
|
|
|
).code;
|
2015-09-22 19:11:13 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 15:32:04 +00:00
|
|
|
return transformer.transform({
|
|
|
|
filename: file,
|
2017-05-11 23:37:07 +00:00
|
|
|
localPath: file,
|
2017-05-11 15:32:04 +00:00
|
|
|
options: {
|
|
|
|
dev: true,
|
|
|
|
inlineRequires: true,
|
|
|
|
platform: '',
|
|
|
|
projectRoot: '',
|
2017-06-14 16:25:53 +00:00
|
|
|
retainLines: true,
|
2017-05-11 15:32:04 +00:00
|
|
|
},
|
|
|
|
src,
|
2017-05-09 15:02:08 +00:00
|
|
|
}).code;
|
2015-09-19 22:20:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getCacheKey: createCacheKeyFunction([
|
|
|
|
__filename,
|
2017-06-25 00:04:27 +00:00
|
|
|
require.resolve('metro-bundler/src/transformer.js'),
|
2016-01-18 14:02:16 +00:00
|
|
|
require.resolve('babel-core/package.json'),
|
2015-09-19 22:20:25 +00:00
|
|
|
]),
|
2015-09-16 17:30:53 +00:00
|
|
|
};
|