Skip to content

Commit 9cce8e7

Browse files
committed
Try again to get multiple prs
1 parent cbde084 commit 9cce8e7

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/commands/fix/pnpm-fix.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,26 @@ export async function pnpmFix(
136136
pkgEnvDetails.editablePkgJson.filename!
137137
]
138138

139-
let actualTree = await getActualTree(cwd)
140-
141139
for (const { 0: name, 1: infos } of infoByPkg) {
140+
debugLog(`Processing vulnerable package: ${name}`)
142141
if (getManifestData(NPM, name)) {
143142
spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
144143
continue
145144
}
146-
const oldVersions = arrayUnique(
147-
findPackageNodes(actualTree, name)
148-
.map(n => n.target?.version ?? n.version)
149-
.filter(Boolean)
150-
)
151-
const packument =
152-
oldVersions.length && infos.length
153-
? // eslint-disable-next-line no-await-in-loop
154-
await fetchPackagePackument(name)
155-
: null
156-
if (!packument) {
157-
continue
158-
}
159145

160146
const fixedSpecs = new Set<string>()
161147

162148
for (const pkgJsonPath of pkgJsonPaths) {
163-
// Re-read actualTree to avoid lockfile state issues
149+
debugLog(`Checking workspace: ${pkgJsonPath}`)
150+
164151
// eslint-disable-next-line no-await-in-loop
165-
actualTree = await getActualTree(cwd)
152+
let actualTree = await getActualTree(cwd)
166153

167-
const pkgPath = path.dirname(pkgJsonPath)
168154
const isWorkspaceRoot =
169155
pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
170156
const workspaceName = isWorkspaceRoot
171157
? 'root'
172-
: path.relative(rootPath, pkgPath)
158+
: path.relative(rootPath, path.dirname(pkgJsonPath))
173159

174160
const editablePkgJson = isWorkspaceRoot
175161
? pkgEnvDetails.editablePkgJson
@@ -184,6 +170,20 @@ export async function pnpmFix(
184170
| Record<string, string>
185171
| undefined
186172

173+
const oldVersions = arrayUnique(
174+
findPackageNodes(actualTree, name)
175+
.map(n => n.target?.version ?? n.version)
176+
.filter(Boolean)
177+
)
178+
const packument =
179+
oldVersions.length && infos.length
180+
? // eslint-disable-next-line no-await-in-loop
181+
await fetchPackagePackument(name)
182+
: null
183+
if (!packument) {
184+
continue
185+
}
186+
187187
for (const oldVersion of oldVersions) {
188188
const oldSpec = `${name}@${oldVersion}`
189189
const oldPurl = `pkg:npm/${oldSpec}`
@@ -352,10 +352,13 @@ export async function pnpmFix(
352352

353353
if (errored) {
354354
editablePkgJson.update(revertData)
355+
355356
// eslint-disable-next-line no-await-in-loop
356357
await Promise.all([removeNodeModules(cwd), editablePkgJson.save()])
358+
357359
// eslint-disable-next-line no-await-in-loop
358360
actualTree = await install(pkgEnvDetails, { spinner })
361+
359362
spinner?.failAndStop(
360363
`Update failed for ${oldSpec} in ${workspaceName}`,
361364
error
@@ -364,15 +367,16 @@ export async function pnpmFix(
364367
// eslint-disable-next-line no-await-in-loop
365368
await Promise.all([
366369
removeNodeModules(cwd),
367-
// Reset to base branch to isolate next PR
368370
gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)
369371
])
372+
370373
// eslint-disable-next-line no-await-in-loop
371374
actualTree = await install(pkgEnvDetails, { spinner })
372375
}
373376
}
374377
}
375378
}
376379
}
380+
377381
spinner?.stop()
378382
}

0 commit comments

Comments
 (0)