Fix exports walk (#852) (#853)

* Fix exports walk (#852)

Fixes #852

* Create eight-toes-pump.md

* traverse default exports in type:module packages
This commit is contained in:
Jason Miller 2021-10-06 09:59:44 -04:00 committed by GitHub
parent 5d0465b39b
commit 5e93a0e4cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"microbundle": patch
---
Fix crash when traversing `"exports"` objects (#852)

View File

@ -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 }) {
@ -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',