Add metro to paths to be babel-transformed

Reviewed By: fkgozali

Differential Revision: D7620341

fbshipit-source-id: fc801c938628f5b6b118b8250d5c63268e19359e
This commit is contained in:
Peter van der Zee 2018-04-13 14:10:43 -07:00 committed by Facebook Github Bot
parent 7500b3ec83
commit af661e4a6f

View File

@ -11,7 +11,7 @@ const babelRegisterOnly = require('metro/src/babelRegisterOnly');
const escapeRegExp = require('lodash/escapeRegExp'); const escapeRegExp = require('lodash/escapeRegExp');
const path = require('path'); 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 * 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) { function buildRegExps(basePath, dirPaths) {
return dirPaths.map( return dirPaths.map(
folderPath => folderPath =>
// Babel `only` option works with forward slashes in the RegExp so replace folderPath === 'metro'
// backslashes for Windows. // metro uses flow (for example) which needs to be stripped out w/babel.
folderPath instanceof RegExp // it'll resolve to .../metro/packages/metro/src/index.js we want root
? new RegExp( ? path.resolve(require.resolve('metro'), '..', '..', '..', '..')
`^${escapeRegExp( // Babel `only` option works with forward slashes in the RegExp so replace
path.resolve(basePath, '.').replace(/\\/g, '/') // backslashes for Windows.
)}/${folderPath.source}`, : folderPath instanceof RegExp
folderPath.flags ? new RegExp(
) `^${escapeRegExp(
: new RegExp( path.resolve(basePath, '.').replace(/\\/g, '/')
`^${escapeRegExp( )}/${folderPath.source}`,
path.resolve(basePath, folderPath).replace(/\\/g, '/') folderPath.flags
)}` )
) : new RegExp(
`^${escapeRegExp(
path.resolve(basePath, folderPath).replace(/\\/g, '/')
)}`
)
); );
} }