Skip to content

Commit 8357506

Browse files
committed
chore: replace regex with semver.valid
1 parent f7734e7 commit 8357506

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

app/composables/npm/useResolvedVersion.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PackageVersionsInfo, ResolvedPackageVersion } from 'fast-npm-meta'
2+
import semver from 'semver'
23

34
export function useResolvedVersion(
45
packageName: MaybeRefOrGetter<string>,
@@ -18,7 +19,7 @@ export function useResolvedVersion(
1819
// error (no publishedAt, no validation). When publishedAt is missing for
1920
// an exact version request, cross-check the versions list to confirm the
2021
// version actually exists in the registry.
21-
if (version && /^\d/.test(version) && !data.publishedAt) {
22+
if (version && semver.valid(version) && !data.publishedAt) {
2223
const versionsData = await $fetch<PackageVersionsInfo>(
2324
`https://npm.antfu.dev/versions/${name}`,
2425
)

test/nuxt/composables/use-resolved-version.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('useResolvedVersion', () => {
118118
})
119119

120120
it('does not cross-check dist-tags against the versions list', async () => {
121-
// Dist-tags start with a letter — the /^\d/ guard short-circuits the check
121+
// Dist-tags start with a letter
122122
fetchSpy.mockResolvedValue(
123123
makeResolvedVersion({
124124
name: 'pkg-dist-tag-next',

0 commit comments

Comments
 (0)