MCPcopy Create free account
hub / github.com/TanStack/devtools / PackageJsonPanel

Function PackageJsonPanel

examples/preact/basic/src/package-json-panel.tsx:4–340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { useEffect, useState } from 'preact/hooks'
3
4export const PackageJsonPanel = () => {
5 const [packageJson, setPackageJson] = useState<any>(null)
6 const [outdatedDeps, setOutdatedDeps] = useState<
7 Record<
8 string,
9 {
10 current: string
11 wanted: string
12 latest: string
13 type?: 'dependencies' | 'devDependencies'
14 }
15 >
16 >({})
17
18 useEffect(() => {
19 devtoolsEventClient.emit('mounted', undefined as any)
20 const cleanupOutdated = devtoolsEventClient.on(
21 'outdated-deps-read',
22 (event) => {
23 setOutdatedDeps(event.payload.outdatedDeps || {})
24 },
25 )
26 const cleanupPackageJson = devtoolsEventClient.on(
27 'package-json-read',
28 (event) => {
29 console.log('package-json-read', event)
30 setPackageJson(event.payload.packageJson)
31 },
32 )
33 return () => {
34 cleanupOutdated()
35 cleanupPackageJson()
36 }
37 }, [])
38
39 const hasOutdated = Object.keys(outdatedDeps).length > 0
40
41 // Helpers
42 const stripRange = (v?: string) => (v ?? '').replace(/^[~^><=v\s]*/, '')
43 const parseSemver = (v?: string) => {
44 const s = stripRange(v)
45 const m = s.match(/^(\d+)\.(\d+)\.(\d+)/)
46 if (!m) return null
47 return { major: +m[1], minor: +m[2], patch: +m[3] }
48 }
49 const diffType = (
50 current?: string,
51 latest?: string,
52 ): 'major' | 'minor' | 'patch' | null => {
53 const c = parseSemver(current)
54 const l = parseSemver(latest)
55 if (!c || !l) return null
56 if (l.major > c.major) return 'major'
57 if (l.major === c.major && l.minor > c.minor) return 'minor'
58 if (l.major === c.major && l.minor === c.minor && l.patch > c.patch)
59 return 'patch'
60 return null
61 }

Callers

nothing calls this directly

Calls 3

renderDepsFunction · 0.70
emitMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected