diff --git a/packages/metro-babel-register/src/babel-register.js b/packages/metro-babel-register/src/babel-register.js index 5a4cde54f1..7717849107 100644 --- a/packages/metro-babel-register/src/babel-register.js +++ b/packages/metro-babel-register/src/babel-register.js @@ -55,21 +55,21 @@ function config(onlyList) { * have the same name as one of `BABEL_ENABLED_PATHS`. */ function buildRegExps(basePath, dirPaths) { + // Babel `only` option works with forward slashes in the RegExp so replace + // them for Windows (only v7 beta 44 ~ 52 temporarily changes this behavior) return dirPaths.map( folderPath => - // 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, '.') + path.sep)}${ - folderPath.source // This is actual regex, don't escape it - }`, - folderPath.flags, + `^${escapeRegExp( + path.resolve(basePath, '.').replace(/\\/g, '/'), + )}/${folderPath.source}`, ) - : new RegExp('^' + escapeRegExp(path.resolve(basePath, folderPath))), + : new RegExp( + `^${escapeRegExp( + path.resolve(basePath, folderPath).replace(/\\/g, '/'), + )}`, + ), ); }