Skip to content

Commit

Permalink
fix: Is there a way to not upgrade a package if it's peer depndencies…
Browse files Browse the repository at this point in the history
… are not currently met raineorshine#1418
  • Loading branch information
rbnayax committed Aug 7, 2024
1 parent 19bb36d commit 4153fee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/package-managers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ export const greatest: GetVersion = async (
export const getPeerDependencies = async (packageName: string, version: Version): Promise<Index<Version>> => {
const args = ['view', `${packageName}@${version}`, 'peerDependencies']
const result = await spawnNpm(args, {}, { rejectOnError: false })
return result ? parseJson(result, { command: [...args, '--json'].join(' ') }) : {}
const parsed = result ? parseJson(result, { command: [...args, '--json'].join(' ') }) : {}
return Array.isArray(parsed) ? parsed.at(-1) : parsed
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/getIgnoredUpgradesDueToPeerDeps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('getIgnoredUpgradesDueToPeerDeps', function () {
'eslint-plugin-unused-imports': {
from: '^3',
reason: {
'eslint-plugin-unused-imports': 'eslint 9',
'eslint-plugin-unused-imports': 'eslint ^9.0.0',
},
to: '^4',
},
Expand Down
11 changes: 11 additions & 0 deletions test/getPeerDependenciesFromRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ describe('getPeerDependenciesFromRegistry', function () {
})
})

it('single package with range', async () => {
await chalkInit()
const data = await getPeerDependenciesFromRegistry({ 'eslint-plugin-unused-imports': '^4' }, {})
data.should.deep.equal({
'eslint-plugin-unused-imports': {
'@typescript-eslint/eslint-plugin': '^8.0.0-0',
eslint: '^9.0.0',
},
})
})

it('single package empty', async () => {
await chalkInit()
const data = await getPeerDependenciesFromRegistry({ 'ncu-test-return-version': '1.0' }, {})
Expand Down

0 comments on commit 4153fee

Please sign in to comment.