1
- use std:: { collections :: BTreeSet , str :: FromStr , sync:: LazyLock } ;
1
+ use std:: sync:: LazyLock ;
2
2
3
3
use anyhow:: { Context , Result , bail} ;
4
4
use rustc_hash:: FxHashSet ;
@@ -670,7 +670,7 @@ impl TryFrom<ConfigConditionItem> for ConditionItem {
670
670
Clone , Debug , PartialEq , Eq , Serialize , Deserialize , TraceRawVcs , NonLocalValue , OperationValue ,
671
671
) ]
672
672
#[ serde( rename_all = "camelCase" ) ]
673
- pub struct RuleConfigItemOptions {
673
+ pub struct RuleConfigItem {
674
674
pub loaders : Vec < LoaderItem > ,
675
675
#[ serde( default , alias = "as" ) ]
676
676
pub rename_as : Option < RcStr > ,
@@ -687,16 +687,6 @@ pub enum RuleConfigItemOrShortcut {
687
687
Advanced ( RuleConfigItem ) ,
688
688
}
689
689
690
- #[ derive(
691
- Clone , Debug , PartialEq , Eq , Serialize , Deserialize , TraceRawVcs , NonLocalValue , OperationValue ,
692
- ) ]
693
- #[ serde( rename_all = "camelCase" , untagged) ]
694
- pub enum RuleConfigItem {
695
- Options ( RuleConfigItemOptions ) ,
696
- LegacyConditional ( FxIndexMap < RcStr , RuleConfigItem > ) ,
697
- LegacyBoolean ( bool ) ,
698
- }
699
-
700
690
#[ derive(
701
691
Clone , Debug , PartialEq , Eq , Serialize , Deserialize , TraceRawVcs , NonLocalValue , OperationValue ,
702
692
) ]
@@ -1378,7 +1368,6 @@ impl NextConfig {
1378
1368
#[ turbo_tasks:: function]
1379
1369
pub async fn webpack_rules (
1380
1370
& self ,
1381
- active_conditions : BTreeSet < WebpackLoaderBuiltinCondition > ,
1382
1371
project_path : FileSystemPath ,
1383
1372
) -> Result < Vc < OptionWebpackRules > > {
1384
1373
let Some ( turbo_rules) = self . turbopack . as_ref ( ) . and_then ( |t| t. rules . as_ref ( ) ) else {
@@ -1403,43 +1392,6 @@ impl NextConfig {
1403
1392
. collect ( ) ,
1404
1393
)
1405
1394
}
1406
- enum FindRuleResult < ' a > {
1407
- Found ( & ' a RuleConfigItemOptions ) ,
1408
- NotFound ,
1409
- Break ,
1410
- }
1411
- // This logic is needed for the `LegacyConditional`/`LegacyBoolean` configuration
1412
- // syntax. This is technically public syntax, but was never documented and it is
1413
- // unlikely that anyone is depending on it (outside of some Next.js internals).
1414
- fn find_rule < ' a > (
1415
- rule : & ' a RuleConfigItem ,
1416
- active_conditions : & BTreeSet < WebpackLoaderBuiltinCondition > ,
1417
- ) -> FindRuleResult < ' a > {
1418
- match rule {
1419
- RuleConfigItem :: Options ( rule) => FindRuleResult :: Found ( rule) ,
1420
- RuleConfigItem :: LegacyConditional ( map) => {
1421
- for ( condition, rule) in map. iter ( ) {
1422
- let condition = WebpackLoaderBuiltinCondition :: from_str ( condition) ;
1423
- if let Ok ( condition) = condition
1424
- && ( condition == WebpackLoaderBuiltinCondition :: Default
1425
- || active_conditions. contains ( & condition) )
1426
- {
1427
- match find_rule ( rule, active_conditions) {
1428
- FindRuleResult :: Found ( rule) => {
1429
- return FindRuleResult :: Found ( rule) ;
1430
- }
1431
- FindRuleResult :: Break => {
1432
- return FindRuleResult :: Break ;
1433
- }
1434
- FindRuleResult :: NotFound => { }
1435
- }
1436
- }
1437
- }
1438
- FindRuleResult :: NotFound
1439
- }
1440
- RuleConfigItem :: LegacyBoolean ( _) => FindRuleResult :: Break ,
1441
- }
1442
- }
1443
1395
let config_file_path = || project_path. join ( & self . config_file_name ) ;
1444
1396
match rule {
1445
1397
RuleConfigItemOrShortcut :: Loaders ( loaders) => {
@@ -1452,55 +1404,52 @@ impl NextConfig {
1452
1404
} ,
1453
1405
) ;
1454
1406
}
1455
- RuleConfigItemOrShortcut :: Advanced ( rule) => {
1456
- if let FindRuleResult :: Found ( RuleConfigItemOptions {
1457
- loaders,
1458
- rename_as,
1459
- condition,
1460
- } ) = find_rule ( rule, & active_conditions)
1407
+ RuleConfigItemOrShortcut :: Advanced ( RuleConfigItem {
1408
+ loaders,
1409
+ rename_as,
1410
+ condition,
1411
+ } ) => {
1412
+ // If the extension contains a wildcard, and the rename_as does not,
1413
+ // emit an issue to prevent users from encountering duplicate module names.
1414
+ if glob. contains ( "*" )
1415
+ && let Some ( rename_as) = rename_as. as_ref ( )
1416
+ && !rename_as. contains ( "*" )
1461
1417
{
1462
- // If the extension contains a wildcard, and the rename_as does not,
1463
- // emit an issue to prevent users from encountering duplicate module names.
1464
- if glob. contains ( "*" )
1465
- && let Some ( rename_as) = rename_as. as_ref ( )
1466
- && !rename_as. contains ( "*" )
1467
- {
1468
- InvalidLoaderRuleRenameAsIssue {
1469
- glob : glob. clone ( ) ,
1418
+ InvalidLoaderRuleRenameAsIssue {
1419
+ glob : glob. clone ( ) ,
1420
+ config_file_path : config_file_path ( ) ?,
1421
+ rename_as : rename_as. clone ( ) ,
1422
+ }
1423
+ . resolved_cell ( )
1424
+ . emit ( ) ;
1425
+ }
1426
+
1427
+ // convert from Next.js-specific condition type to internal Turbopack
1428
+ // condition type
1429
+ let condition = if let Some ( condition) = condition {
1430
+ if let Ok ( cond) = ConditionItem :: try_from ( condition. clone ( ) ) {
1431
+ Some ( cond)
1432
+ } else {
1433
+ InvalidLoaderRuleConditionIssue {
1434
+ condition : condition. clone ( ) ,
1470
1435
config_file_path : config_file_path ( ) ?,
1471
- rename_as : rename_as. clone ( ) ,
1472
1436
}
1473
1437
. resolved_cell ( )
1474
1438
. emit ( ) ;
1439
+ None
1475
1440
}
1441
+ } else {
1442
+ None
1443
+ } ;
1476
1444
1477
- // convert from Next.js-specific condition type to internal Turbopack
1478
- // condition type
1479
- let condition = if let Some ( condition) = condition {
1480
- if let Ok ( cond) = ConditionItem :: try_from ( condition. clone ( ) ) {
1481
- Some ( cond)
1482
- } else {
1483
- InvalidLoaderRuleConditionIssue {
1484
- condition : condition. clone ( ) ,
1485
- config_file_path : config_file_path ( ) ?,
1486
- }
1487
- . resolved_cell ( )
1488
- . emit ( ) ;
1489
- None
1490
- }
1491
- } else {
1492
- None
1493
- } ;
1494
-
1495
- rules. insert (
1496
- glob. clone ( ) ,
1497
- LoaderRuleItem {
1498
- loaders : transform_loaders ( loaders) ,
1499
- rename_as : rename_as. clone ( ) ,
1500
- condition,
1501
- } ,
1502
- ) ;
1503
- }
1445
+ rules. insert (
1446
+ glob. clone ( ) ,
1447
+ LoaderRuleItem {
1448
+ loaders : transform_loaders ( loaders) ,
1449
+ rename_as : rename_as. clone ( ) ,
1450
+ condition,
1451
+ } ,
1452
+ ) ;
1504
1453
}
1505
1454
}
1506
1455
}
@@ -1963,11 +1912,11 @@ mod tests {
1963
1912
}
1964
1913
} ) ;
1965
1914
1966
- let rule_config: RuleConfigItemOptions = serde_json:: from_value ( json_value) . unwrap ( ) ;
1915
+ let rule_config: RuleConfigItem = serde_json:: from_value ( json_value) . unwrap ( ) ;
1967
1916
1968
1917
assert_eq ! (
1969
1918
rule_config,
1970
- RuleConfigItemOptions {
1919
+ RuleConfigItem {
1971
1920
loaders: vec![ ] ,
1972
1921
rename_as: Some ( rcstr!( "*.js" ) ) ,
1973
1922
condition: Some ( ConfigConditionItem :: All (
0 commit comments