Files
atom/src/module-utils.js
Amin Yahyaabadi bd189ebce9 support ES6 default require for packages (#21112)
This allows loading the packages that are Es module and export their function wrapped in a default object. This is the case for any package that uses Babel 6, Babel 7, or other modern compilers for transpiling their package.
2020-11-18 10:57:21 +03:00

22 lines
626 B
JavaScript

// a require function with both ES5 and ES6 default export support
function requireModule(path) {
const modul = require(path);
if (modul === null || modul === undefined) {
// if null do not bother
return modul;
} else {
if (
modul.__esModule === true &&
(modul.default !== undefined && modul.default !== null)
) {
// __esModule flag is true and default is exported, which means that
// an object containing the main functions (e.g. activate, etc) is default exported
return modul.default;
} else {
return modul;
}
}
}
exports.requireModule = requireModule;