From 585e77d719a9862fbfdfeee641b7e83bcf04c18f Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sat, 12 Jun 2021 16:12:11 -0400 Subject: [PATCH 1/3] Fix exports walk (#852) Fixes #852 --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 6793c3e8..17a5741f 100644 --- a/src/index.js +++ b/src/index.js @@ -260,6 +260,7 @@ function replaceName(filename, name) { } function walk(exports) { + if (!exports) return null; if (typeof exports === 'string') return exports; return walk(exports['.'] || exports.import || exports.module); } From c469714ce8fefdc3582fd385fcc7b4ec89bb6f7d Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sat, 12 Jun 2021 16:13:37 -0400 Subject: [PATCH 2/3] Create eight-toes-pump.md --- .changeset/eight-toes-pump.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eight-toes-pump.md diff --git a/.changeset/eight-toes-pump.md b/.changeset/eight-toes-pump.md new file mode 100644 index 00000000..bd89f985 --- /dev/null +++ b/.changeset/eight-toes-pump.md @@ -0,0 +1,5 @@ +--- +"microbundle": patch +--- + +Fix crash when traversing `"exports"` objects (#852) From 9a9b45c99c43e620881239b004997db0f2afba82 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 6 Oct 2021 09:19:04 -0400 Subject: [PATCH 3/3] traverse default exports in type:module packages --- src/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 17a5741f..fcd75d81 100644 --- a/src/index.js +++ b/src/index.js @@ -259,10 +259,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 +298,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',