Skip to content

Commit

Permalink
added support for reading named exports from ESM files
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Feb 12, 2023
1 parent 7d057dd commit 2498fe8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/utils/requireModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ module.exports = function (fullpath) {
if (getNodeVersion() >= 14) {
const {pathToFileURL} = require('node:url');

return import(pathToFileURL(fullpath).href).then(result => (result.default || {}));
return import(pathToFileURL(fullpath).href).then(result => {
const _default = result.default || {};

return Object.keys(result).reduce((prev, val) => {
if (val !== 'default') {
prev[val] = result[val];
}

return prev;
}, _default);
});
}

return import(fullpath).then(result => (result.default || {}));
Expand Down

0 comments on commit 2498fe8

Please sign in to comment.