@@ -1122,7 +1122,7 @@ pub const ESMConditions = struct {
11221122 require : ConditionsMap ,
11231123 style : ConditionsMap ,
11241124
1125- pub fn init (allocator : std.mem.Allocator , defaults : []const string ) ! ESMConditions {
1125+ pub fn init (allocator : std.mem.Allocator , defaults : []const string ) bun.OOM ! ESMConditions {
11261126 var default_condition_amp = ConditionsMap .init (allocator );
11271127
11281128 var import_condition_map = ConditionsMap .init (allocator );
@@ -1176,7 +1176,7 @@ pub const ESMConditions = struct {
11761176 };
11771177 }
11781178
1179- pub fn appendSlice (self : * ESMConditions , conditions : []const string ) ! void {
1179+ pub fn appendSlice (self : * ESMConditions , conditions : []const string ) bun.OOM ! void {
11801180 try self .default .ensureUnusedCapacity (conditions .len );
11811181 try self .import .ensureUnusedCapacity (conditions .len );
11821182 try self .require .ensureUnusedCapacity (conditions .len );
@@ -1189,6 +1189,13 @@ pub const ESMConditions = struct {
11891189 self .style .putAssumeCapacity (condition , {});
11901190 }
11911191 }
1192+
1193+ pub fn append (self : * ESMConditions , condition : string ) bun.OOM ! void {
1194+ try self .default .put (condition , {});
1195+ try self .import .put (condition , {});
1196+ try self .require .put (condition , {});
1197+ try self .style .put (condition , {});
1198+ }
11921199};
11931200
11941201pub const JSX = struct {
@@ -1993,10 +2000,26 @@ pub const BundleOptions = struct {
19932000 opts .main_fields = Target .DefaultMainFields .get (opts .target );
19942001 }
19952002
1996- opts .conditions = try ESMConditions .init (allocator , opts .target .defaultConditions ());
2003+ {
2004+ // conditions:
2005+ // 1. defaults
2006+ // 2. node-addons
2007+ // 3. user conditions
2008+ opts .conditions = try ESMConditions .init (allocator , opts .target .defaultConditions ());
2009+
2010+ dont_append_node_addons : {
2011+ if (transform .allow_addons ) | allow_addons | {
2012+ if (! allow_addons ) {
2013+ break :dont_append_node_addons ;
2014+ }
2015+ }
2016+
2017+ try opts .conditions .append ("node-addons" );
2018+ }
19972019
1998- if (transform .conditions .len > 0 ) {
1999- opts .conditions .appendSlice (transform .conditions ) catch bun .outOfMemory ();
2020+ if (transform .conditions .len > 0 ) {
2021+ try opts .conditions .appendSlice (transform .conditions );
2022+ }
20002023 }
20012024
20022025 switch (opts .target ) {
0 commit comments