From af661e4a6f6583b4c2b372a22d71f41470760d93 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Fri, 13 Apr 2018 14:10:43 -0700 Subject: [PATCH] Add metro to paths to be babel-transformed Reviewed By: fkgozali Differential Revision: D7620341 fbshipit-source-id: fc801c938628f5b6b118b8250d5c63268e19359e --- setupBabel.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/setupBabel.js b/setupBabel.js index 15e0f19a458bb2..0b21ffe31f5c7d 100644 --- a/setupBabel.js +++ b/setupBabel.js @@ -11,7 +11,7 @@ const babelRegisterOnly = require('metro/src/babelRegisterOnly'); const escapeRegExp = require('lodash/escapeRegExp'); const path = require('path'); -const BABEL_ENABLED_PATHS = ['local-cli']; +const BABEL_ENABLED_PATHS = ['local-cli', 'metro']; /** * We use absolute paths for matching only the top-level folders reliably. For @@ -21,20 +21,24 @@ const BABEL_ENABLED_PATHS = ['local-cli']; function buildRegExps(basePath, dirPaths) { return dirPaths.map( folderPath => - // Babel `only` option works with forward slashes in the RegExp so replace - // backslashes for Windows. - folderPath instanceof RegExp - ? new RegExp( - `^${escapeRegExp( - path.resolve(basePath, '.').replace(/\\/g, '/') - )}/${folderPath.source}`, - folderPath.flags - ) - : new RegExp( - `^${escapeRegExp( - path.resolve(basePath, folderPath).replace(/\\/g, '/') - )}` - ) + folderPath === 'metro' + // metro uses flow (for example) which needs to be stripped out w/babel. + // it'll resolve to .../metro/packages/metro/src/index.js we want root + ? path.resolve(require.resolve('metro'), '..', '..', '..', '..') + // Babel `only` option works with forward slashes in the RegExp so replace + // backslashes for Windows. + : folderPath instanceof RegExp + ? new RegExp( + `^${escapeRegExp( + path.resolve(basePath, '.').replace(/\\/g, '/') + )}/${folderPath.source}`, + folderPath.flags + ) + : new RegExp( + `^${escapeRegExp( + path.resolve(basePath, folderPath).replace(/\\/g, '/') + )}` + ) ); }