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

Function PackageJsonPanel

examples/react/basic/src/package-json-panel.tsx:5–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

renderDepsFunction · 0.70
emitMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected