Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,23 @@ function _findSubpath(subpath: string, exports: PackageJson["exports"]) {
}

function _flattenExports(
exports: Exclude<PackageJson["exports"], string> = {},
exports: Exclude<PackageJson["exports"], string> | null = {},
parentSubpath = "./",
): { subpath: string; fsPath: string; condition?: string }[] {
if (exports === null) {
return [];
}

return Object.entries(exports).flatMap(([key, value]) => {
const [subpath, condition] = key.startsWith(".")
? [key.slice(1), undefined]
: ["", key];
const _subPath = joinURL(parentSubpath, subpath);

if (value === null) {
return [];
}

if (typeof value === "string") {
return [{ subpath: _subPath, fsPath: value, condition }];
} else {
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/package/node_modules/subpaths/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.