Skip to content

Commit fa63477

Browse files
authored
Log install status after starting install (#453)
1 parent 5a0b69e commit fa63477

File tree

2 files changed

+71
-70
lines changed

2 files changed

+71
-70
lines changed

src/commands/fix/npm-fix.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,6 @@ export async function npmFix(
195195
const newSpec = `${name}@${newVersionRange}`
196196
const newSpecKey = `${workspaceName ? `${workspaceName}>` : ''}${newSpec}`
197197

198-
const branch = isCi
199-
? getSocketBranchName(oldPurl, newVersion, workspaceName)
200-
: ''
201-
const { owner, repo } = isCi
202-
? getGitHubEnvRepoInfo()
203-
: { owner: '', repo: '' }
204-
const shouldOpenPr = isCi
205-
? // eslint-disable-next-line no-await-in-loop
206-
!(await doesPullRequestExistForBranch(owner, repo, branch))
207-
: false
208-
209198
const revertData = {
210199
...(editablePkgJson.content.dependencies
211200
? { dependencies: editablePkgJson.content.dependencies }
@@ -221,32 +210,47 @@ export async function npmFix(
221210
: undefined)
222211
} as PackageJson
223212

224-
if (!installedSpecs.has(newSpecKey)) {
225-
testedSpecs.add(newSpecKey)
226-
spinner?.info(`Installing ${newSpec}${workspaceDetails}`)
227-
}
213+
const branch = isCi
214+
? getSocketBranchName(oldPurl, newVersion, workspaceName)
215+
: ''
216+
const baseBranch = isCi ? getBaseGitBranch() : ''
217+
const { owner, repo } = isCi
218+
? getGitHubEnvRepoInfo()
219+
: { owner: '', repo: '' }
220+
const shouldOpenPr = isCi
221+
? // eslint-disable-next-line no-await-in-loop
222+
!(await doesPullRequestExistForBranch(owner, repo, branch))
223+
: false
228224

229-
const baseBranch = getBaseGitBranch()
225+
if (isCi) {
226+
// eslint-disable-next-line no-await-in-loop
227+
await gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)
228+
}
230229

231-
// eslint-disable-next-line no-await-in-loop
232-
await gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)
230+
updatePackageJsonFromNode(
231+
editablePkgJson,
232+
arb.idealTree!,
233+
node,
234+
newVersion,
235+
rangeStyle
236+
)
233237

234238
let error: unknown
235239
let errored = false
236240
let installed = false
237241
let saved = false
242+
243+
// eslint-disable-next-line no-await-in-loop
244+
if (await editablePkgJson.save()) {
245+
saved = true
246+
}
247+
248+
if (!installedSpecs.has(newSpecKey)) {
249+
testedSpecs.add(newSpecKey)
250+
spinner?.info(`Installing ${newSpec}${workspaceDetails}`)
251+
}
252+
238253
try {
239-
updatePackageJsonFromNode(
240-
editablePkgJson,
241-
arb.idealTree!,
242-
node,
243-
newVersion,
244-
rangeStyle
245-
)
246-
// eslint-disable-next-line no-await-in-loop
247-
if (await editablePkgJson.save()) {
248-
saved = true
249-
}
250254
// eslint-disable-next-line no-await-in-loop
251255
await install(arb.idealTree!, { cwd })
252256
installed = true

src/commands/fix/pnpm-fix.ts

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

Comments
 (0)