Skip to content

Commit

Permalink
Use semver.minVersion to extract versions from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeTechGuy committed Mar 22, 2024
1 parent 676c57d commit 7f3d2b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/lib/getPeerDependenciesFromRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ProgressBar from 'progress'
import nodeSemver from 'semver'
import { Index } from '../types/IndexType'
import { Options } from '../types/Options'
import { Version } from '../types/Version'
Expand Down Expand Up @@ -62,7 +61,7 @@ async function getPeerDependenciesFromRegistry(packageMap: Index<Version>, optio

const peerDependencies: Index<Index<string>> = Object.entries(packageMap).reduce(
async (accumPromise, [pkg, version]) => {
const dep = await packageManager.getPeerDependencies!(pkg, nodeSemver.coerce(version)?.version ?? version)
const dep = await packageManager.getPeerDependencies!(pkg, version)
if (bar) {
bar.tick()
}
Expand Down
15 changes: 12 additions & 3 deletions src/lib/runLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
import pick from 'lodash/pick'
import prompts from 'prompts-ncu'
import { satisfies } from 'semver'
import nodeSemver from 'semver'
import { Index } from '../types/IndexType'
import { Maybe } from '../types/Maybe'
import { Options } from '../types/Options'
Expand Down Expand Up @@ -183,7 +183,14 @@ async function runLocal(
}

if (options.peer) {
options.peerDependencies = await getPeerDependenciesFromRegistry(current, options)
options.peerDependencies = await getPeerDependenciesFromRegistry(
Object.fromEntries(
Object.entries(current).map(([packageName, versionSpec]) => {
return [packageName, nodeSemver.minVersion(versionSpec)?.version ?? versionSpec]
}),
),
options,
)
}

const [upgraded, latestResults, upgradedPeerDependencies] = await upgradePackageDefinitions(current, options)
Expand All @@ -210,7 +217,9 @@ async function runLocal(

// filter out satisfied deps when using --minimal
const filteredUpgraded = options.minimal
? keyValueBy(upgraded, (dep, version) => (!satisfies(latest[dep], current[dep]) ? { [dep]: version } : null))
? keyValueBy(upgraded, (dep, version) =>
!nodeSemver.satisfies(latest[dep], current[dep]) ? { [dep]: version } : null,
)
: upgraded

const ownersChangedDeps = (options.format || []).includes('ownerChanged')
Expand Down

0 comments on commit 7f3d2b7

Please sign in to comment.