mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 19:44:13 +00:00
Allow to pass regular expressions to buildRegExps
Summary: Allows to use `setupBabel.buildRegExps` with regular expressions, not only with strings. Reviewed By: mjesun Differential Revision: D5614738 fbshipit-source-id: ccad4d49f8d2006a714833989b3c6be2ce7071ab
This commit is contained in:
parent
41504103ce
commit
475cf1ad29
@ -13,9 +13,7 @@ const babelRegisterOnly = require('metro-bundler/src/babelRegisterOnly');
|
|||||||
const escapeRegExp = require('lodash/escapeRegExp');
|
const escapeRegExp = require('lodash/escapeRegExp');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const BABEL_ENABLED_PATHS = [
|
const BABEL_ENABLED_PATHS = ['local-cli'];
|
||||||
'local-cli',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@ -23,10 +21,22 @@ const BABEL_ENABLED_PATHS = [
|
|||||||
* have the same name as one of `BABEL_ENABLED_PATHS`.
|
* have the same name as one of `BABEL_ENABLED_PATHS`.
|
||||||
*/
|
*/
|
||||||
function buildRegExps(basePath, dirPaths) {
|
function buildRegExps(basePath, dirPaths) {
|
||||||
return dirPaths.map(folderPath =>
|
return dirPaths.map(
|
||||||
|
folderPath =>
|
||||||
// Babel `only` option works with forward slashes in the RegExp so replace
|
// Babel `only` option works with forward slashes in the RegExp so replace
|
||||||
// backslashes for Windows.
|
// backslashes for Windows.
|
||||||
new RegExp(`^${escapeRegExp(path.resolve(basePath, folderPath).replace(/\\/g, '/'))}`)
|
folderPath instanceof RegExp
|
||||||
|
? new RegExp(
|
||||||
|
`^${escapeRegExp(
|
||||||
|
path.resolve(basePath, '.').replace(/\\/g, '/'),
|
||||||
|
)}/${folderPath.source}`,
|
||||||
|
folderPath.flags,
|
||||||
|
)
|
||||||
|
: new RegExp(
|
||||||
|
`^${escapeRegExp(
|
||||||
|
path.resolve(basePath, folderPath).replace(/\\/g, '/'),
|
||||||
|
)}`,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user