Skip to content

Commit 2313806

Browse files
authored
refactor(devtools): replace semver with verkit (#1027)
1 parent 0c94730 commit 2313806

8 files changed

Lines changed: 47 additions & 24 deletions

File tree

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@playwright/test": "catalog:cli",
3939
"@types/markdown-it": "catalog:types",
4040
"@types/node": "catalog:types",
41-
"@types/semver": "catalog:types",
4241
"@types/which": "catalog:types",
4342
"@types/ws": "catalog:types",
4443
"@unocss/eslint-config": "catalog:buildtools",

‎packages/devtools/client/composables/npm.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NpmCommandOptions } from '../../src/types'
2-
import semver from 'semver'
2+
import { satisfies } from 'verkit'
33
import { computed, ref } from 'vue'
44
import { useNuxtApp } from '#app/nuxt'
55
import { rpc } from './rpc'
@@ -25,7 +25,7 @@ export function satisfyNuxtVersion(range: string) {
2525
return computed(() => {
2626
if (!nuxt?.value?.current)
2727
return false
28-
return semver.satisfies(nuxt.value.current, range)
28+
return satisfies(nuxt.value.current, range)
2929
})
3030
}
3131

‎packages/devtools/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@
6969
"pathe": "catalog:frontend",
7070
"perfect-debounce": "catalog:frontend",
7171
"pkg-types": "catalog:prod",
72-
"semver": "catalog:prod",
7372
"sirv": "catalog:prod",
7473
"structured-clone-es": "catalog:frontend",
7574
"tinyexec": "catalog:prod",
7675
"tinyglobby": "catalog:prod",
7776
"unstorage": "catalog:prod",
77+
"verkit": "catalog:prod",
7878
"vite-plugin-inspect": "catalog:prod",
7979
"vite-plugin-vue-tracer": "catalog:prod",
8080
"which": "catalog:prod",

‎packages/devtools/src/integrations/timeline.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Import } from 'unimport'
22
import type { NuxtDevtoolsServerContext } from '../types'
33
import { resolve } from 'pathe'
4-
import semver from 'semver'
4+
import { isGreaterOrEqual } from 'verkit'
55
import { runtimeDir } from '../dirs'
66

77
const DEFINE_UPPER_RE = /^define[A-Z]/
@@ -37,7 +37,7 @@ export function setup({ nuxt, options }: NuxtDevtoolsServerContext) {
3737
nuxt.hook('imports:context', (unimport) => {
3838
const ctx = unimport.getInternalContext()
3939

40-
if (!ctx.version || !semver.gte(ctx.version, '3.1.0'))
40+
if (!ctx.version || !isGreaterOrEqual(ctx.version, '3.1.0'))
4141
throw new Error(`[Nuxt DevTools] The timeline feature requires \`unimport\` >= v3.1.0, but got \`${ctx.version || '(unknown)'}\`. Please upgrade using \`nuxi upgrade --force\`.`)
4242

4343
ctx.addons.push(

‎packages/devtools/src/npm/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { logger, useNuxt } from '@nuxt/kit'
44
import { getPackageInfo } from 'local-pkg'
55
import { fetch } from 'ofetch'
66
import { readPackageJSON } from 'pkg-types'
7-
import semver from 'semver'
7+
import { isLess } from 'verkit'
88

99
export async function getMainPackageJSON(nuxt = useNuxt()) {
1010
return readPackageJSON(nuxt.options.rootDir)
@@ -32,7 +32,7 @@ export async function checkForUpdateOf(name: string, current?: string, nuxt = us
3232
fetch,
3333
})
3434

35-
const needsUpdate = !!latest && latest !== current && semver.lt(current, latest)
35+
const needsUpdate = !!latest && latest !== current && isLess(current, latest)
3636

3737
return {
3838
name,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { isGreaterOrEqual, isLess, satisfies } from 'verkit'
2+
import { describe, expect, it } from 'vitest'
3+
4+
describe('version comparisons', () => {
5+
it('checks the minimum supported unimport version', () => {
6+
expect(isGreaterOrEqual('3.1.0', '3.1.0')).toBe(true)
7+
expect(isGreaterOrEqual('3.0.9', '3.1.0')).toBe(false)
8+
})
9+
10+
it('detects stable and prerelease package updates', () => {
11+
expect(isLess('4.0.0', '4.0.1')).toBe(true)
12+
expect(isLess('4.0.0-alpha.1', '4.0.0')).toBe(true)
13+
expect(isLess('4.0.1', '4.0.0')).toBe(false)
14+
})
15+
16+
it('preserves default prerelease range behavior', () => {
17+
expect(satisfies('4.0.0-alpha.7', '^4.0.0-alpha.1')).toBe(true)
18+
expect(satisfies('4.0.0-alpha.7', '^4.0.0')).toBe(false)
19+
})
20+
21+
it('rejects invalid comparison inputs', () => {
22+
expect(() => isLess('invalid', '4.0.0')).toThrow(TypeError)
23+
expect(() => isGreaterOrEqual('invalid', '3.1.0')).toThrow(TypeError)
24+
expect(satisfies('invalid', '^4.0.0')).toBe(false)
25+
})
26+
})

‎pnpm-lock.yaml‎

Lines changed: 12 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ minimumReleaseAgeExclude:
88
- vite-plugin-inspect@12.0.2
99
- '@devframes/hub@0.6.1'
1010
- devframe@0.6.1
11+
- verkit@0.1.2
1112
resolutionMode: highest
1213
shamefullyHoist: true
1314
shellEmulator: true
@@ -172,11 +173,11 @@ catalogs:
172173
magicast: ^0.5.3
173174
nostics: ^1.1.4
174175
pkg-types: ^2.3.1
175-
semver: ^7.8.5
176176
sirv: ^3.0.2
177177
tinyexec: ^1.2.4
178178
tinyglobby: ^0.2.17
179179
unstorage: ^1.17.5
180+
verkit: ^0.1.2
180181
vite-plugin-inspect: ^12.0.2
181182
vite-plugin-vue-tracer: ^1.4.0
182183
which: ^7.0.0
@@ -186,7 +187,6 @@ catalogs:
186187
'@types/markdown-it': ^14.1.2
187188
'@types/markdown-it-link-attributes': ^3.0.5
188189
'@types/node': ^26.1.1
189-
'@types/semver': ^7.7.1
190190
'@types/which': ^3.0.4
191191
'@types/ws': ^8.18.1
192192
'@unhead/schema': ^3.1.8

0 commit comments

Comments
 (0)