1
- use std:: { collections:: BTreeSet , str:: FromStr } ;
2
-
3
1
use anyhow:: { Context , Result , bail} ;
4
2
use either:: Either ;
5
3
use rustc_hash:: FxHashSet ;
@@ -667,21 +665,11 @@ impl TryFrom<ConfigConditionItem> for ConditionItem {
667
665
}
668
666
}
669
667
670
- #[ derive(
671
- Clone , Debug , PartialEq , Eq , Serialize , Deserialize , TraceRawVcs , NonLocalValue , OperationValue ,
672
- ) ]
673
- #[ serde( rename_all = "camelCase" , untagged) ]
674
- pub enum RuleConfigItem {
675
- Options ( RuleConfigItemOptions ) ,
676
- LegacyConditional ( FxIndexMap < RcStr , RuleConfigItem > ) ,
677
- LegacyBoolean ( bool ) ,
678
- }
679
-
680
668
#[ derive(
681
669
Clone , Debug , PartialEq , Eq , Serialize , Deserialize , TraceRawVcs , NonLocalValue , OperationValue ,
682
670
) ]
683
671
#[ serde( rename_all = "camelCase" ) ]
684
- pub struct RuleConfigItemOptions {
672
+ pub struct RuleConfigItem {
685
673
pub loaders : Vec < LoaderItem > ,
686
674
#[ serde( default , alias = "as" ) ]
687
675
pub rename_as : Option < RcStr > ,
@@ -1401,11 +1389,7 @@ impl NextConfig {
1401
1389
}
1402
1390
1403
1391
#[ turbo_tasks:: function]
1404
- pub async fn webpack_rules (
1405
- & self ,
1406
- active_conditions : BTreeSet < WebpackLoaderBuiltinCondition > ,
1407
- project_path : FileSystemPath ,
1408
- ) -> Result < Vc < WebpackRules > > {
1392
+ pub async fn webpack_rules ( & self , project_path : FileSystemPath ) -> Result < Vc < WebpackRules > > {
1409
1393
let Some ( turbo_rules) = self . turbopack . as_ref ( ) . and_then ( |t| t. rules . as_ref ( ) ) else {
1410
1394
return Ok ( Vc :: cell ( Vec :: new ( ) ) ) ;
1411
1395
} ;
@@ -1429,43 +1413,6 @@ impl NextConfig {
1429
1413
. collect ( ) ,
1430
1414
)
1431
1415
}
1432
- enum FindRuleResult < ' a > {
1433
- Found ( & ' a RuleConfigItemOptions ) ,
1434
- NotFound ,
1435
- Break ,
1436
- }
1437
- // This logic is needed for the `LegacyConditional`/`LegacyBoolean` configuration
1438
- // syntax. This is technically public syntax, but was never documented and it is
1439
- // unlikely that anyone is depending on it (outside of some Next.js internals).
1440
- fn find_rule < ' a > (
1441
- rule : & ' a RuleConfigItem ,
1442
- active_conditions : & BTreeSet < WebpackLoaderBuiltinCondition > ,
1443
- ) -> FindRuleResult < ' a > {
1444
- match rule {
1445
- RuleConfigItem :: Options ( rule) => FindRuleResult :: Found ( rule) ,
1446
- RuleConfigItem :: LegacyConditional ( map) => {
1447
- for ( condition, rule) in map. iter ( ) {
1448
- let condition = WebpackLoaderBuiltinCondition :: from_str ( condition) ;
1449
- if let Ok ( condition) = condition
1450
- && ( condition == WebpackLoaderBuiltinCondition :: Default
1451
- || active_conditions. contains ( & condition) )
1452
- {
1453
- match find_rule ( rule, active_conditions) {
1454
- FindRuleResult :: Found ( rule) => {
1455
- return FindRuleResult :: Found ( rule) ;
1456
- }
1457
- FindRuleResult :: Break => {
1458
- return FindRuleResult :: Break ;
1459
- }
1460
- FindRuleResult :: NotFound => { }
1461
- }
1462
- }
1463
- }
1464
- FindRuleResult :: NotFound
1465
- }
1466
- RuleConfigItem :: LegacyBoolean ( _) => FindRuleResult :: Break ,
1467
- }
1468
- }
1469
1416
let config_file_path = || project_path. join ( & self . config_file_name ) ;
1470
1417
for item in & rule_collection. 0 {
1471
1418
match item {
@@ -1479,55 +1426,52 @@ impl NextConfig {
1479
1426
} ,
1480
1427
) ) ;
1481
1428
}
1482
- RuleConfigCollectionItem :: Full ( rule_config_item) => {
1483
- if let FindRuleResult :: Found ( RuleConfigItemOptions {
1484
- loaders,
1485
- rename_as,
1486
- condition,
1487
- } ) = find_rule ( rule_config_item, & active_conditions)
1429
+ RuleConfigCollectionItem :: Full ( RuleConfigItem {
1430
+ loaders,
1431
+ rename_as,
1432
+ condition,
1433
+ } ) => {
1434
+ // If the extension contains a wildcard, and the rename_as does not,
1435
+ // emit an issue to prevent users from encountering duplicate module
1436
+ // names.
1437
+ if glob. contains ( "*" )
1438
+ && let Some ( rename_as) = rename_as. as_ref ( )
1439
+ && !rename_as. contains ( "*" )
1488
1440
{
1489
- // If the extension contains a wildcard, and the rename_as does not,
1490
- // emit an issue to prevent users from encountering duplicate module
1491
- // names.
1492
- if glob. contains ( "*" )
1493
- && let Some ( rename_as) = rename_as. as_ref ( )
1494
- && !rename_as. contains ( "*" )
1495
- {
1496
- InvalidLoaderRuleRenameAsIssue {
1497
- glob : glob. clone ( ) ,
1441
+ InvalidLoaderRuleRenameAsIssue {
1442
+ glob : glob. clone ( ) ,
1443
+ config_file_path : config_file_path ( ) ?,
1444
+ rename_as : rename_as. clone ( ) ,
1445
+ }
1446
+ . resolved_cell ( )
1447
+ . emit ( ) ;
1448
+ }
1449
+
1450
+ // convert from Next.js-specific condition type to internal Turbopack
1451
+ // condition type
1452
+ let condition = if let Some ( condition) = condition {
1453
+ if let Ok ( cond) = ConditionItem :: try_from ( condition. clone ( ) ) {
1454
+ Some ( cond)
1455
+ } else {
1456
+ InvalidLoaderRuleConditionIssue {
1457
+ condition : condition. clone ( ) ,
1498
1458
config_file_path : config_file_path ( ) ?,
1499
- rename_as : rename_as. clone ( ) ,
1500
1459
}
1501
1460
. resolved_cell ( )
1502
1461
. emit ( ) ;
1503
- }
1504
-
1505
- // convert from Next.js-specific condition type to internal Turbopack
1506
- // condition type
1507
- let condition = if let Some ( condition) = condition {
1508
- if let Ok ( cond) = ConditionItem :: try_from ( condition. clone ( ) ) {
1509
- Some ( cond)
1510
- } else {
1511
- InvalidLoaderRuleConditionIssue {
1512
- condition : condition. clone ( ) ,
1513
- config_file_path : config_file_path ( ) ?,
1514
- }
1515
- . resolved_cell ( )
1516
- . emit ( ) ;
1517
- None
1518
- }
1519
- } else {
1520
1462
None
1521
- } ;
1522
- rules. push ( (
1523
- glob. clone ( ) ,
1524
- LoaderRuleItem {
1525
- loaders : transform_loaders ( Box :: new ( loaders. iter ( ) ) ) ,
1526
- rename_as : rename_as. clone ( ) ,
1527
- condition,
1528
- } ,
1529
- ) ) ;
1530
- }
1463
+ }
1464
+ } else {
1465
+ None
1466
+ } ;
1467
+ rules. push ( (
1468
+ glob. clone ( ) ,
1469
+ LoaderRuleItem {
1470
+ loaders : transform_loaders ( Box :: new ( loaders. iter ( ) ) ) ,
1471
+ rename_as : rename_as. clone ( ) ,
1472
+ condition,
1473
+ } ,
1474
+ ) ) ;
1531
1475
}
1532
1476
}
1533
1477
}
@@ -2001,11 +1945,11 @@ mod tests {
2001
1945
}
2002
1946
} ) ;
2003
1947
2004
- let rule_config: RuleConfigItemOptions = serde_json:: from_value ( json_value) . unwrap ( ) ;
1948
+ let rule_config: RuleConfigItem = serde_json:: from_value ( json_value) . unwrap ( ) ;
2005
1949
2006
1950
assert_eq ! (
2007
1951
rule_config,
2008
- RuleConfigItemOptions {
1952
+ RuleConfigItem {
2009
1953
loaders: vec![ ] ,
2010
1954
rename_as: Some ( rcstr!( "*.js" ) ) ,
2011
1955
condition: Some ( ConfigConditionItem :: All (
0 commit comments