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
This commit is contained in:
Martín Bigio 2015-10-08 17:36:12 -07:00 committed by facebook-github-bot-4
parent 42d756310a
commit 32b62ef055
3 changed files with 18 additions and 3 deletions

16
babelRegisterOnly.js Normal file
View File

@ -0,0 +1,16 @@
/**
* 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.
*/
'use strict';
var _only = [];
module.exports = function(onlyList) {
_only = _only.concat(onlyList);
require('babel-core/register')({only: _only});
};

View File

@ -8,7 +8,7 @@
*/
'use strict';
require('babel-core/register')();
require('../../babelRegisterOnly')([/react-packager\/src/]);
useGracefulFs();

View File

@ -8,8 +8,7 @@
*/
'use strict';
// trigger babel-core/register
require('../packager/react-packager');
require('../babelRegisterOnly')([/private-cli\/src/]);
var cli = require('./src/cli');
var fs = require('fs');