@@ -96,6 +96,8 @@ export async function npmFix(
9696 }
9797
9898 const editablePkgJson = await readPackageJson ( cwd , { editable : true } )
99+ // Lazily access constants.ENV[CI].
100+ const isCi = constants . ENV [ CI ]
99101
100102 await arb . buildIdealTree ( )
101103
@@ -144,29 +146,22 @@ export async function npmFix(
144146 firstPatchedVersionIdentifier
145147 )
146148 ) {
147- spinner ?. failAndStop ( `Could not patch ${ fromSpec } ` )
148- return
149+ spinner ?. fail ( `Could not patch ${ fromSpec } ` )
150+ continue
149151 }
150152
151153 const toVersion = node . package . version !
152154 const toVersionRange = applyRange ( fromVersion , toVersion , rangeStyle )
153155 const toSpec = `${ name } @${ toVersionRange } `
154156
155- let branch : string | undefined
156- let owner : string | undefined
157- let repo : string | undefined
158- let shouldOpenPr = false
159- // Lazily access constants.ENV[CI].
160- if ( constants . ENV [ CI ] ) {
161- ; ( { owner, repo } = getGitHubEnvRepoInfo ( ) )
162- branch = getSocketBranchName ( fromPurl , toVersion )
163- // eslint-disable-next-line no-await-in-loop
164- shouldOpenPr = ! ( await doesPullRequestExistForBranch (
165- owner ,
166- repo ,
167- branch
168- ) )
169- }
157+ const branch = isCi ? getSocketBranchName ( fromPurl , toVersion ) : ''
158+ const { owner, repo } = isCi
159+ ? getGitHubEnvRepoInfo ( )
160+ : { owner : '' , repo : '' }
161+ const shouldOpenPr = isCi
162+ ? // eslint-disable-next-line no-await-in-loop
163+ ! ( await doesPullRequestExistForBranch ( owner , repo , branch ) )
164+ : false
170165
171166 const revertData = {
172167 ...( editablePkgJson . content . dependencies
@@ -190,6 +185,8 @@ export async function npmFix(
190185 // eslint-disable-next-line no-await-in-loop
191186 await checkoutBaseBranchIfAvailable ( baseBranch , cwd )
192187
188+ let error : unknown
189+ let errored = false
193190 let installed = false
194191 let saved = false
195192 try {
@@ -215,22 +212,12 @@ export async function npmFix(
215212 }
216213 spinner ?. successAndStop ( `Fixed ${ name } ` )
217214 spinner ?. start ( )
218- } catch {
219- spinner ?. error ( `Reverting ${ toSpec } ` )
220- if ( saved ) {
221- editablePkgJson . update ( revertData )
222- // eslint-disable-next-line no-await-in-loop
223- await editablePkgJson . save ( )
224- }
225- if ( installed ) {
226- // eslint-disable-next-line no-await-in-loop
227- await install ( revertTree , { cwd } )
228- }
229- spinner ?. failAndStop ( `Failed to fix ${ fromSpec } ` )
230- return
215+ } catch ( e ) {
216+ error = e
217+ errored = true
231218 }
232219
233- if ( shouldOpenPr ) {
220+ if ( ! errored && shouldOpenPr ) {
234221 // eslint-disable-next-line no-await-in-loop
235222 await createAndPushBranchIfNeeded (
236223 branch ! ,
@@ -252,6 +239,24 @@ export async function npmFix(
252239 await enableAutoMerge ( prResponse . data )
253240 }
254241 }
242+
243+ if ( errored || isCi ) {
244+ if ( errored ) {
245+ spinner ?. error ( `Reverting ${ toSpec } ` , error )
246+ }
247+ if ( saved ) {
248+ editablePkgJson . update ( revertData )
249+ // eslint-disable-next-line no-await-in-loop
250+ await editablePkgJson . save ( )
251+ }
252+ if ( installed ) {
253+ // eslint-disable-next-line no-await-in-loop
254+ await install ( revertTree , { cwd } )
255+ }
256+ if ( errored ) {
257+ spinner ?. failAndStop ( `Failed to fix ${ fromSpec } ` )
258+ }
259+ }
255260 }
256261 }
257262 }
0 commit comments