Skip to content

Commit

Permalink
runLocal: Validate minVersion to avoid crashing --peer on git urls (#…
Browse files Browse the repository at this point in the history
…1437).

Regression: c9fe908
  • Loading branch information
raineorshine committed Aug 3, 2024
1 parent d1f62b5 commit 5765fce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/runLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ async function runLocal(
options.peerDependencies = await getPeerDependenciesFromRegistry(
Object.fromEntries(
Object.entries(current).map(([packageName, versionSpec]) => {
return [packageName, nodeSemver.minVersion(versionSpec)?.version ?? versionSpec]
return [
packageName,
// git urls and other non-semver versions are ignored.
// Make sure versionSpec is a valid semver range, otherwise minVersion will throw.
nodeSemver.validRange(versionSpec)
? (nodeSemver.minVersion(versionSpec)?.version ?? versionSpec)
: versionSpec,
]
}),
),
options,
Expand Down
13 changes: 13 additions & 0 deletions test/peer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,17 @@ describe('peer dependencies', function () {
const upgrades = await ncu({ cwd, peer: true })
upgrades!.should.contain.keys('@vitest/ui', 'vitest')
})

// https://github.com/raineorshine/npm-check-updates/issues/1437
it('git urls are ignored', async () => {
const upgrades = await ncu({
peer: true,
packageData: {
dependencies: {
'@libraries/project-4-utils': 'git+gitlab.com/projects/libraries/project-4-utils.git',
},
},
})
upgrades!.should.deep.equal({})
})
})

0 comments on commit 5765fce

Please sign in to comment.