diff --git a/src/commands/check/interactive.ts b/src/commands/check/interactive.ts index 7eb273a..7b597a8 100644 --- a/src/commands/check/interactive.ts +++ b/src/commands/check/interactive.ts @@ -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) => { @@ -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))) diff --git a/src/commands/check/render.ts b/src/commands/check/render.ts index a262797..649f45c 100644 --- a/src/commands/check/render.ts +++ b/src/commands/check/render.ts @@ -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}`) @@ -85,8 +88,6 @@ export function renderChanges( '', ) - changes = sortDepChanges(changes, sort) - lines.push(...formatTable( changes.map(c => renderChange(c, interactive)), 'LLRRRRRL',