@@ -51,6 +51,7 @@ pub struct SetWorkspaceConfigOptions {
51
51
pub struct WorkspaceConfig {
52
52
pub root : WorkspaceMemberConfig ,
53
53
pub members : HashMap < String , WorkspaceMemberConfig > ,
54
+ pub patches : HashMap < String , LockfilePatchContent > ,
54
55
}
55
56
56
57
#[ derive( Default , Debug , Clone , PartialEq , Eq ) ]
@@ -62,7 +63,8 @@ pub struct WorkspaceMemberConfig {
62
63
#[ derive( Debug , Clone , PartialEq , Eq ) ]
63
64
pub struct NpmPackageLockfileInfo {
64
65
pub serialized_id : StackString ,
65
- pub integrity : String ,
66
+ /// Will be `None` for patch packages.
67
+ pub integrity : Option < String > ,
66
68
pub dependencies : Vec < NpmPackageDependencyLockfileInfo > ,
67
69
}
68
70
@@ -74,7 +76,8 @@ pub struct NpmPackageDependencyLockfileInfo {
74
76
75
77
#[ derive( Debug , Clone , Serialize , Deserialize , Hash , PartialEq , Eq ) ]
76
78
pub struct NpmPackageInfo {
77
- pub integrity : String ,
79
+ /// Will be `None` for patch packages.
80
+ pub integrity : Option < String > ,
78
81
#[ serde( default ) ]
79
82
pub dependencies : BTreeMap < StackString , StackString > ,
80
83
}
@@ -162,18 +165,34 @@ impl WorkspaceMemberConfigContent {
162
165
}
163
166
}
164
167
168
+ #[ derive( Debug , Default , Clone , Deserialize , PartialEq , Eq ) ]
169
+ #[ serde( rename_all = "camelCase" ) ]
170
+ pub struct LockfilePatchContent {
171
+ #[ serde( default ) ]
172
+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
173
+ pub dependencies : HashSet < JsrDepPackageReq > ,
174
+ #[ serde( default ) ]
175
+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
176
+ pub peer_dependencies : HashSet < JsrDepPackageReq > ,
177
+ #[ serde( default ) ]
178
+ #[ serde( skip_serializing_if = "HashMap::is_empty" ) ]
179
+ pub peer_dependencies_meta : HashMap < String , serde_json:: Value > ,
180
+ }
181
+
165
182
#[ derive( Debug , Default , Clone , Deserialize ) ]
166
183
#[ serde( rename_all = "camelCase" ) ]
167
184
pub ( crate ) struct WorkspaceConfigContent {
168
185
#[ serde( default , flatten) ]
169
186
pub root : WorkspaceMemberConfigContent ,
170
187
#[ serde( default ) ]
171
188
pub members : HashMap < String , WorkspaceMemberConfigContent > ,
189
+ #[ serde( default ) ]
190
+ pub patches : HashMap < String , LockfilePatchContent > ,
172
191
}
173
192
174
193
impl WorkspaceConfigContent {
175
194
pub fn is_empty ( & self ) -> bool {
176
- self . root . is_empty ( ) && self . members . is_empty ( )
195
+ self . root . is_empty ( ) && self . members . is_empty ( ) && self . patches . is_empty ( )
177
196
}
178
197
179
198
fn get_all_dep_reqs ( & self ) -> impl Iterator < Item = & JsrDepPackageReq > {
@@ -209,7 +228,7 @@ impl LockfileContent {
209
228
210
229
#[ derive( Debug , Deserialize ) ]
211
230
struct RawNpmPackageInfo {
212
- pub integrity : String ,
231
+ pub integrity : Option < String > ,
213
232
#[ serde( default ) ]
214
233
pub dependencies : Vec < StackString > ,
215
234
}
@@ -577,6 +596,40 @@ impl Lockfile {
577
596
// to !self.has_content_changed after populating it with this information
578
597
let allow_content_changed =
579
598
self . has_content_changed || !self . content . is_empty ( ) ;
599
+
600
+ let has_any_patch_changed = options. config . patches . len ( )
601
+ != self . content . workspace . patches . len ( )
602
+ || !options. config . patches . is_empty ( )
603
+ && options. config . patches . iter ( ) . all ( |( patch, new) | {
604
+ let Some ( existing) = self . content . workspace . patches . get_mut ( patch)
605
+ else {
606
+ return true ;
607
+ } ;
608
+ new != existing
609
+ } ) ;
610
+
611
+ // if a patch changes, it's quite complicated to figure out how to get it to redo
612
+ // npm resolution just for that part, so for now, clear out all the npm dependencies
613
+ // if any patch changes
614
+ if has_any_patch_changed {
615
+ self . has_content_changed = true ;
616
+ self . content . packages . npm . clear ( ) ;
617
+ self
618
+ . content
619
+ . packages
620
+ . specifiers
621
+ . retain ( |k, _| match k. kind {
622
+ deno_semver:: package:: PackageKind :: Jsr => true ,
623
+ deno_semver:: package:: PackageKind :: Npm => false ,
624
+ } ) ;
625
+ self . content . workspace . patches . clear ( ) ;
626
+ self
627
+ . content
628
+ . workspace
629
+ . patches
630
+ . extend ( options. config . patches ) ;
631
+ }
632
+
580
633
let old_deps = self
581
634
. content
582
635
. workspace
@@ -1015,7 +1068,7 @@ mod tests {
1015
1068
// already in lockfile
1016
1069
let npm_package = NpmPackageLockfileInfo {
1017
1070
serialized_id : "[email protected] " . into ( ) ,
1018
- integrity : "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==" . to_string ( ) ,
1071
+ integrity : Some ( "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==" . to_string ( ) ) ,
1019
1072
dependencies : vec ! [ ] ,
1020
1073
} ;
1021
1074
lockfile. insert_npm_package ( npm_package) ;
@@ -1024,7 +1077,7 @@ mod tests {
1024
1077
// insert package that exists already, but has slightly different properties
1025
1078
let npm_package = NpmPackageLockfileInfo {
1026
1079
serialized_id : "[email protected] " . into ( ) ,
1027
- integrity : "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" . to_string ( ) ,
1080
+ integrity : Some ( "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" . to_string ( ) ) ,
1028
1081
dependencies : vec ! [ ] ,
1029
1082
} ;
1030
1083
lockfile. insert_npm_package ( npm_package) ;
@@ -1033,7 +1086,7 @@ mod tests {
1033
1086
lockfile. has_content_changed = false ;
1034
1087
let npm_package = NpmPackageLockfileInfo {
1035
1088
serialized_id : "[email protected] " . into ( ) ,
1036
- integrity : "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==" . to_string ( ) ,
1089
+ integrity : Some ( "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==" . to_string ( ) ) ,
1037
1090
dependencies : vec ! [ ] ,
1038
1091
} ;
1039
1092
// Not present in lockfile yet, should be inserted
@@ -1047,7 +1100,7 @@ mod tests {
1047
1100
1048
1101
let npm_package = NpmPackageLockfileInfo {
1049
1102
serialized_id : "[email protected] " . into ( ) ,
1050
- integrity : "sha512-foobar" . to_string ( ) ,
1103
+ integrity : Some ( "sha512-foobar" . to_string ( ) ) ,
1051
1104
dependencies : vec ! [ ] ,
1052
1105
} ;
1053
1106
// Now present in lockfile, should be changed due to different integrity
0 commit comments