From ba208b7e9ba8b7170e6fa523023c61452ea3e994 Mon Sep 17 00:00:00 2001 From: Amr Bashir <48618675+amrbashir@users.noreply.github.com> Date: Sat, 24 Apr 2021 14:43:29 +0200 Subject: [PATCH] fix(api): correctly merge pkg exports in `after-build.js` script (#1609) --- tooling/api/scripts/after-build.cjs | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tooling/api/scripts/after-build.cjs b/tooling/api/scripts/after-build.cjs index f57b69f99..d4941c3c2 100644 --- a/tooling/api/scripts/after-build.cjs +++ b/tooling/api/scripts/after-build.cjs @@ -13,25 +13,29 @@ const modules = readdirSync('src').map((mod) => mod.replace('.ts', '')) if (!pkg.exports) { pkg.exports = {} } -const outputPkg = Object.assign( - pkg.exports, - ...modules.map((mod) => { - let temp = {} - let key = `./${mod}` - if (mod === 'index') { - key = '.' - } - temp[key] = { - import: `./${mod}.js`, - require: `./${mod}.cjs` - } - return temp - }), - // if for some reason in the future we manually add something in the `exports` field - // this will ensure it doesn't get overwritten by the logic above - { ...pkg.exports } -) +const outputPkg = { + ...pkg, + exports: Object.assign( + {}, + ...modules.map((mod) => { + let temp = {} + let key = `./${mod}` + if (mod === 'index') { + key = '.' + } + + temp[key] = { + import: `./${mod}.js`, + require: `./${mod}.cjs` + } + return temp + }), + // if for some reason in the future we manually add something in the `exports` field + // this will ensure it doesn't get overwritten by the logic above + { ...pkg.exports } + ) +} writeFileSync('dist/package.json', JSON.stringify(outputPkg, undefined, 2)) /**