Skip to content

Commit 1e455b0

Browse files
authored
fix: evaluate nested export conditions when resolving a module-sync fallback (#557)
The code (added [here](#550)) was previously only adding the fallback when the condition was a string, but wasn't handling `{`"default": {"default": "./fallback.js"}}`, as is used in [this package](https://www.npmjs.com/package/@mjackson/node-fetch-server/v/0.2.0?activeTab=code)
1 parent 684032b commit 1e455b0

File tree

8 files changed

+34
-1
lines changed

8 files changed

+34
-1
lines changed

src/resolve-dependency.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ async function resolveExportsImports(
254254
) {
255255
const fallbackCondition =
256256
'require' in exportsForSubpath ? 'require' : 'default';
257-
const fallbackTarget = exportsForSubpath[fallbackCondition];
257+
const fallbackTarget = getExportsTarget(
258+
exportsForSubpath[fallbackCondition],
259+
job.conditions,
260+
cjsResolve,
261+
);
258262
if (
259263
typeof fallbackTarget === 'string' &&
260264
fallbackTarget.startsWith('./')

test/unit.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const skipOnMac = [];
2828
const skipOnNode20AndBelow = [
2929
'module-sync-condition-es',
3030
'module-sync-condition-cjs',
31+
'module-sync-condition-es-nested',
3132
'imports-module-sync',
3233
'imports-module-sync-cjs',
3334
'self-reference-module-sync',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const test = 'fallback version';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const test = 'import version';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { test } from 'test-pkg-sync-es';
2+
console.log(test);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const test = 'module-sync version';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"test/unit/module-sync-condition-es-nested/fallback.js",
3+
"test/unit/module-sync-condition-es-nested/input.js",
4+
"test/unit/module-sync-condition-es-nested/module-sync.js",
5+
"test/unit/module-sync-condition-es-nested/package.json"
6+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "test-pkg-sync-es",
3+
"type": "module",
4+
"exports": {
5+
".": {
6+
"module-sync": {
7+
"default": "./module-sync.js"
8+
},
9+
"import": {
10+
"default": "./import.js"
11+
},
12+
"default": {
13+
"default": "./fallback.js"
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)