From 6cd2c136c6efd647247a46ed67c25b2f0bc673b7 Mon Sep 17 00:00:00 2001 From: Alex Kirszenberg Date: Tue, 4 Jul 2023 14:49:35 +0200 Subject: [PATCH] Fix internal JS/TS references not being processed --- crates/turbopack/src/module_options/mod.rs | 4 ++-- .../src/module_options/module_rule.rs | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/turbopack/src/module_options/mod.rs b/crates/turbopack/src/module_options/mod.rs index bd9677f8dbcff..84c01cc292011 100644 --- a/crates/turbopack/src/module_options/mod.rs +++ b/crates/turbopack/src/module_options/mod.rs @@ -225,7 +225,7 @@ impl ModuleOptionsVc { ModuleRuleCondition::ResourcePathEndsWith(".json".to_string()), vec![ModuleRuleEffect::ModuleType(ModuleType::Json)], ), - ModuleRule::new( + ModuleRule::new_all( ModuleRuleCondition::any(vec![ ModuleRuleCondition::ResourcePathEndsWith(".js".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".jsx".to_string()), @@ -255,7 +255,7 @@ impl ModuleOptionsVc { }, })], ), - ModuleRule::new( + ModuleRule::new_all( ModuleRuleCondition::any(vec![ ModuleRuleCondition::ResourcePathEndsWith(".ts".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".tsx".to_string()), diff --git a/crates/turbopack/src/module_options/module_rule.rs b/crates/turbopack/src/module_options/module_rule.rs index 6a170ab1436de..86666aca2b133 100644 --- a/crates/turbopack/src/module_options/module_rule.rs +++ b/crates/turbopack/src/module_options/module_rule.rs @@ -18,20 +18,21 @@ pub struct ModuleRule { match_mode: MatchMode, } -#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)] enum MatchMode { // Match all but internal references. - #[default] - Default, + NonInternal, // Only match internal references. Internal, + // Match both internal and non-internal references. + All, } impl MatchMode { fn matches(&self, reference_type: &ReferenceType) -> bool { matches!( (self, reference_type.is_internal()), - (MatchMode::Default, false) | (MatchMode::Internal, true) + (MatchMode::All, _) | (MatchMode::NonInternal, false) | (MatchMode::Internal, true) ) } } @@ -42,7 +43,7 @@ impl ModuleRule { ModuleRule { condition, effects, - match_mode: Default::default(), + match_mode: MatchMode::NonInternal, } } @@ -55,6 +56,15 @@ impl ModuleRule { } } + /// Creates a new module rule. Will only matches internal references. + pub fn new_all(condition: ModuleRuleCondition, effects: Vec) -> Self { + ModuleRule { + condition, + effects, + match_mode: MatchMode::All, + } + } + pub fn effects(&self) -> impl Iterator { self.effects.iter() }