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, '/') + )}` + ) ); }