Skip to content

Commit 7473d2c

Browse files
committed
refactor and small fixes
1 parent e237b48 commit 7473d2c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/packages.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ class Package {
5050
}
5151

5252
resolveExports(importPath) {
53-
for (const exportKey in this.exports) {
53+
if (!this.exports) return null;
54+
for (const [exportKey, exportValue] of Object.entries(this.exports)) {
5455
const normalizedExportKey = ospath.join(this.name, exportKey);
55-
if ((typeof this.exports[exportKey] === "object") && (normalizedExportKey === importPath) && ("require" in this.exports[exportKey]) && ("import" in this.exports[exportKey])) {
56+
const isObject = typeof exportValue === "object";
57+
const isPathMatch = normalizedExportKey === importPath;
58+
const hasRequiredKeys = ["require", "import"].every(key => Object.keys(exportValue).includes(key));
59+
if (isObject && isPathMatch && hasRequiredKeys) {
5660
return {
57-
absCjsFile: this.exports[exportKey]["require"],
58-
absEsmFile: this.exports[exportKey]["import"]
61+
absCjsFile: exportValue.require?.default || exportValue.require,
62+
absEsmFile: exportValue.import?.default || exportValue.import
5963
}
6064
}
6165
}

0 commit comments

Comments
 (0)