Skip to content

Commit 5980323

Browse files
committed
separate event client
1 parent 830bb72 commit 5980323

File tree

15 files changed

+170
-27
lines changed

15 files changed

+170
-27
lines changed

examples/react/basic/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"test:types": "tsc"
1010
},
1111
"dependencies": {
12+
"@tanstack/devtools-client": "0.0.1",
1213
"@tanstack/devtools-event-client": "0.3.2",
1314
"@tanstack/react-devtools": "^0.7.4",
1415
"@tanstack/react-query": "^5.90.1",
@@ -41,4 +42,4 @@
4142
"last 1 safari version"
4243
]
4344
}
44-
}
45+
}

examples/react/basic/src/package-json-panel.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { devtoolsEventClient } from '@tanstack/devtools-vite/client'
1+
import { devtoolsEventClient } from '@tanstack/devtools-client'
22
import { useEffect, useState } from 'react'
33
import type { CSSProperties } from 'react'
44

@@ -22,12 +22,10 @@ export const PackageJsonPanel = () => {
2222
setPackageJson(event.payload.packageJson)
2323
setOutdatedDeps(event.payload.outdatedDeps || {})
2424
})
25-
return () => {
26-
off?.()
27-
}
25+
return off
2826
}, [])
2927

30-
const hasOutdated = Object.keys(outdatedDeps || {}).length > 0
28+
const hasOutdated = Object.keys(outdatedDeps).length > 0
3129

