Skip to content

Commit d92b5e7

Browse files
committed
refactor: upgrade vue-devtools
1 parent 7de39be commit d92b5e7

File tree

6 files changed

+195
-103
lines changed

6 files changed

+195
-103
lines changed

packages/pinia/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@vue/test-utils": "^2.4.6"
7474
},
7575
"dependencies": {
76-
"@vue/devtools-api": "^6.6.3"
76+
"@vue/devtools-api": "^7.7.1"
7777
},
7878
"peerDependencies": {
7979
"typescript": ">=4.4.4",

packages/pinia/src/devtools/formatting.ts

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,88 @@
1-
import {
2-
ComponentCustomState,
3-
CustomInspectorNode,
4-
CustomInspectorState,
5-
} from '@vue/devtools-api'
61
import { MutationType, StoreGeneric } from '../types'
72
import { DebuggerEvent } from 'vue'
83
import { Pinia } from '../rootStore'
94
import { isPinia } from './utils'
105

6+
// types from devtools-api
7+
interface StateBase {
8+
key: string
9+
value: any
10+
editable?: boolean
11+
objectType?: 'ref' | 'reactive' | 'computed' | 'other'
12+
raw?: string
13+
}
14+
interface ComponentStateBase extends StateBase {
15+
type: string
16+
}
17+
type ComponentBuiltinCustomStateTypes =
18+
| 'function'
19+
| 'map'
20+
| 'set'
21+
| 'reference'
22+
| 'component'
23+
| 'component-definition'
24+
| 'router'
25+
| 'store'
26+
interface CustomState {
27+
_custom: {
28+
type: ComponentBuiltinCustomStateTypes | string
29+
objectType?: string
30+
display?: string
31+
tooltip?: string
32+
value?: any
33+
abstract?: boolean
34+
file?: string
35+
uid?: number
36+
readOnly?: boolean
37+
/** Configure immediate child fields */
38+
fields?: {
39+
abstract?: boolean
40+
}
41+
id?: any
42+
actions?: {
43+
icon: string
44+
tooltip?: string
45+
action: () => void | Promise<void>
46+
}[]
47+
/** internal */
48+
_reviveId?: number
49+
}
50+
}
51+
interface ComponentPropState extends ComponentStateBase {
52+
meta?: {
53+
type: string
54+
required: boolean
55+
/** Vue 1 only */
56+
mode?: 'default' | 'sync' | 'once'
57+
}
58+
}
59+
type ComponentState =
60+
| ComponentStateBase
61+
| ComponentPropState
62+
| ComponentCustomState
63+
interface ComponentCustomState extends ComponentStateBase {
64+
value: CustomState
65+
}
66+
67+
interface InspectorNodeTag {
68+
label: string
69+
textColor: number
70+
backgroundColor: number
71+
tooltip?: string
72+
}
73+
interface CustomInspectorNode {
74+
id: string
75+
label: string
76+
children?: CustomInspectorNode[]
77+
tags?: InspectorNodeTag[]
78+
name?: string
79+
file?: string
80+
}
81+
82+
interface CustomInspectorState {
83+
[key: string]: (StateBase | Omit<ComponentState, 'type'>)[]
84+
}
85+
1186
export function formatDisplay(display: string) {
1287
return {
1388
_custom: {

packages/pinia/src/devtools/plugin.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
setupDevtoolsPlugin,
3-
TimelineEvent,
4-
App as DevtoolsApp,
5-
} from '@vue/devtools-api'
6-
import { ComponentPublicInstance, markRaw, toRaw, unref, watch } from 'vue'
1+
import { setupDevtoolsPlugin } from '@vue/devtools-api'
2+
import { App, ComponentPublicInstance, markRaw, toRaw, unref, watch } from 'vue'
73
import { Pinia, PiniaPluginContext } from '../rootStore'
84
import {
95
_GettersTree,
@@ -37,6 +33,17 @@ const MUTATIONS_LAYER_ID = 'pinia:mutations'
3733
const INSPECTOR_ID = 'pinia'
3834
const { assign } = Object
3935

36+
// copied from devtools
37+
interface TimelineEvent<TData = any, TMeta = any> {
38+
time: number
39+
data: TData
40+
logType?: 'default' | 'warning' | 'error'
41+
meta?: TMeta
42+
groupId?: number | string
43+
title?: string
44+
subtitle?: string
45+
}
46+
4047
/**
4148
* Gets the displayed name of a store in devtools
4249
*
@@ -52,7 +59,7 @@ const getStoreType = (id: string) => '🍍 ' + id
5259
* @param app - Vue application
5360
* @param pinia - pinia instance
5461
*/
55-
export function registerPiniaDevtools(app: DevtoolsApp, pinia: Pinia) {
62+
export function registerPiniaDevtools(app: App, pinia: Pinia) {
5663
setupDevtoolsPlugin(
5764
{
5865
id: 'dev.esm.pinia',
@@ -140,7 +147,7 @@ export function registerPiniaDevtools(app: DevtoolsApp, pinia: Pinia) {
140147
],
141148
})
142149

143-
api.on.inspectComponent((payload, ctx) => {
150+
api.on.inspectComponent((payload) => {
144151
const proxy = (payload.componentInstance &&
145152
payload.componentInstance.proxy) as
146153
| ComponentPublicInstance
@@ -241,7 +248,7 @@ export function registerPiniaDevtools(app: DevtoolsApp, pinia: Pinia) {
241248
}
242249
})
243250

244-
api.on.editInspectorState((payload, ctx) => {
251+
api.on.editInspectorState((payload) => {
245252
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
246253
const inspectedStore =
247254
payload.nodeId === PINIA_ROOT_ID
@@ -301,7 +308,7 @@ export function registerPiniaDevtools(app: DevtoolsApp, pinia: Pinia) {
301308
)
302309
}
303310

304-
function addStoreToDevtools(app: DevtoolsApp, store: StoreGeneric) {
311+
function addStoreToDevtools(app: App, store: StoreGeneric) {
305312
if (!componentStateTypes.includes(getStoreType(store.$id))) {
306313
componentStateTypes.push(getStoreType(store.$id))
307314
}

packages/playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"devDependencies": {
1111
"@vitejs/plugin-vue": "^5.2.1",
12-
"vite": "^6.0.11"
12+
"vite": "^6.0.11",
13+
"vite-plugin-vue-devtools": "^7.7.1"
1314
},
1415
"dependencies": {
1516
"@vueuse/core": "^12.5.0",

packages/playground/vite.config.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { defineConfig, Plugin } from 'vite'
22
import Vue from '@vitejs/plugin-vue'
3-
import { promises as fs } from 'fs'
4-
import path from 'path'
3+
import fs from 'node:fs/promises'
4+
import { fileURLToPath, URL } from 'node:url'
5+
import VueDevtools from 'vite-plugin-vue-devtools'
56

67
// https://vitejs.dev/config/
78
export default defineConfig({
8-
plugins: [Vue(), copyPiniaPlugin()],
9+
plugins: [Vue(), copyPiniaPlugin(), VueDevtools()],
910
define: {
1011
__DEV__: 'true',
1112
// __BROWSER__: 'true',
@@ -14,8 +15,7 @@ export default defineConfig({
1415
resolve: {
1516
dedupe: ['vue', 'pinia'],
1617
alias: {
17-
// FIXME: use fileToUrl
18-
pinia: path.resolve(__dirname, '../pinia/src/index.ts'),
18+
pinia: fileURLToPath(new URL('../pinia/src/index.ts', import.meta.url)),
1919
},
2020
},
2121
optimizeDeps: {
@@ -27,7 +27,9 @@ function copyPiniaPlugin(): Plugin {
2727
return {
2828
name: 'copy-pinia',
2929
async generateBundle() {
30-
const filePath = path.resolve(__dirname, '../pinia/dist/pinia.mjs')
30+
const filePath = fileURLToPath(
31+
new URL('../pinia/dist/pinia.mjs', import.meta.url)
32+
)
3133

3234
// throws if file doesn't exist
3335
await fs.access(filePath)

0 commit comments

Comments
 (0)