@@ -168,6 +168,44 @@ const updatePackageLock = async ({ lockFileName, depsToForceUpdate }) => {
168
168
}
169
169
} ;
170
170
171
+ const created = new Date ( ) ;
172
+ created . setUTCHours ( 0 , 0 , 0 , 0 ) ;
173
+
174
+ const updateSnykPolicyWithIgnores = ( vulnerabilityIds ) => {
175
+ const snykPolicyFile = fs . existsSync ( ".snyk" )
176
+ ? fs . readFileSync ( ".snyk" , "utf8" )
177
+ : "ignore: {}\npatch: {}" ;
178
+
179
+ const policy = yaml . load ( snykPolicyFile ) ;
180
+
181
+ const updatedPolicy = {
182
+ ...policy ,
183
+ ignore : {
184
+ ...policy . ignore ,
185
+ ...Object . fromEntries (
186
+ vulnerabilityIds . map ( ( vulnerabilityId ) => [
187
+ vulnerabilityId ,
188
+ [
189
+ {
190
+ "*" : {
191
+ // REF: https://github.com/snyk/cli/blob/main/src/cli/commands/ignore.ts#L59
192
+ reason : "None Given" ,
193
+ // REF: https://github.com/snyk/cli/blob/main/src/cli/commands/ignore.ts#L55
194
+ expires : new Date ( created + 30 * 24 * 60 * 60 * 1000 ) ,
195
+ // REF: https://github.com/snyk/cli/blob/main/src/cli/commands/ignore.ts#L80
196
+ created,
197
+ } ,
198
+ } ,
199
+ ] ,
200
+ ] ) ,
201
+ ) ,
202
+ } ,
203
+ } ;
204
+
205
+ const updatedPolicyFile = yaml . dump ( updatedPolicy ) ;
206
+ fs . writeFileSync ( ".snyk" , updatedPolicyFile ) ;
207
+ } ;
208
+
171
209
const updateSnykPolicyPatches = ( patchablePackages ) => {
172
210
const snykPolicyFile = fs . existsSync ( ".snyk" )
173
211
? fs . readFileSync ( ".snyk" , "utf8" )
@@ -388,13 +426,12 @@ const snyker = async () => {
388
426
389
427
const uniqueVulnerabilityIds = unique ( vulnerabilityIds ) ;
390
428
uniqueVulnerabilityIds . forEach ( ( id ) => console . log ( `\t- ${ id } ` ) ) ;
429
+
430
+ updateSnykPolicyWithIgnores ( uniqueVulnerabilityIds ) ;
431
+
391
432
// Intentional newline
392
433
console . log ( ) ;
393
434
394
- for ( const id of uniqueVulnerabilityIds ) {
395
- await exec ( "npx" , [ "snyk" , "ignore" , `--id=${ id } ` ] ) ;
396
- }
397
-
398
435
if ( upgradablePackages . length ) {
399
436
const installCommand = isYarn ? "yarn upgrade" : "npm install" ;
400
437
const upgradablePackagesStr = unique ( upgradablePackages ) . reduce (
@@ -413,6 +450,7 @@ const snyker = async () => {
413
450
unique ( patchablePackages . map ( ( { id } ) => id ) ) . forEach ( ( id ) =>
414
451
console . log ( `\t- ${ id } ` ) ,
415
452
) ;
453
+
416
454
// Intentional newline
417
455
console . log ( ) ;
418
456
updateSnykPolicyPatches ( patchablePackages ) ;
0 commit comments