Skip to content

Commit b8720d7

Browse files
authored
Reset state when bailing early in fix loop (#507)
1 parent afbbf91 commit b8720d7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/commands/fix/npm-fix.mts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export async function npmFix(
115115

116116
// Lazily access constants.ENV.CI.
117117
const isCi = constants.ENV.CI
118+
const baseBranch = isCi ? getBaseGitBranch() : ''
118119
const workspacePkgJsonPaths = await globWorkspace(
119120
pkgEnvDetails.agent,
120121
rootPath
@@ -243,6 +244,13 @@ export async function npmFix(
243244
// eslint-disable-next-line no-await-in-loop
244245
if (!(await editablePkgJson.save({ ignoreWhitespace: true }))) {
245246
debugLog(`Nothing changed for ${workspaceName}, skipping install`)
247+
// Reset things just in case.
248+
if (isCi) {
249+
// eslint-disable-next-line no-await-in-loop
250+
await gitHardReset(baseBranch, cwd)
251+
// eslint-disable-next-line no-await-in-loop
252+
await gitCleanFdx(cwd)
253+
}
246254
continue
247255
}
248256

@@ -266,7 +274,6 @@ export async function npmFix(
266274
error = e
267275
}
268276

269-
const baseBranch = isCi ? getBaseGitBranch() : ''
270277
if (!errored && isCi) {
271278
const branch = getSocketBranchName(
272279
oldPurl,
@@ -328,7 +335,7 @@ export async function npmFix(
328335
// eslint-disable-next-line no-await-in-loop
329336
await Promise.all([
330337
removeNodeModules(cwd),
331-
editablePkgJson.save()
338+
editablePkgJson.save({ ignoreWhitespace: true })
332339
])
333340
// eslint-disable-next-line no-await-in-loop
334341
await install(arb.idealTree!, { cwd })

src/commands/fix/pnpm-fix.mts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export async function pnpmFix(
142142

143143
// Lazily access constants.ENV.CI.
144144
const isCi = constants.ENV.CI
145+
const baseBranch = isCi ? getBaseGitBranch() : ''
145146
const workspacePkgJsonPaths = await globWorkspace(
146147
pkgEnvDetails.agent,
147148
rootPath
@@ -309,6 +310,13 @@ export async function pnpmFix(
309310
// eslint-disable-next-line no-await-in-loop
310311
if (!(await editablePkgJson.save({ ignoreWhitespace: true }))) {
311312
debugLog(`Nothing changed for ${workspaceName}, skipping install`)
313+
// Reset things just in case.
314+
if (isCi) {
315+
// eslint-disable-next-line no-await-in-loop
316+
await gitHardReset(baseBranch, cwd)
317+
// eslint-disable-next-line no-await-in-loop
318+
await gitCleanFdx(cwd)
319+
}
312320
continue
313321
}
314322

@@ -332,7 +340,6 @@ export async function pnpmFix(
332340
errored = true
333341
}
334342

335-
const baseBranch = isCi ? getBaseGitBranch() : ''
336343
if (!errored && isCi) {
337344
const branch = getSocketBranchName(
338345
oldPurl,
@@ -394,7 +401,7 @@ export async function pnpmFix(
394401
// eslint-disable-next-line no-await-in-loop
395402
await Promise.all([
396403
removeNodeModules(cwd),
397-
editablePkgJson.save()
404+
editablePkgJson.save({ ignoreWhitespace: true })
398405
])
399406
// eslint-disable-next-line no-await-in-loop
400407
actualTree = await install(pkgEnvDetails, { cwd, spinner })

0 commit comments

Comments
 (0)