@@ -670,7 +670,6 @@ function tryResolveRealFileWithExtensions(
670
670
export type InternalResolveOptionsWithOverrideConditions =
671
671
InternalResolveOptions & {
672
672
/**
673
- * @deprecated In future, `conditions` will work like this.
674
673
* @internal
675
674
*/
676
675
overrideConditions ?: string [ ]
@@ -1072,52 +1071,38 @@ function packageEntryFailure(id: string, details?: string) {
1072
1071
)
1073
1072
}
1074
1073
1075
- const conditionalConditions = new Set ( [ 'production' , 'development' , 'module' ] )
1076
-
1077
1074
function resolveExportsOrImports (
1078
1075
pkg : PackageData [ 'data' ] ,
1079
1076
key : string ,
1080
1077
options : InternalResolveOptionsWithOverrideConditions ,
1081
1078
targetWeb : boolean ,
1082
1079
type : 'imports' | 'exports' ,
1083
1080
) {
1084
- const overrideConditions = options . overrideConditions
1085
- ? new Set ( options . overrideConditions )
1086
- : undefined
1081
+ const additionalConditions = new Set (
1082
+ options . overrideConditions || [
1083
+ 'production' ,
1084
+ 'development' ,
1085
+ 'module' ,
1086
+ ...options . conditions ,
1087
+ ] ,
1088
+ )
1087
1089
1088
- const conditions = [ ]
1089
- if (
1090
- ( ! overrideConditions || overrideConditions . has ( 'production' ) ) &&
1091
- options . isProduction
1092
- ) {
1093
- conditions . push ( 'production' )
1094
- }
1095
- if (
1096
- ( ! overrideConditions || overrideConditions . has ( 'development' ) ) &&
1097
- ! options . isProduction
1098
- ) {
1099
- conditions . push ( 'development' )
1100
- }
1101
- if (
1102
- ( ! overrideConditions || overrideConditions . has ( 'module' ) ) &&
1103
- ! options . isRequire
1104
- ) {
1105
- conditions . push ( 'module' )
1106
- }
1107
- if ( options . overrideConditions ) {
1108
- conditions . push (
1109
- ...options . overrideConditions . filter ( ( condition ) =>
1110
- conditionalConditions . has ( condition ) ,
1111
- ) ,
1112
- )
1113
- } else if ( options . conditions . length > 0 ) {
1114
- conditions . push ( ...options . conditions )
1115
- }
1090
+ const conditions = [ ...additionalConditions ] . filter ( ( condition ) => {
1091
+ switch ( condition ) {
1092
+ case 'production' :
1093
+ return options . isProduction
1094
+ case 'development' :
1095
+ return ! options . isProduction
1096
+ case 'module' :
1097
+ return ! options . isRequire
1098
+ }
1099
+ return true
1100
+ } )
1116
1101
1117
1102
const fn = type === 'imports' ? imports : exports
1118
1103
const result = fn ( pkg , key , {
1119
- browser : targetWeb && ! conditions . includes ( 'node' ) ,
1120
- require : options . isRequire && ! conditions . includes ( 'import' ) ,
1104
+ browser : targetWeb && ! additionalConditions . has ( 'node' ) ,
1105
+ require : options . isRequire && ! additionalConditions . has ( 'import' ) ,
1121
1106
conditions,
1122
1107
} )
1123
1108
0 commit comments