Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/cli/src/lib/walker-package-ranger.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,18 @@ async function walkPackageForExports(dependency, packageJson, resolvedRoot) {
if (typeof exports === "string") {
// https://unpkg.com/browse/robust-predicates@3.0.2/package.json
updateImportMap(dependency, exports, resolvedRoot);
} else if (typeof exports === "object") {
} else if (exports && typeof exports === "object") {
// we need to check for conditional exports that are null first, since typeof null === "object"
// https://github.com/ProjectEvergreen/greenwood/issues/1704
// https://app.unpkg.com/effect@4.0.0-beta.97/files/package.json#L52
/*
* test for conditional subpath exports
* 1. import
* 2. module-sync
* 3. default
*/
for (const sub in exports) {
// although not widely used and is generally discouraged / deprecated
// some export maps have an array
// although not widely used and is generally discouraged / deprecated, some export maps have an array
// https://app.unpkg.com/@jridgewell/gen-mapping@0.3.13/files/package.json#L18
if (Array.isArray(exports[sub])) {
for (const item of exports[sub]) {
Expand Down Expand Up @@ -209,7 +211,10 @@ async function walkPackageForExports(dependency, packageJson, resolvedRoot) {
}
}
}
} else if (typeof exports[sub] === "object") {
} else if (exports[sub] && typeof exports[sub] === "object") {
// we need to check for conditional exports that are null first, since typeof null === "object"
// https://github.com/ProjectEvergreen/greenwood/issues/1704
// https://app.unpkg.com/effect@4.0.0-beta.97/files/package.json#L52
let matched = false;

for (const condition of SUPPORTED_EXPORT_CONDITIONS) {
Expand All @@ -235,7 +240,10 @@ async function walkPackageForExports(dependency, packageJson, resolvedRoot) {
// handle (unconditional) subpath exports
if (sub === ".") {
updateImportMap(dependency, `${exports[sub]}`, resolvedRoot);
} else if (sub.indexOf("*") >= 0) {
} else if (exports[sub] && sub.indexOf("*") >= 0) {
// we need to check for conditional export sub conditions that are null first
// https://github.com/ProjectEvergreen/greenwood/issues/1704
// https://app.unpkg.com/effect@4.0.0-beta.97/files/package.json#L52
await walkExportPatterns(dependency, exports[sub], resolvedRoot);
} else if (SUPPORTED_EXPORT_CONDITIONS.includes(sub)) {
// filter out for just supported top level conditions
Expand Down
Loading