3230
// Helpers
3331
const stripRange = (v?: string) => (v ?? '').replace(/^[~^><=v\s]*/, '')
@@ -120,7 +118,12 @@ export const PackageJsonPanel = () => {
120118
dep: string
121119
specified: string
122120
}) => {
123-
const info = outdatedDeps[dep]
121+
const info = outdatedDeps[dep] as {
122+
current: string
123+
wanted: string
124+
latest: string
125+
type?: 'dependencies' | 'devDependencies'
126+
} | undefined
124127
const current = info?.current ?? specified
125128
const latest = info?.latest
126129
const dt = info ? diffType(current, latest) : null
@@ -140,7 +143,12 @@ export const PackageJsonPanel = () => {
140143
}
141144

142145
const UpgradeRowActions = ({ name }: { name: string }) => {
143-
const info = outdatedDeps[name]
146+
const info = outdatedDeps[name] as {
147+
current: string
148+
wanted: string
149+
latest: string
150+
type?: 'dependencies' | 'devDependencies'
151+
} | undefined
144152
if (!info) return null
145153
return (
146154
<div style={{ display: 'flex', gap: 6 }}>
@@ -163,7 +171,7 @@ export const PackageJsonPanel = () => {
163171
)
164172
}
165173

166-
const makeLists = (names?: string[]) => {
174+
const makeLists = (names?: Array<string>) => {
167175
const entries = Object.entries(outdatedDeps).filter(
168176
([n]) => !names || names.includes(n),
169177
)
@@ -178,7 +186,7 @@ export const PackageJsonPanel = () => {
178186
return { wantedList, latestList }
179187
}
180188

181-
const BulkActions = ({ names }: { names?: string[] }) => {
189+
const BulkActions = ({ names }: { names?: Array<string> }) => {
182190
const { wantedList, latestList } = makeLists(names)
183191
if (wantedList.length === 0 && latestList.length === 0) return null
184192
return (
@@ -202,6 +210,7 @@ export const PackageJsonPanel = () => {
202210

203211
const renderDeps = (title: string, deps?: Record<string, string>) => {
204212
const names = Object.keys(deps || {})
213+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
205214
const someOutdatedInSection = names.some((n) => !!outdatedDeps[n])
206215
return (
207216
<div style={sectionStyle}>
@@ -227,13 +236,18 @@ export const PackageJsonPanel = () => {
227236
</thead>
228237
<tbody>
229238
{Object.entries(deps || {}).map(([dep, version]) => {
230-
const info = outdatedDeps[dep]
239+
const info = outdatedDeps[dep] as {
240+
current: string
241+
wanted: string
242+
latest: string
243+
type?: 'dependencies' | 'devDependencies'
244+
} | undefined
231245
const isOutdated = !!info && info.current !== info.latest
232246
return (
233247
<tr key={dep}>
234248
<td style={thtd}>{dep}</td>
235249
<td style={thtd}>
236-
<VersionCell dep={dep} specified={version as string} />
250+
<VersionCell dep={dep} specified={version} />
237251
</td>
238252
<td style={thtd}>
239253
{isOutdated

packages/devtools-client/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @tanstack/devtools-utils
2+
3+
This package is still under active development and might have breaking changes in the future. Please use it with caution.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
3+
import rootConfig from '../../eslint.config.js'
4+
5+
export default [
6+
...rootConfig,
7+
{
8+
rules: {},
9+
},
10+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@tanstack/devtools-client",
3+
"version": "0.0.1",
4+
"description": "TanStack Devtools client that is used to interact with the event system produced by the Devtools.",
5+
"author": "Tanner Linsley",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/TanStack/devtools.git",
10+
"directory": "packages/devtools"
11+
},
12+
"homepage": "https://tanstack.com/devtools",
13+
"funding": {
14+
"type": "github",
15+
"url": "https://github.com/sponsors/tannerlinsley"
16+
},
17+
"keywords": [
18+
"devtools"
19+
],
20+
"type": "module",
21+
"exports": {
22+
".": {
23+
"import": {
24+
"types": "./dist/esm/index.d.ts",
25+
"default": "./dist/esm/index.js"
26+
}
27+
},
28+
"./package.json": "./package.json"
29+
},
30+
"sideEffects": false,
31+
"engines": {
32+
"node": ">=18"
33+
},
34+
"dependencies": {
35+
"@tanstack/devtools-event-client": "workspace:^"
36+
},
37+
"files": [
38+
"dist/",
39+
"src"
40+
],
41+
"scripts": {
42+
"clean": "premove ./build ./dist",
43+
"lint:fix": "eslint ./src --fix",
44+
"test:eslint": "eslint ./src",
45+
"test:lib": "vitest",
46+
"test:lib:dev": "pnpm test:lib --watch",
47+
"test:types": "tsc",
48+
"test:build": "publint --strict",
49+
"build": "vite build"
50+
},
51+
"devDependencies": {
52+
"tsup": "^8.5.0",
53+
"tsup-preset-solid": "^2.2.0",
54+
"vite-plugin-solid": "^2.11.8"
55+
}
56+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventClient } from '@tanstack/devtools-event-client'
22

33
interface EventMap {
4-
'tanstack-devtools-vite:ready': {
4+
'tanstack-devtools-core:ready': {
55
packageJson: {
66
name?: string
77
version?: string
@@ -21,13 +21,13 @@ interface EventMap {
2121
}
2222
> | null
2323
}
24-
'tanstack-devtools-vite:mounted': void
24+
'tanstack-devtools-core:mounted': void
2525
}
2626

2727
export class DevtoolsEventClient extends EventClient<EventMap> {
2828
constructor() {
2929
super({
30-
pluginId: 'tanstack-devtools-vite',
30+
pluginId: 'tanstack-devtools-core',
3131
})
3232
}
3333
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/vitest'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["tests", "src"]
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react-jsx",
4+
"jsxImportSource": "react"
5+
},
6+
"extends": "../../tsconfig.json",
7+
"include": [
8+
"src",
9+
"tsup.config.ts",
10+
"eslint.config.js",
11+
"vite.config.ts",
12+
"tests",
13+
"vite.config.solid.ts"
14+
]
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig, mergeConfig } from 'vitest/config'
2+
import { tanstackViteConfig } from '@tanstack/config/vite'
3+
import packageJson from './package.json'
4+
5+
const config = defineConfig({
6+
plugins: [],
7+
test: {
8+
name: packageJson.name,
9+
dir: './',
10+
watch: false,
11+
environment: 'jsdom',
12+
setupFiles: ['./tests/test-setup.ts'],
13+
globals: true,
14+
},
15+
})
16+
17+
export default mergeConfig(
18+
config,
19+
tanstackViteConfig({
20+
entry: ['./src/index.ts'],
21+
srcDir: './src',
22+
cjs: false,
23+
}),
24+
)

0 commit comments

Comments
 (0)