mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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.
22 lines
626 B
JavaScript
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;
|