Created
May 17, 2018 11:06
-
-
Save IhostVlad/3b4921d9e4e94f4f3ece4bfcc1d74bcc to your computer and use it in GitHub Desktop.
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
function conditionalRequireModuleByPath(modulePath, condition) { | |
try { | |
var packageJson = require(path.join(modulePath, './package.json')) | |
if (condition(packageJson)) { | |
return require(path.join( | |
modulePath, | |
'./', | |
packageJson.main || 'index.js' | |
)) | |
} | |
} catch (err) {} | |
return null | |
} | |
function loadBabelCoreVersions() { | |
var pathBabelCoreRoot = path.join(__dirname, '../node_modules/babel-core') | |
var pathBabelCore6 = path.join( | |
__dirname, | |
'../node_modules/babelcore6/node_modules/babel-core/' | |
) | |
var pathBabelCore7 = path.join( | |
__dirname, | |
'../node_modules/babelcore7/node_modules/babel-core/' | |
) | |
var checkVersion6 = function(info) { | |
return info.version.indexOf('6') === 0 | |
} | |
var checkVersion7 = function(info) { | |
return info.version.indexOf('7') === 0 | |
} | |
var babel6 = | |
conditionalRequireModuleByPath(pathBabelCoreRoot, checkVersion6) || | |
conditionalRequireModuleByPath(pathBabelCore6, checkVersion6) | |
var babel7 = | |
conditionalRequireModuleByPath(pathBabelCoreRoot, checkVersion7) || | |
conditionalRequireModuleByPath(pathBabelCore7, checkVersion7) | |
return { | |
babel6: babel6, | |
babel7: babel7 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment