3
3
instance:: Instance ,
4
4
instance_state:: InstanceState ,
5
5
package_json:: PackageJson ,
6
- specifier:: { orderable :: IsOrderable , semver :: Semver , simple_semver :: SimpleSemver , Specifier } ,
6
+ specifier:: { semver_range :: SemverRange , Specifier } ,
7
7
version_group:: VersionGroupVariant ,
8
8
} ,
9
9
itertools:: Itertools ,
@@ -26,9 +26,9 @@ pub struct Dependency {
26
26
/// If this dependency is a local package, this is the local instance.
27
27
pub local_instance : RefCell < Option < Rc < Instance > > > ,
28
28
/// Does every instance match the filter options provided via the CLI?
29
- pub matches_cli_filter : RefCell < bool > ,
29
+ pub matches_cli_filter : bool ,
30
30
/// The name of the dependency
31
- pub name_internal : String ,
31
+ pub internal_name : String ,
32
32
/// The version to pin all instances to when variant is `Pinned`
33
33
pub pinned_specifier : Option < Specifier > ,
34
34
/// package.json files developed in the monorepo when variant is `SnappedTo`
@@ -39,7 +39,7 @@ pub struct Dependency {
39
39
40
40
impl Dependency {
41
41
pub fn new (
42
- name_internal : String ,
42
+ internal_name : String ,
43
43
variant : VersionGroupVariant ,
44
44
pinned_specifier : Option < Specifier > ,
45
45
snapped_to_packages : Option < Vec < Rc < RefCell < PackageJson > > > > ,
@@ -48,8 +48,8 @@ impl Dependency {
48
48
expected : RefCell :: new ( None ) ,
49
49
instances : RefCell :: new ( vec ! [ ] ) ,
50
50
local_instance : RefCell :: new ( None ) ,
51
- matches_cli_filter : RefCell :: new ( false ) ,
52
- name_internal ,
51
+ matches_cli_filter : true ,
52
+ internal_name ,
53
53
pinned_specifier,
54
54
snapped_to_packages,
55
55
variant,
@@ -68,7 +68,7 @@ impl Dependency {
68
68
. instances
69
69
. borrow ( )
70
70
. iter ( )
71
- . map ( |instance| instance. actual_specifier . clone ( ) )
71
+ . map ( |instance| instance. descriptor . specifier . clone ( ) )
72
72
. collect ( ) ;
73
73
set. into_iter ( ) . collect ( )
74
74
}
@@ -95,8 +95,8 @@ impl Dependency {
95
95
pub fn get_instances_by_specifier ( & self ) -> BTreeMap < String , Vec < Rc < Instance > > > {
96
96
let mut map = BTreeMap :: new ( ) ;
97
97
for instance in self . instances . borrow ( ) . iter ( ) {
98
- let specifier = instance. actual_specifier . unwrap ( ) ;
99
- map. entry ( specifier ) . or_insert_with ( Vec :: new) . push ( Rc :: clone ( instance) ) ;
98
+ let raw = instance. descriptor . specifier . get_raw ( ) ;
99
+ map. entry ( raw ) . or_insert_with ( Vec :: new) . push ( Rc :: clone ( instance) ) ;
100
100
}
101
101
map
102
102
}
@@ -111,30 +111,32 @@ impl Dependency {
111
111
. local_instance
112
112
. borrow ( )
113
113
. as_ref ( )
114
- . map ( |instance| instance. actual_specifier . clone ( ) )
114
+ . map ( |instance| instance. descriptor . specifier . clone ( ) )
115
115
}
116
116
117
117
pub fn has_local_instance ( & self ) -> bool {
118
118
self . local_instance . borrow ( ) . is_some ( )
119
119
}
120
120
121
121
pub fn has_local_instance_with_invalid_specifier ( & self ) -> bool {
122
- self . has_local_instance ( )
123
- && !matches ! (
124
- self . get_local_specifier( ) . unwrap( ) ,
125
- Specifier :: Semver ( Semver :: Simple ( SimpleSemver :: Exact ( _) ) )
126
- )
122
+ self . get_local_specifier ( ) . is_some_and ( |local| {
123
+ if let Specifier :: BasicSemver ( semver) = local {
124
+ !matches ! ( semver. range_variant, SemverRange :: Exact )
125
+ } else {
126
+ true
127
+ }
128
+ } )
127
129
}
128
130
129
131
/// Does every instance in this group have a specifier which is exactly the
130
132
/// same?
131
133
pub fn every_specifier_is_already_identical ( & self ) -> bool {
132
- if let Some ( first_actual) = self . instances . borrow ( ) . first ( ) . map ( |instance| & instance. actual_specifier ) {
134
+ if let Some ( first_actual) = self . instances . borrow ( ) . first ( ) . map ( |instance| & instance. descriptor . specifier ) {
133
135
self
134
136
. instances
135
137
. borrow ( )
136
138
. iter ( )
137
- . all ( |instance| instance. actual_specifier == * first_actual)
139
+ . all ( |instance| instance. descriptor . specifier == * first_actual)
138
140
} else {
139
141
false
140
142
}
@@ -148,15 +150,13 @@ impl Dependency {
148
150
. instances
149
151
. borrow ( )
150
152
. iter ( )
151
- . filter ( |instance| instance. actual_specifier . is_simple_semver ( ) )
152
- . map ( |instance| instance. actual_specifier . clone ( ) )
153
+ . filter ( |instance| instance. descriptor . specifier . is_basic_semver ( ) )
154
+ . map ( |instance| instance. descriptor . specifier . clone ( ) )
153
155
. fold ( None , |preferred, specifier| match preferred {
154
156
None => Some ( specifier) ,
155
157
Some ( preferred) => {
156
- let a = specifier. get_orderable ( ) ;
157
- let b = preferred. get_orderable ( ) ;
158
- if a. cmp ( & b) == preferred_order {
159
- Some ( specifier. clone ( ) )
158
+ if specifier. cmp ( & preferred) == preferred_order {
159
+ Some ( specifier)
160
160
} else {
161
161
Some ( preferred)
162
162
}
@@ -175,10 +175,10 @@ impl Dependency {
175
175
pub fn get_snapped_to_specifier ( & self , every_instance_in_the_project : & [ Rc < Instance > ] ) -> Option < Specifier > {
176
176
if let Some ( snapped_to_packages) = & self . snapped_to_packages {
177
177
for instance in every_instance_in_the_project {
178
- if * instance. name_internal . borrow ( ) == * self . name_internal {
178
+ if * instance. internal_name == * self . internal_name {
179
179
for snapped_to_package in snapped_to_packages {
180
180
if instance. package . borrow ( ) . name == snapped_to_package. borrow ( ) . name {
181
- return Some ( instance. actual_specifier . clone ( ) ) ;
181
+ return Some ( instance. descriptor . specifier . clone ( ) ) ;
182
182
}
183
183
}
184
184
}
@@ -203,13 +203,13 @@ impl Dependency {
203
203
if matches ! ( * b. state. borrow( ) , InstanceState :: Valid ( _) ) && !matches ! ( * a. state. borrow( ) , InstanceState :: Valid ( _) ) {
204
204
return Ordering :: Greater ;
205
205
}
206
- if matches ! ( & a. actual_specifier , Specifier :: None ) {
206
+ if matches ! ( & a. descriptor . specifier , Specifier :: None ) {
207
207
return Ordering :: Greater ;
208
208
}
209
- if matches ! ( & b. actual_specifier , Specifier :: None ) {
209
+ if matches ! ( & b. descriptor . specifier , Specifier :: None ) {
210
210
return Ordering :: Less ;
211
211
}
212
- let specifier_order = b. actual_specifier . unwrap ( ) . cmp ( & a. actual_specifier . unwrap ( ) ) ;
212
+ let specifier_order = b. descriptor . specifier . cmp ( & a. descriptor . specifier ) ;
213
213
if matches ! ( specifier_order, Ordering :: Equal ) {
214
214
a. package . borrow ( ) . name . cmp ( & b. package . borrow ( ) . name )
215
215
} else {
0 commit comments