@@ -86,6 +86,43 @@ impl PackageChangeMapper for DefaultPackageChangeMapper<'_> {
86
86
}
87
87
}
88
88
89
+ pub struct DefaultPackageChangeMapperWithLockfile < ' a > {
90
+ base : DefaultPackageChangeMapper < ' a > ,
91
+ }
92
+
93
+ impl < ' a > DefaultPackageChangeMapperWithLockfile < ' a > {
94
+ pub fn new ( pkg_dep_graph : & ' a PackageGraph ) -> Self {
95
+ Self {
96
+ base : DefaultPackageChangeMapper :: new ( pkg_dep_graph) ,
97
+ }
98
+ }
99
+ }
100
+
101
+ impl PackageChangeMapper for DefaultPackageChangeMapperWithLockfile < ' _ > {
102
+ fn detect_package ( & self , path : & AnchoredSystemPath ) -> PackageMapping {
103
+ // If we have a lockfile change, we consider this as a root package change,
104
+ // since there's a chance that the root package uses a workspace package
105
+ // dependency (this is cursed behavior but sadly possible). There's a chance
106
+ // that we can make this more accurate by checking which package
107
+ // manager, since not all package managers may permit root pulling from
108
+ // workspace package dependencies
109
+ if PackageManager :: supported_managers ( )
110
+ . iter ( )
111
+ . any ( |pm| pm. lockfile_name ( ) == path. as_str ( ) )
112
+ {
113
+ PackageMapping :: Package ( (
114
+ WorkspacePackage {
115
+ name : PackageName :: Root ,
116
+ path : AnchoredSystemPathBuf :: from_raw ( "" ) . unwrap ( ) ,
117
+ } ,
118
+ PackageInclusionReason :: ConservativeRootLockfileChanged ,
119
+ ) )
120
+ } else {
121
+ self . base . detect_package ( path)
122
+ }
123
+ }
124
+ }
125
+
89
126
#[ derive( Error , Debug ) ]
90
127
pub enum Error {
91
128
#[ error( transparent) ]
@@ -101,7 +138,7 @@ pub enum Error {
101
138
/// changes all packages. Since we have a list of global deps,
102
139
/// we can check against that and avoid invalidating in unnecessary cases.
103
140
pub struct GlobalDepsPackageChangeMapper < ' a > {
104
- pkg_dep_graph : & ' a PackageGraph ,
141
+ base : DefaultPackageChangeMapperWithLockfile < ' a > ,
105
142
global_deps_matcher : wax:: Any < ' a > ,
106
143
}
107
144
@@ -110,36 +147,19 @@ impl<'a> GlobalDepsPackageChangeMapper<'a> {
110
147
pkg_dep_graph : & ' a PackageGraph ,
111
148
global_deps : I ,
112
149
) -> Result < Self , Error > {
150
+ let base = DefaultPackageChangeMapperWithLockfile :: new ( pkg_dep_graph) ;
113
151
let global_deps_matcher = wax:: any ( global_deps) ?;
114
152
115
153
Ok ( Self {
116
- pkg_dep_graph ,
154
+ base ,
117
155
global_deps_matcher,
118
156
} )
119
157
}
120
158
}
121
159
122
160
impl PackageChangeMapper for GlobalDepsPackageChangeMapper < ' _ > {
123
161
fn detect_package ( & self , path : & AnchoredSystemPath ) -> PackageMapping {
124
- // If we have a lockfile change, we consider this as a root package change,
125
- // since there's a chance that the root package uses a workspace package
126
- // dependency (this is cursed behavior but sadly possible). There's a chance
127
- // that we can make this more accurate by checking which package
128
- // manager, since not all package managers may permit root pulling from
129
- // workspace package dependencies
130
- if PackageManager :: supported_managers ( )
131
- . iter ( )
132
- . any ( |pm| pm. lockfile_name ( ) == path. as_str ( ) )
133
- {
134
- return PackageMapping :: Package ( (
135
- WorkspacePackage {
136
- name : PackageName :: Root ,
137
- path : AnchoredSystemPathBuf :: from_raw ( "" ) . unwrap ( ) ,
138
- } ,
139
- PackageInclusionReason :: ConservativeRootLockfileChanged ,
140
- ) ) ;
141
- }
142
- match DefaultPackageChangeMapper :: new ( self . pkg_dep_graph ) . detect_package ( path) {
162
+ match self . base . detect_package ( path) {
143
163
// Since `DefaultPackageChangeMapper` is overly conservative, we can check here if
144
164
// the path is actually in globalDeps and if not, return it as
145
165
// PackageDetection::Package(WorkspacePackage::root()).
0 commit comments