Explorar el Código

fix(api): correctly merge pkg exports in `after-build.js` script (#1609)

Amr Bashir hace 4 años
padre
commit
ba208b7e9b
Se han modificado 1 ficheros con 22 adiciones y 18 borrados
  1. 22 18
      tooling/api/scripts/after-build.cjs

+ 22 - 18
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))
 
 /**