Skip to content

Commit

Permalink
feat: add timediff option (#149)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
THernandez03 and antfu authored Jan 15, 2025
1 parent 13dcf44 commit 9ba69c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ yargs(hideBin(process.argv))
type: 'boolean',
describe: 'include locked dependencies & devDependencies',
})
.option('timediff', {
type: 'boolean',
describe: 'show time difference between the current and the updated version',
})
.help()
},
async (args) => {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/check/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function promptInteractive(pkgs: PackageMeta[], options: CheckOptio
const {
sort = 'diff-asc',
group = true,
timediff = true,
} = options

const checked = new Set<object>()
Expand Down Expand Up @@ -170,11 +171,11 @@ export async function promptInteractive(pkgs: PackageMeta[], options: CheckOptio
formatTable(versions.map((v, idx) => {
return [
(index === idx ? FIG_POINTER : FIG_NO_POINTER) + (index === idx ? v.name : c.gray(v.name)),
timeDifference(dep.currentVersionTime),
timediff ? timeDifference(dep.currentVersionTime) : '',
c.gray(dep.currentVersion),
c.dim(c.gray('→')),
colorizeVersionDiff(dep.currentVersion, v.targetVersion),
timeDifference(v.time),
timediff ? timeDifference(v.time) : '',
]
}), 'LLLL').join('\n'),
)
Expand Down
7 changes: 4 additions & 3 deletions src/commands/check/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function renderChange(
change: ResolvedDepChange,
interactive?: InteractiveContext,
grouped = false,
timediff = true,
) {
const update = change.update && (!interactive || interactive.isChecked(change))
const pre = interactive
Expand All @@ -34,13 +35,13 @@ export function renderChange(
return [
`${pre} ${update ? name : c.gray(name)}`,
grouped ? '' : c.gray(DependenciesTypeShortMap[change.source]),
timeDifference(change.currentVersionTime),
timediff ? timeDifference(change.currentVersionTime) : '',
c.gray(change.currentVersion),
update ? c.dim(c.gray('→')) : '',
update
? colorizeVersionDiff(change.currentVersion, change.targetVersion)
: c.gray(c.strikethrough(change.targetVersion)),
update
update && timediff
? timeDifference(change.targetVersionTime)
: '',
(change.latestVersionAvailable && semver.minVersion(change.targetVersion)!.toString() !== change.latestVersionAvailable)
Expand Down Expand Up @@ -99,7 +100,7 @@ export function renderChanges(
)

const table = formatTable(
changes.map(c => renderChange(c, interactive, group)),
changes.map(c => renderChange(c, interactive, group, options.timediff ?? true)),
'LLRRRRRL',
)

Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ export interface CheckOptions extends CommonOptions {
* @description exclude the locked deps/devDeps by default
*/
includeLocked?: boolean
/**
* Show time difference between the current and the updated version
*
* @default true
* @description hide the time difference
*/
timediff?: boolean
}

export interface PackageMeta {
Expand Down

0 comments on commit 9ba69c2

Please sign in to comment.