From 50145b659f9b327cc60f81180fc701ed52422ee8 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sat, 30 Apr 2016 16:24:55 -0700 Subject: [PATCH] Use a separate babel config for the local-cli and the packager Summary: This separates the babel config of the local-cli and the packager from the one used by the transforms of the packager since it doesn't run in the same environment and the local-cli/packager doesn't require react specific transforms and runs in node 4 so we can also avoid some es2015 transforms that node already supports. I had to move the code in cli.js so it can still run in node 0.12 that doesn't support `const` since it is no longer transformed. **Test plan** Run the local-cli on node 0.12 and there should be a message saying that it requires at least node 4. Run the local-cli on node 4 and 5 and everything should work the same as before. I was also hoping for some perf gains but there was nothing noticeable. I did benchmark the babel-register call and it stayed pretty much the same. As for runtime performance it can help if there are optimisations for es2015 features in node. Closes https://github.com/facebook/react-native/pull/6155 Differential Revision: D3242754 Pulled By: davidaurelio fb-gh-sync-id: 02880c841c10562d5f107e1c975d668e55cc619f fbshipit-source-id: 02880c841c10562d5f107e1c975d668e55cc619f --- babelRegisterOnly.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/babelRegisterOnly.js b/babelRegisterOnly.js index bb973ba4..703ba338 100644 --- a/babelRegisterOnly.js +++ b/babelRegisterOnly.js @@ -12,20 +12,19 @@ Array.prototype.values || require('core-js/fn/array/values'); Object.entries || require('core-js/fn/object/entries'); Object.values || require('core-js/fn/object/values'); -var fs = require('fs'); -var path = require('path'); - var _only = []; -function readBabelRC() { - var rcpath = path.join(__dirname, 'react-packager', 'rn-babelrc.json'); - var source = fs.readFileSync(rcpath).toString(); - return JSON.parse(source); -} - module.exports = function(onlyList) { _only = _only.concat(onlyList); - var config = readBabelRC(); - config.only = _only; - require('babel-register')(config); + + require('babel-register')({ + presets: ['es2015-node'], + plugins: [ + 'transform-flow-strip-types', + 'syntax-trailing-function-commas', + 'transform-object-rest-spread', + ], + only: _only, + sourceMaps: 'inline', + }); };