Skip to content

Commit

Permalink
Fix exports walk (#852) (#853)
Browse files Browse the repository at this point in the history
* Fix exports walk (#852)

Fixes #852

* Create eight-toes-pump.md

* traverse default exports in type:module packages
  • Loading branch information
developit authored Oct 6, 2021
1 parent 5d0465b commit 5e93a0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-toes-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"microbundle": patch
---

Fix crash when traversing `"exports"` objects (#852)
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ function replaceName(filename, name) {
);
}

function walk(exports) {
function walk(exports, includeDefault) {
if (!exports) return null;
if (typeof exports === 'string') return exports;
return walk(exports['.'] || exports.import || exports.module);
let p = exports['.'] || exports.import || exports.module;
if (!p && includeDefault) p = exports.default;
return walk(p, includeDefault);
}

function getMain({ options, entry, format }) {
Expand Down Expand Up @@ -296,7 +299,7 @@ function getMain({ options, entry, format }) {
mainNoExtension,
);
mainsByFormat.modern = replaceName(
(pkg.exports && walk(pkg.exports)) ||
(pkg.exports && walk(pkg.exports, pkg.type === 'module')) ||
(pkg.syntax && pkg.syntax.esmodules) ||
pkg.esmodule ||
'x.modern.js',
Expand Down

0 comments on commit 5e93a0e

Please sign in to comment.