Skip to content

Commit

Permalink
Add metro to paths to be babel-transformed
Browse files Browse the repository at this point in the history
Reviewed By: fkgozali

Differential Revision: D7620341

fbshipit-source-id: fc801c938628f5b6b118b8250d5c63268e19359e
  • Loading branch information
Peter van der Zee authored and facebook-github-bot committed Apr 13, 2018
1 parent 7500b3e commit af661e4
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions setupBabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'), '..', '..', '..', '..')

This comment has been minimized.

Copy link
@janicduplessis

janicduplessis Apr 19, 2018

Contributor

This breaks OSS since the path to metro is not the same. It needs to be 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, '/')
)}`
)
);
}

Expand Down

0 comments on commit af661e4

Please sign in to comment.