Skip to content

Commit 1e515c3

Browse files
committed
Revert changes in between prs
1 parent 7c35eec commit 1e515c3

File tree

2 files changed

+71
-61
lines changed

2 files changed

+71
-61
lines changed

src/commands/fix/npm-fix.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/commands/fix/pnpm-fix.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export async function pnpmFix(
103103
spinner?.start()
104104

105105
const editablePkgJson = await readPackageJson(cwd, { editable: true })
106+
// Lazily access constants.ENV[CI].
107+
const isCi = constants.ENV[CI]
106108

107109
let actualTree = await getActualTree(cwd)
108110

@@ -151,8 +153,8 @@ export async function pnpmFix(
151153
: undefined
152154

153155
if (!(toVersion && targetPackument)) {
154-
spinner?.failAndStop(`Could not patch ${fromSpec}`)
155-
return
156+
spinner?.fail(`Could not patch ${fromSpec}`)
157+
continue
156158
}
157159

158160
const oldPnpm = editablePkgJson.content[PNPM] as
@@ -175,21 +177,14 @@ export async function pnpmFix(
175177
)
176178
const toSpec = `${name}@${toVersionRange}`
177179

178-
let branch: string | undefined
179-
let owner: string | undefined
180-
let repo: string | undefined
181-
let shouldOpenPr = false
182-
// Lazily access constants.ENV[CI].
183-
if (constants.ENV[CI]) {
184-
;({ owner, repo } = getGitHubEnvRepoInfo())
185-
branch = getSocketBranchName(fromPurl, toVersion)
186-
// eslint-disable-next-line no-await-in-loop
187-
shouldOpenPr = !(await doesPullRequestExistForBranch(
188-
owner,
189-
repo,
190-
branch
191-
))
192-
}
180+
const branch = isCi ? getSocketBranchName(fromPurl, toVersion) : ''
181+
const { owner, repo } = isCi
182+
? getGitHubEnvRepoInfo()
183+
: { owner: '', repo: '' }
184+
const shouldOpenPr = isCi
185+
? // eslint-disable-next-line no-await-in-loop
186+
!(await doesPullRequestExistForBranch(owner, repo, branch))
187+
: false
193188

194189
const updateData = {
195190
[PNPM]: {
@@ -235,6 +230,8 @@ export async function pnpmFix(
235230
// eslint-disable-next-line no-await-in-loop
236231
await checkoutBaseBranchIfAvailable(baseBranch, cwd)
237232

233+
let error: unknown
234+
let errored = false
238235
let installed = false
239236
let saved = false
240237
try {
@@ -262,21 +259,11 @@ export async function pnpmFix(
262259
spinner?.successAndStop(`Fixed ${name}`)
263260
spinner?.start()
264261
} catch (e) {
265-
spinner?.error(`Reverting ${toSpec}`, e)
266-
if (saved) {
267-
editablePkgJson.update(revertData)
268-
// eslint-disable-next-line no-await-in-loop
269-
await editablePkgJson.save()
270-
}
271-
if (installed) {
272-
// eslint-disable-next-line no-await-in-loop
273-
actualTree = await install(pkgEnvDetails, { spinner })
274-
}
275-
spinner?.failAndStop(`Failed to fix ${fromSpec}`)
276-
return
262+
error = e
263+
errored = true
277264
}
278265

279-
if (shouldOpenPr) {
266+
if (!errored && shouldOpenPr) {
280267
// eslint-disable-next-line no-await-in-loop
281268
await createAndPushBranchIfNeeded(
282269
branch!,
@@ -298,6 +285,24 @@ export async function pnpmFix(
298285
await enableAutoMerge(prResponse.data)
299286
}
300287
}
288+
289+
if (errored || isCi) {
290+
if (errored) {
291+
spinner?.error(`Reverting ${toSpec}`, error)
292+
}
293+
if (saved) {
294+
editablePkgJson.update(revertData)
295+
// eslint-disable-next-line no-await-in-loop
296+
await editablePkgJson.save()
297+
}
298+
if (installed) {
299+
// eslint-disable-next-line no-await-in-loop
300+
actualTree = await install(pkgEnvDetails, { spinner })
301+
}
302+
if (errored) {
303+
spinner?.failAndStop(`Failed to fix ${fromSpec}`)
304+
}
305+
}
301306
}
302307
}
303308
}

0 commit comments

Comments
 (0)