@@ -670,7 +670,6 @@ function tryResolveRealFileWithExtensions(
670670export type InternalResolveOptionsWithOverrideConditions =
671671 InternalResolveOptions & {
672672 /**
673- * @deprecated In future, `conditions` will work like this.
674673 * @internal
675674 */
676675 overrideConditions ?: string [ ]
@@ -1072,52 +1071,38 @@ function packageEntryFailure(id: string, details?: string) {
10721071 )
10731072}
10741073
1075- const conditionalConditions = new Set ( [ 'production' , 'development' , 'module' ] )
1076-
10771074function resolveExportsOrImports (
10781075 pkg : PackageData [ 'data' ] ,
10791076 key : string ,
10801077 options : InternalResolveOptionsWithOverrideConditions ,
10811078 targetWeb : boolean ,
10821079 type : 'imports' | 'exports' ,
10831080) {
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+ )
10871089
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+ } )
11161101
11171102 const fn = type === 'imports' ? imports : exports
11181103 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' ) ,
11211106 conditions,
11221107 } )
11231108
0 commit comments