Skip to content

Instantly share code, notes, and snippets.

@IhostVlad
Created May 17, 2018 11:06
Show Gist options
  • Save IhostVlad/3b4921d9e4e94f4f3ece4bfcc1d74bcc to your computer and use it in GitHub Desktop.
Save IhostVlad/3b4921d9e4e94f4f3ece4bfcc1d74bcc to your computer and use it in GitHub Desktop.
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