-
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.
Refactored index.js to match the new code style
- Loading branch information
1 parent
2a39941
commit f62778b
Showing
1 changed file
with
16 additions
and
31 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,57 +1,42 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @module | ||
* @author Oleg Dutchenko <dutchenko.o.dev@gmail.com> | ||
* @version 1.0.3 | ||
* @contributors | ||
* - April Arcus {@link https://github.com/AprilArcus} | ||
*/ | ||
|
||
var path = require('path') | ||
, escapeStringRegexp = require('escape-string-regexp') | ||
, ESCAPED_NODE_MODULES = escapeStringRegexp('node_modules') | ||
, ESCAPED_PATH_SEP = escapeStringRegexp(path.sep); | ||
|
||
// ---------------------------------------- | ||
// Public | ||
// ---------------------------------------- | ||
const path = require('path'); | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
const ESCAPED_NODE_MODULES = escapeStringRegexp('node_modules'); | ||
const ESCAPED_PATH_SEP = escapeStringRegexp(path.sep); | ||
|
||
/** | ||
* Creating a regular expression for excluding node modules | ||
* from babel transpiling except for individual modules | ||
* @param {string[]} [exceptionList] - exclude all modules except this list | ||
* @return {RegExp} | ||
*/ | ||
function babelLoaderExcludeNodeModulesExcept (exceptionList) { | ||
var normalizedExceptionList | ||
, alternationGroup | ||
, negativeLookahead | ||
|
||
function babelLoaderExcludeNodeModulesExcept(exceptionList) { | ||
if (Array.isArray(exceptionList) && exceptionList.length) { | ||
// Module names can contain path separators, e.g. "@types/react". | ||
// Assume POSIX input and normalize for the current platform. | ||
normalizedExceptionList = exceptionList.map(function (moduleName) { | ||
const 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('|') + ')'; | ||
|
||
const 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'); | ||
const negativeLookahead = '(?!' + alternationGroup + ESCAPED_PATH_SEP + ')'; | ||
|
||
return new RegExp( | ||
ESCAPED_NODE_MODULES + ESCAPED_PATH_SEP + negativeLookahead, | ||
'i' | ||
); | ||
} else { | ||
return new RegExp(ESCAPED_NODE_MODULES, 'i'); | ||
} | ||
} | ||
|
||
// ---------------------------------------- | ||
// Exports | ||
// ---------------------------------------- | ||
|
||
module.exports = babelLoaderExcludeNodeModulesExcept; |