From 2498fe8daf7598c2f2bf3c94f626e65e6f29d901 Mon Sep 17 00:00:00 2001 From: Andrei Rusu Date: Sun, 12 Feb 2023 16:24:11 +0100 Subject: [PATCH] added support for reading named exports from ESM files --- lib/utils/requireModule.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils/requireModule.js b/lib/utils/requireModule.js index f65315e8d4..d476fe8bd6 100644 --- a/lib/utils/requireModule.js +++ b/lib/utils/requireModule.js @@ -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 || {}));