Skip to content

Commit

Permalink
Fix regex paths for Windows
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D8735223

fbshipit-source-id: 646f03a6192699a8f890e19cdcafee1631332251
  • Loading branch information
Peter van der Zee authored and rafeca committed Jul 11, 2018
1 parent de5df97 commit 33c1a8b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/metro-babel-register/src/babel-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@ function config(onlyList) {
function buildRegExps(basePath, dirPaths) {
return dirPaths.map(
folderPath =>
// Babel `only` option works with forward slashes in the RegExp so replace
// backslashes for Windows.
// Babel cares about windows/unix paths since v7b44
// https://github.com/babel/babel/issues/8184
// basePath + path.sep + dirPath/dirRegex
// /home/name/webroot/js + / + relative/path/to/exclude
// c:\home\name\webroot\js + \ + relative\path\to\exclude
folderPath instanceof RegExp
? new RegExp(
`^${escapeRegExp(
path.resolve(basePath, '.').replace(/\\/g, '/'),
)}/${folderPath.source}`,
`^${escapeRegExp(path.resolve(basePath, '.') + path.sep)}${
folderPath.source // This is actual regex, don't escape it
}`,
folderPath.flags,
)
: new RegExp(
`^${escapeRegExp(
path.resolve(basePath, folderPath).replace(/\\/g, '/'),
)}`,
),
: new RegExp('^' + escapeRegExp(path.resolve(basePath, folderPath))),
);
}

Expand Down

0 comments on commit 33c1a8b

Please sign in to comment.