@@ -11,48 +11,42 @@ use crate::{
1111
1212/// A condition which determines if the hooks of a resolve plugin gets called.
1313#[ turbo_tasks:: value]
14- pub struct AfterResolvePluginCondition {
15- root : FileSystemPath ,
16- glob : ResolvedVc < Glob > ,
14+ pub enum AfterResolvePluginCondition {
15+ Glob {
16+ root : FileSystemPath ,
17+ glob : ResolvedVc < Glob > ,
18+ } ,
19+ Always ,
20+ Never ,
1721}
1822
1923#[ turbo_tasks:: value_impl]
2024impl AfterResolvePluginCondition {
2125 #[ turbo_tasks:: function]
22- pub fn new ( root : FileSystemPath , glob : ResolvedVc < Glob > ) -> Vc < Self > {
23- AfterResolvePluginCondition { root, glob } . cell ( )
24- }
25-
26- #[ turbo_tasks:: function]
27- pub async fn matches ( & self , fs_path : FileSystemPath ) -> Result < Vc < bool > > {
28- let root = self . root . clone ( ) ;
29- let glob = self . glob . await ?;
30-
31- let path = fs_path;
32-
33- if let Some ( path) = root. get_path_to ( & path)
34- && glob. matches ( path)
35- {
36- return Ok ( Vc :: cell ( true ) ) ;
37- }
38-
39- Ok ( Vc :: cell ( false ) )
26+ pub fn new_with_glob ( root : FileSystemPath , glob : ResolvedVc < Glob > ) -> Vc < Self > {
27+ AfterResolvePluginCondition :: Glob { root, glob } . cell ( )
4028 }
4129}
4230
43- #[ turbo_tasks:: value( transparent) ]
44- pub struct OptionAfterResolvePluginCondition ( Option < ResolvedVc < AfterResolvePluginCondition > > ) ;
45-
4631#[ turbo_tasks:: value_impl]
47- impl OptionAfterResolvePluginCondition {
32+ impl AfterResolvePluginCondition {
4833 #[ turbo_tasks:: function]
49- pub fn none ( ) -> Vc < Self > {
50- Vc :: cell ( None )
51- }
34+ pub async fn matches ( & self , fs_path : FileSystemPath ) -> Result < Vc < bool > > {
35+ match self {
36+ AfterResolvePluginCondition :: Glob { root, glob } => {
37+ let path = fs_path;
38+
39+ if let Some ( path) = root. get_path_to ( & path)
40+ && glob. await ?. matches ( path)
41+ {
42+ return Ok ( Vc :: cell ( true ) ) ;
43+ }
5244
53- #[ turbo_tasks:: function]
54- pub fn some ( condition : ResolvedVc < AfterResolvePluginCondition > ) -> Vc < Self > {
55- Vc :: cell ( Some ( condition) )
45+ Ok ( Vc :: cell ( false ) )
46+ }
47+ AfterResolvePluginCondition :: Always => Ok ( Vc :: cell ( true ) ) ,
48+ AfterResolvePluginCondition :: Never => Ok ( Vc :: cell ( false ) ) ,
49+ }
5650 }
5751}
5852
@@ -61,6 +55,8 @@ impl OptionAfterResolvePluginCondition {
6155pub enum BeforeResolvePluginCondition {
6256 Request ( ResolvedVc < Glob > ) ,
6357 Modules ( FxHashSet < RcStr > ) ,
58+ Always ,
59+ Never ,
6460}
6561
6662#[ turbo_tasks:: value_impl]
@@ -92,30 +88,16 @@ impl BeforeResolvePluginCondition {
9288 false
9389 }
9490 }
91+ BeforeResolvePluginCondition :: Always => true ,
92+ BeforeResolvePluginCondition :: Never => false ,
9593 } ) )
9694 }
9795}
9896
99- #[ turbo_tasks:: value( transparent) ]
100- pub struct OptionBeforeResolvePluginCondition ( Option < ResolvedVc < BeforeResolvePluginCondition > > ) ;
101-
102- #[ turbo_tasks:: value_impl]
103- impl OptionBeforeResolvePluginCondition {
104- #[ turbo_tasks:: function]
105- pub fn none ( ) -> Vc < Self > {
106- Vc :: cell ( None )
107- }
108-
109- #[ turbo_tasks:: function]
110- pub fn some ( condition : ResolvedVc < BeforeResolvePluginCondition > ) -> Vc < Self > {
111- Vc :: cell ( Some ( condition) )
112- }
113- }
114-
11597#[ turbo_tasks:: value_trait]
11698pub trait BeforeResolvePlugin {
11799 #[ turbo_tasks:: function]
118- fn before_resolve_condition ( self : Vc < Self > ) -> Vc < OptionBeforeResolvePluginCondition > ;
100+ fn before_resolve_condition ( self : Vc < Self > ) -> Vc < BeforeResolvePluginCondition > ;
119101
120102 #[ turbo_tasks:: function]
121103 fn before_resolve (
@@ -130,7 +112,7 @@ pub trait BeforeResolvePlugin {
130112pub trait AfterResolvePlugin {
131113 /// A condition which determines if the hooks gets called.
132114 #[ turbo_tasks:: function]
133- fn after_resolve_condition ( self : Vc < Self > ) -> Vc < OptionAfterResolvePluginCondition > ;
115+ fn after_resolve_condition ( self : Vc < Self > ) -> Vc < AfterResolvePluginCondition > ;
134116
135117 /// This hook gets called when a full filepath has been resolved and the
136118 /// condition matches. If a value is returned it replaces the resolve
0 commit comments