Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace json-parse-helpfulerror with jsonc-parser #1493

Merged
merged 7 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: revert some changes and remove code duplication
  • Loading branch information
Torathion committed Jan 26, 2025
commit 96914167c52dddd4db7b27b72f5259f07977c42e
23 changes: 11 additions & 12 deletions src/lib/runLocal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs/promises'
import prompts from 'prompts-ncu'
import nodeSemver from 'semver'
import { DependencyGroup } from '../types/DependencyGroup'
import { Index } from '../types/IndexType'
import { Maybe } from '../types/Maybe'
import { Options } from '../types/Options'
Expand Down Expand Up @@ -37,6 +38,12 @@ const INTERACTIVE_HINT = `
a: Toggle all
Enter: Upgrade`

function getOptionsPerPage(groups?: DependencyGroup[]): number {
return process.stdout.rows
? Math.max(3, process.stdout.rows - INTERACTIVE_HINT.split('\n').length - 1 - (groups?.length ?? 0) * 2)
: 50
}

/**
* Return a promise which resolves to object storing package owner changed status for each dependency.
*
Expand Down Expand Up @@ -75,7 +82,7 @@ const chooseUpgrades = async (
from: oldDependencies,
to: newDependencies,
format: options.format,
pkgFile: pkgFile ?? undefined,
pkgFile: pkgFile || undefined,
})

const formattedLines = keyValueBy(table.toString().split('\n'), line => {
Expand Down Expand Up @@ -106,17 +113,13 @@ const chooseUpgrades = async (
]
})

const optionsPerPage = process.stdout.rows
? Math.max(3, process.stdout.rows - INTERACTIVE_HINT.split('\n').length - 1 - groups.length * 2)
: 50

const response = await prompts({
choices: [...choices, { title: ' ', heading: true }],
hint: INTERACTIVE_HINT,
instructions: false,
message: 'Choose which packages to update',
name: 'value',
optionsPerPage,
optionsPerPage: getOptionsPerPage(groups),
type: 'multiselect',
onState: (state: any) => {
if (state.aborted) {
Expand All @@ -135,17 +138,13 @@ const chooseUpgrades = async (
selected: true,
}))

const optionsPerPage = process.stdout.rows
? Math.max(3, process.stdout.rows - INTERACTIVE_HINT.split('\n').length - 1)
: 50

const response = await prompts({
choices: [...choices, { title: ' ', heading: true }],
hint: INTERACTIVE_HINT + '\n',
instructions: false,
message: 'Choose which packages to update',
name: 'value',
optionsPerPage,
optionsPerPage: getOptionsPerPage(),
type: 'multiselect',
onState: (state: any) => {
if (state.aborted) {
Expand Down Expand Up @@ -261,7 +260,7 @@ export default async function runLocal(
total: Object.keys(upgraded).length,
latest: latestResults,
ownersChangedDeps,
pkgFile: pkgFile ?? undefined,
pkgFile: pkgFile || undefined,
errors,
time,
},
Expand Down
3 changes: 2 additions & 1 deletion src/lib/version-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import parseGithubUrl from 'parse-github-url'
import semver from 'semver'
import semverutils, { SemVer, parse, parseRange } from 'semver-utils'
import util from 'util'
import { DependencyGroup } from '../types/DependencyGroup'
import { Index } from '../types/IndexType'
import { Maybe } from '../types/Maybe'
import { Options } from '../types/Options'
Expand Down Expand Up @@ -191,7 +192,7 @@ export function getDependencyGroups(
newDependencies: Index<string>,
oldDependencies: Index<string>,
options: Options,
): { heading: string; groupName: string; packages: Index<string> }[] {
): DependencyGroup[] {
const groups = keyValueBy<string, Index<string>>(newDependencies, (dep, to, accum) => {
const from = oldDependencies[dep]
const defaultGroup = partChanged(from, to)
Expand Down
7 changes: 7 additions & 0 deletions src/types/DependencyGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Index } from './IndexType'

export interface DependencyGroup {
heading: string
groupName: string
packages: Index<string>
}