@@ -225,18 +225,6 @@ export async function pnpmFix(
225225 const newSpec = `${ name } @${ newVersionRange } `
226226 const newSpecKey = `${ workspaceName ? `${ workspaceName } >` : '' } ${ newSpec } `
227227
228- const branch = isCi
229- ? getSocketBranchName ( oldPurl , newVersion , workspaceName )
230- : ''
231- const baseBranch = isCi ? getBaseGitBranch ( ) : ''
232- const { owner, repo } = isCi
233- ? getGitHubEnvRepoInfo ( )
234- : { owner : '' , repo : '' }
235- const shouldOpenPr = isCi
236- ? // eslint-disable-next-line no-await-in-loop
237- ! ( await doesPullRequestExistForBranch ( owner , repo , branch ) )
238- : false
239-
240228 const updateData = isWorkspaceRoot
241229 ? {
242230 [ PNPM ] : {
@@ -247,7 +235,7 @@ export async function pnpmFix(
247235 }
248236 }
249237 }
250- : { }
238+ : undefined
251239
252240 const revertData = {
253241 ...( isWorkspaceRoot
@@ -280,34 +268,50 @@ export async function pnpmFix(
280268 : undefined )
281269 } as PackageJson
282270
283- if ( ! installedSpecs . has ( newSpecKey ) ) {
284- installedSpecs . add ( newSpecKey )
285- spinner ?. info ( `Installing ${ newSpec } ${ workspaceDetails } ` )
286- }
271+ const branch = isCi
272+ ? getSocketBranchName ( oldPurl , newVersion , workspaceName )
273+ : ''
274+ const baseBranch = isCi ? getBaseGitBranch ( ) : ''
275+ const { owner, repo } = isCi
276+ ? getGitHubEnvRepoInfo ( )
277+ : { owner : '' , repo : '' }
278+ const shouldOpenPr = isCi
279+ ? // eslint-disable-next-line no-await-in-loop
280+ ! ( await doesPullRequestExistForBranch ( owner , repo , branch ) )
281+ : false
287282
288283 if ( isCi ) {
289284 // eslint-disable-next-line no-await-in-loop
290285 await gitCheckoutBaseBranchIfAvailable ( baseBranch , cwd )
291286 }
292287
288+ if ( updateData ) {
289+ editablePkgJson . update ( updateData )
290+ }
291+
292+ updatePackageJsonFromNode (
293+ editablePkgJson ,
294+ actualTree ,
295+ node ,
296+ newVersion ,
297+ rangeStyle
298+ )
299+
293300 let error : unknown
294301 let errored = false
295302 let installed = false
296- let saved = false
303+
304+ // eslint-disable-next-line no-await-in-loop
305+ if ( ! ( await editablePkgJson . save ( ) ) ) {
306+ continue
307+ }
308+
309+ if ( ! installedSpecs . has ( newSpecKey ) ) {
310+ installedSpecs . add ( newSpecKey )
311+ spinner ?. info ( `Installing ${ newSpec } ${ workspaceDetails } ` )
312+ }
313+
297314 try {
298- editablePkgJson . update ( updateData )
299- updatePackageJsonFromNode (
300- editablePkgJson ,
301- actualTree ,
302- node ,
303- newVersion ,
304- rangeStyle
305- )
306- // eslint-disable-next-line no-await-in-loop
307- if ( ! ( await editablePkgJson . save ( ) ) ) {
308- continue
309- }
310- saved = true
311315 // eslint-disable-next-line no-await-in-loop
312316 actualTree = await install ( pkgEnvDetails , { spinner } )
313317 installed = true
@@ -320,7 +324,6 @@ export async function pnpmFix(
320324 // eslint-disable-next-line no-await-in-loop
321325 await runScript ( testScript , [ ] , { spinner, stdio : 'ignore' } )
322326 }
323-
324327 if ( ! fixedSpecs . has ( newSpecKey ) ) {
325328 fixedSpecs . add ( newSpecKey )
326329 spinner ?. successAndStop ( `Fixed ${ name } ${ workspaceDetails } ` )
@@ -364,21 +367,15 @@ export async function pnpmFix(
364367 spinner ?. error ( `Reverting ${ newSpec } ${ workspaceDetails } ` , error )
365368 }
366369 }
370+ editablePkgJson . update ( revertData )
367371 if ( isRepo ) {
368372 // eslint-disable-next-line no-await-in-loop
369373 await gitHardReset ( cwd )
370- }
371- if ( saved ) {
372- editablePkgJson . update ( revertData )
373- if ( ! isRepo ) {
374- // eslint-disable-next-line no-await-in-loop
375- await editablePkgJson . save ( )
376- }
377- }
378- if ( isRepo ) {
379374 // eslint-disable-next-line no-await-in-loop
380375 actualTree = await getActualTree ( cwd )
381376 } else if ( installed ) {
377+ // eslint-disable-next-line no-await-in-loop
378+ await editablePkgJson . save ( )
382379 // eslint-disable-next-line no-await-in-loop
383380 actualTree = await install ( pkgEnvDetails , { spinner } )
384381 }
0 commit comments