Skip to content

Commit 5514dce

Browse files
authored
Add back some install passes and fix isTopLevel (#559)
1 parent 216fc73 commit 5514dce

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/commands/fix/npm-fix.mts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ async function install(
7070
} as InstallOptions
7171
const newArb = new Arborist({ path: cwd })
7272
newArb.idealTree = await arb.buildIdealTree()
73-
return await newArb.reify()
73+
const actualTree = await newArb.reify()
74+
arb.actualTree = actualTree
75+
return actualTree
7476
}
7577

7678
export async function npmFix(
@@ -253,6 +255,8 @@ export async function npmFix(
253255
if (isCi) {
254256
// eslint-disable-next-line no-await-in-loop
255257
await gitResetAndClean(baseBranch, cwd)
258+
// eslint-disable-next-line no-await-in-loop
259+
actualTree = await install(arb, { cwd })
256260
}
257261
continue
258262
}
@@ -361,6 +365,8 @@ export async function npmFix(
361365
if (isCi) {
362366
// eslint-disable-next-line no-await-in-loop
363367
await gitResetAndClean(baseBranch, cwd)
368+
// eslint-disable-next-line no-await-in-loop
369+
actualTree = await install(arb, { cwd })
364370
}
365371
if (errored) {
366372
if (!isCi) {
@@ -370,6 +376,8 @@ export async function npmFix(
370376
removeNodeModules(cwd),
371377
editablePkgJson.save({ ignoreWhitespace: true })
372378
])
379+
// eslint-disable-next-line no-await-in-loop
380+
actualTree = await install(arb, { cwd })
373381
}
374382
spinner?.failAndStop(
375383
`Update failed for ${oldId} in ${workspaceName}`,

src/commands/fix/pnpm-fix.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export async function pnpmFix(
163163
logger.error('Required pnpm-lock.yaml not found.')
164164
return
165165
}
166+
166167
const alertsMap = purls.length
167168
? await getAlertsMapFromPurls(purls, getAlertMapOptions({ limit }))
168169
: await getAlertsMapFromPnpmLockfile(
@@ -353,6 +354,8 @@ export async function pnpmFix(
353354
if (isCi) {
354355
// eslint-disable-next-line no-await-in-loop
355356
await gitResetAndClean(baseBranch, cwd)
357+
// eslint-disable-next-line no-await-in-loop
358+
actualTree = await install(pkgEnvDetails, { cwd, spinner })
356359
}
357360
continue
358361
}
@@ -461,6 +464,8 @@ export async function pnpmFix(
461464
if (isCi) {
462465
// eslint-disable-next-line no-await-in-loop
463466
await gitResetAndClean(baseBranch, cwd)
467+
// eslint-disable-next-line no-await-in-loop
468+
actualTree = await install(pkgEnvDetails, { cwd, spinner })
464469
}
465470
if (errored) {
466471
if (!isCi) {
@@ -470,6 +475,8 @@ export async function pnpmFix(
470475
removeNodeModules(cwd),
471476
editablePkgJson.save({ ignoreWhitespace: true })
472477
])
478+
// eslint-disable-next-line no-await-in-loop
479+
actualTree = await install(pkgEnvDetails, { cwd, spinner })
473480
}
474481
spinner?.failAndStop(
475482
`Update failed for ${oldId} in ${workspaceName}`,

src/shadow/npm/arborist-helpers.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function findPackageNode(
7777
let sentinel = 0
7878
while (queue.length) {
7979
if (sentinel++ === LOOP_SENTINEL) {
80-
throw new Error('Detected infinite loop in findPackageNodes')
80+
throw new Error('Detected infinite loop in findPackageNode')
8181
}
8282
const nodeOrLink = queue.pop()!
8383
const node = nodeOrLink.isLink ? nodeOrLink.target : nodeOrLink
@@ -300,7 +300,11 @@ export function getDetailsFromDiff(
300300
}
301301

302302
export function isTopLevel(tree: SafeNode, node: SafeNode): boolean {
303-
return tree.children.get(node.name) === node
303+
const childNodeOrLink = tree.children.get(node.name)
304+
const childNode = childNodeOrLink?.isLink
305+
? childNodeOrLink.target
306+
: childNodeOrLink
307+
return childNode === node
304308
}
305309

306310
export type Packument = Exclude<

0 commit comments

Comments
 (0)