Skip to content

Commit 46cd072

Browse files
Copilotjakebailey
andauthored
Port #62483: Disable conditional exports fallbacks on null values (#2732)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent c0df2ff commit 46cd072

10 files changed

+37
-90
lines changed

internal/module/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ func (r *resolutionState) loadModuleFromTargetExportOrImport(extensions extensio
742742
}
743743
subTarget, _ := target.AsObject().Get(condition)
744744
if result := r.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, subTarget, subpath, isPattern, key); !result.shouldContinueSearching() {
745-
if r.tracer != nil {
745+
if result.isResolved() && r.tracer != nil {
746746
r.tracer.write(diagnostics.Resolved_under_condition_0, condition)
747747
}
748748
if r.tracer != nil {
@@ -779,7 +779,7 @@ func (r *resolutionState) loadModuleFromTargetExportOrImport(extensions extensio
779779
if r.tracer != nil {
780780
r.tracer.write(diagnostics.X_package_json_scope_0_explicitly_maps_specifier_1_to_null, scope.PackageDirectory, moduleName)
781781
}
782-
return continueSearching()
782+
return unresolved()
783783
}
784784

785785
if r.tracer != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/index.mts(1,16): error TS2307: Cannot find module 'dep' or its corresponding type declarations.
2+
3+
4+
==== /node_modules/dep/package.json (0 errors) ====
5+
{
6+
"name": "dep",
7+
"version": "1.0.0",
8+
"exports": {
9+
".": {
10+
"import": null,
11+
"types": "./dist/index.d.ts"
12+
}
13+
}
14+
}
15+
16+
==== /node_modules/dep/dist/index.d.ts (0 errors) ====
17+
export {};
18+
19+
==== /index.mts (1 errors) ====
20+
import {} from "dep"; // Cannot find module 'dep'.
21+
~~~~~
22+
!!! error TS2307: Cannot find module 'dep' or its corresponding type declarations.

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=bundler).errors.txt.diff

Lines changed: 0 additions & 26 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=bundler).trace.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ Found 'package.json' at '/node_modules/dep/package.json'.
88
Entering conditional exports.
99
Matched 'exports' condition 'import'.
1010
package.json scope '/node_modules/dep' explicitly maps specifier '.' to null.
11-
Failed to resolve under condition 'import'.
12-
Matched 'exports' condition 'types'.
13-
Using 'exports' subpath '.' with target './dist/index.d.ts'.
14-
File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.
15-
'package.json' does not have a 'peerDependencies' field.
16-
Resolved under condition 'types'.
1711
Exiting conditional exports.
18-
Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.
19-
======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========
12+
======== Module name 'dep' was not resolved. ========

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=node16).errors.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'.
2+
/index.mts(1,16): error TS2307: Cannot find module 'dep' or its corresponding type declarations.
23

34

45
!!! error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'.
@@ -17,5 +18,7 @@ error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolut
1718
==== /node_modules/dep/dist/index.d.ts (0 errors) ====
1819
export {};
1920

20-
==== /index.mts (0 errors) ====
21-
import {} from "dep"; // Cannot find module 'dep'.
21+
==== /index.mts (1 errors) ====
22+
import {} from "dep"; // Cannot find module 'dep'.
23+
~~~~~
24+
!!! error TS2307: Cannot find module 'dep' or its corresponding type declarations.

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=node16).errors.txt.diff

Lines changed: 0 additions & 17 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=node16).trace.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ Found 'package.json' at '/node_modules/dep/package.json'.
88
Entering conditional exports.
99
Matched 'exports' condition 'import'.
1010
package.json scope '/node_modules/dep' explicitly maps specifier '.' to null.
11-
Failed to resolve under condition 'import'.
12-
Matched 'exports' condition 'types'.
13-
Using 'exports' subpath '.' with target './dist/index.d.ts'.
14-
File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.
15-
'package.json' does not have a 'peerDependencies' field.
16-
Resolved under condition 'types'.
1711
Exiting conditional exports.
18-
Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.
19-
======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========
12+
======== Module name 'dep' was not resolved. ========

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=nodenext).errors.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
2+
/index.mts(1,16): error TS2307: Cannot find module 'dep' or its corresponding type declarations.
23

34

45
!!! error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
@@ -17,5 +18,7 @@ error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResol
1718
==== /node_modules/dep/dist/index.d.ts (0 errors) ====
1819
export {};
1920

20-
==== /index.mts (0 errors) ====
21-
import {} from "dep"; // Cannot find module 'dep'.
21+
==== /index.mts (1 errors) ====
22+
import {} from "dep"; // Cannot find module 'dep'.
23+
~~~~~
24+
!!! error TS2307: Cannot find module 'dep' or its corresponding type declarations.

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=nodenext).errors.txt.diff

Lines changed: 0 additions & 17 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/conditionalExportsResolutionFallbackNull(moduleresolution=nodenext).trace.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ Found 'package.json' at '/node_modules/dep/package.json'.
88
Entering conditional exports.
99
Matched 'exports' condition 'import'.
1010
package.json scope '/node_modules/dep' explicitly maps specifier '.' to null.
11-
Failed to resolve under condition 'import'.
12-
Matched 'exports' condition 'types'.
13-
Using 'exports' subpath '.' with target './dist/index.d.ts'.
14-
File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.
15-
'package.json' does not have a 'peerDependencies' field.
16-
Resolved under condition 'types'.
1711
Exiting conditional exports.
18-
Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.
19-
======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========
12+
======== Module name 'dep' was not resolved. ========

0 commit comments

Comments
 (0)