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 0126a8f commit 80e3d05
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 @@ -653,11 +653,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 80e3d05

Please sign in to comment.