Skip to content

Commit

Permalink
fix: correct sort order on interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 29, 2023
1 parent 97b2a4a commit cd1c10c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/commands/check/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import readline from 'node:readline'
import process from 'node:process'
import c from 'picocolors'
import { createControlledPromise, notNullish } from '@antfu/utils'
import { sort } from 'semver'
import type { CheckOptions, InteractiveContext, PackageMeta, ResolvedDepChange } from '../../types'
import { getVersionOfRange, updateTargetVersion } from '../../io/resolves'
import { getPrefixedVersion } from '../../utils/versions'
import { FIG_BLOCK, FIG_NO_POINTER, FIG_POINTER, colorizeVersionDiff, createSliceRender, formatTable } from '../../render'
import { timeDifference } from '../../utils/time'
import { sortDepChanges } from '../../utils/sort'
import { renderChanges } from './render'

export async function promptInteractive(pkgs: PackageMeta[], options: CheckOptions) {
const {
sort = 'diff-asc',
} = options

pkgs.forEach((i) => {
i.interactiveChecked = true
i.resolved.forEach((i) => {
Expand All @@ -22,6 +28,7 @@ export async function promptInteractive(pkgs: PackageMeta[], options: CheckOptio
updateTargetVersion(i, i.latestVersionAvailable, undefined, options.includeLocked)
}
})
i.resolved = sortDepChanges(i.resolved, sort)
})

if (!pkgs.some(i => i.resolved.some(i => i.update)))
Expand Down
5 changes: 3 additions & 2 deletions src/commands/check/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export function renderChanges(
diffCounts[diff] = 0
diffCounts[diff] += 1
})

changes = sortDepChanges(changes, sort)

const diffEntries = Object.keys(diffCounts).length
? Object.entries(diffCounts)
.map(([key, value]) => `${c[DiffColorMap[key as DiffType || 'patch']](value)} ${key}`)
Expand All @@ -85,8 +88,6 @@ export function renderChanges(
'',
)

changes = sortDepChanges(changes, sort)

lines.push(...formatTable(
changes.map(c => renderChange(c, interactive)),
'LLRRRRRL',
Expand Down

0 comments on commit cd1c10c

Please sign in to comment.