Skip to content

Commit

Permalink
Fix peer dependencies for versions with range operators (#1378).
Browse files Browse the repository at this point in the history
getPeerDependencies and getPeerDependenciesFromRegistry expect exact versions, not version ranges.
  • Loading branch information
raineorshine committed Mar 15, 2024
1 parent 3e2f432 commit 84ce6ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/lib/upgradePackageDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export async function upgradePackageDefinitions(
return !options.jsonUpgraded || !options.minimal || !satisfies(latestVersions[dep], currentDependencies[dep])
})

const filteredLatestDependencies = pickBy(latestVersions, (spec, dep) => filteredUpgradedDependencies[dep])

if (options.peer && !isEmpty(filteredUpgradedDependencies)) {
const upgradedPeerDependencies = await getPeerDependenciesFromRegistry(filteredUpgradedDependencies, options)
const upgradedPeerDependencies = await getPeerDependenciesFromRegistry(filteredLatestDependencies, options)
const peerDependencies = { ...options.peerDependencies, ...upgradedPeerDependencies }
if (!isEqual(options.peerDependencies, peerDependencies)) {
const [newUpgradedDependencies, newLatestVersions, newPeerDependencies] = await upgradePackageDefinitions(
Expand Down
6 changes: 1 addition & 5 deletions src/package-managers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,7 @@ export const greatest: GetVersion = async (
* @returns Promised {packageName: version} collection
*/
export const getPeerDependencies = async (packageName: string, version: Version): Promise<Index<Version>> => {
// if version number uses >, omit the version and find latest
// otherwise, it will error out in the shell
// https://github.com/raineorshine/npm-check-updates/issues/1181
const atVersion = !version.startsWith('>') ? `@${version}` : ''
const args = ['view', `${packageName}${atVersion}`, 'peerDependencies']
const args = ['view', `${packageName}@${version}`, 'peerDependencies']
const result = await spawnNpm(args, {}, { rejectOnError: false })
return result ? parseJson(result, { command: [...args, '--json'].join(' ') }) : {}
}
Expand Down

0 comments on commit 84ce6ea

Please sign in to comment.