1- import { existsSync , promises as fs } from 'node:fs'
1+ import { existsSync } from 'node:fs'
22import path from 'node:path'
33
44import semver from 'semver'
@@ -45,7 +45,6 @@ import {
4545} from '../../shadow/npm/arborist-helpers.mts'
4646import { removeNodeModules } from '../../utils/fs.mts'
4747import { globWorkspace } from '../../utils/glob.mts'
48- import { readLockfile } from '../../utils/lockfile.mts'
4948import { getPurlObject } from '../../utils/purl.mts'
5049import { applyRange } from '../../utils/semver.mts'
5150import { getCveInfoFromAlertsMap } from '../../utils/socket-package-alert.mts'
@@ -104,12 +103,13 @@ export async function agentFix(
104103 alertsMap : AlertsByPurl ,
105104 installer : Installer ,
106105 {
107- beforeInstall = noopHandler ,
108- // eslint-disable-next-line sort-destructure-keys/sort-destructure-keys
109106 afterInstall = noopHandler ,
107+ afterUpdate = noopHandler ,
108+ beforeInstall = noopHandler ,
110109 revertInstall = noopHandler ,
111110 } : {
112111 beforeInstall ?: InstallPhaseHandler | undefined
112+ afterUpdate ?: InstallPhaseHandler | undefined
113113 afterInstall ?: InstallPhaseHandler | undefined
114114 revertInstall ?: InstallPhaseHandler | undefined
115115 } ,
@@ -382,6 +382,16 @@ export async function agentFix(
382382 // eslint-disable-next-line no-await-in-loop
383383 await editablePkgJson . save ( { ignoreWhitespace : true } )
384384
385+ // eslint-disable-next-line no-await-in-loop
386+ await afterUpdate (
387+ editablePkgJson ,
388+ packument ,
389+ oldVersion ,
390+ newVersion ,
391+ vulnerableVersionRange ,
392+ fixConfig ,
393+ )
394+
385395 // eslint-disable-next-line no-await-in-loop
386396 const unstagedCResult = await gitUnstagedModifiedFiles ( cwd )
387397 const moddedFilepaths = unstagedCResult . ok
@@ -407,14 +417,6 @@ export async function agentFix(
407417 continue infosLoop
408418 }
409419
410- // eslint-disable-next-line no-await-in-loop
411- const pkgJsonSrc = await fs . readFile (
412- editablePkgJson . filename ! ,
413- 'utf8' ,
414- )
415- // eslint-disable-next-line no-await-in-loop
416- const lockSrc = await readLockfile ( pkgEnvDetails . lockPath )
417-
418420 if ( ! hasAnnouncedWorkspace ) {
419421 hasAnnouncedWorkspace = true
420422 workspaceLogCallCount = logger . logCallCount
@@ -463,11 +465,6 @@ export async function agentFix(
463465
464466 // Check repoInfo to make TypeScript happy.
465467 if ( ! errored && fixEnv . isCi && fixEnv . repoInfo ) {
466- // Rewrite files in case the install reverted them.
467- // eslint-disable-next-line no-await-in-loop
468- await fs . writeFile ( editablePkgJson . filename ! , pkgJsonSrc , 'utf8' )
469- // eslint-disable-next-line no-await-in-loop
470- await fs . writeFile ( pkgEnvDetails . lockPath , lockSrc ! , 'utf8' )
471468 try {
472469 if (
473470 // eslint-disable-next-line no-await-in-loop
0 commit comments