-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issues on win32 and over-matching
- Loading branch information
1 parent
2adf85a
commit 68fd811
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
'use strict'; | ||
|
||
var path = require('path') | ||
, escapeStringRegexp = require('escape-string-regexp') | ||
, ESCAPED_NODE_MODULES = escapeStringRegexp('node_modules') | ||
, ESCAPED_PATH_SEP = escapeStringRegexp(path.sep); | ||
|
||
/** | ||
* @module | ||
* @author Oleg Dutchenko <[email protected]> | ||
* @version 1.0.0 | ||
* @version 1.0.2 | ||
*/ | ||
|
||
// ---------------------------------------- | ||
|
@@ -17,10 +22,30 @@ | |
* @return {RegExp} | ||
*/ | ||
function babelLoaderExcludeNodeModulesExcept (exceptionList) { | ||
var normalizedExceptionList | ||
, alternationGroup | ||
, negativeLookahead | ||
|
||
if (Array.isArray(exceptionList) && exceptionList.length) { | ||
return new RegExp(`node_modules[\\/|\\\\](?!(${exceptionList.join('|')})).*`, 'i'); | ||
// Module names can contain path separators, e.g. "@types/react". | ||
// Assume POSIX input and normalize for the current platform. | ||
normalizedExceptionList = exceptionList.map(function (moduleName) { | ||
// We'll handle trailing path separators when we build the | ||
// negative lookahead, so remove them if present. | ||
if (moduleName[moduleName.length - 1] === path.posix.sep) { | ||
moduleName = moduleName.slice(0, -1); | ||
} | ||
return moduleName.split(path.posix.sep).join(path.sep); | ||
}); | ||
alternationGroup = '(' + normalizedExceptionList.map(escapeStringRegexp).join('|') + ')'; | ||
// If the exception list includes e.g. "react", we don't want to | ||
// accidentally make an exception for "react-dom", so make sure to | ||
// include a trailing path separator inside the negative lookahead. | ||
negativeLookahead = '(?!' + alternationGroup + ESCAPED_PATH_SEP + ')'; | ||
return new RegExp(ESCAPED_NODE_MODULES + ESCAPED_PATH_SEP + negativeLookahead, 'i'); | ||
} else { | ||
return new RegExp(ESCAPED_NODE_MODULES, 'i'); | ||
} | ||
return /node_modules/i; | ||
} | ||
|
||
// ---------------------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters