Skip to content

Commit 8e98730

Browse files
committed
feat(kit)!: remove deprecated APIs for v0.2.0
Removes the deprecated `DevToolsNodeContext` alias, the `DevToolsLog*` type aliases, the `DockClientScriptContext.logs` property, and the `WhenContext`/`WhenExpression` re-export from the kit's main types barrel. The `utils/*` subpath exports remain as canonical re-exports of `devframe/utils/*` with their `@deprecated` markers dropped. Adds `MIGRATION.md` with the 0.1 → 0.2 mapping table.
1 parent d1bc706 commit 8e98730

30 files changed

Lines changed: 103 additions & 97 deletions

File tree

MIGRATION.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Migration Guide
2+
3+
## 0.1 → 0.2
4+
5+
### `@vitejs/devtools-kit`
6+
7+
The deprecated aliases introduced in 0.1 have been removed. Update imports and references as follows.
8+
9+
#### Message types
10+
11+
The `DevToolsLog*` types were renamed to `DevToolsMessage*` in 0.1. The old names are now gone.
12+
13+
| Removed | Replacement |
14+
| --- | --- |
15+
| `DevToolsLogLevel` | `DevToolsMessageLevel` |
16+
| `DevToolsLogEntryFrom` | `DevToolsMessageEntryFrom` |
17+
| `DevToolsLogElementPosition` | `DevToolsMessageElementPosition` |
18+
| `DevToolsLogFilePosition` | `DevToolsMessageFilePosition` |
19+
| `DevToolsLogEntry` | `DevToolsMessageEntry` |
20+
| `DevToolsLogEntryInput` | `DevToolsMessageEntryInput` |
21+
| `DevToolsLogHandle` | `DevToolsMessageHandle` |
22+
| `DevToolsLogsClient` | `DevToolsMessagesClient` |
23+
| `DevToolsLogsHost` | `DevToolsMessagesHost` |
24+
25+
#### Node context type
26+
27+
```diff
28+
- import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
29+
+ import type { ViteDevToolsNodeContext } from '@vitejs/devtools-kit'
30+
```
31+
32+
The framework-neutral `DevToolsNodeContext` still lives upstream at `devframe/types` and is unchanged.
33+
34+
#### Dock client script context
35+
36+
```diff
37+
defineDockClientScript((ctx) => {
38+
- ctx.logs.add({ ... })
39+
+ ctx.messages.add({ ... })
40+
})
41+
```
42+
43+
#### `WhenContext` / `WhenExpression`
44+
45+
These types are no longer re-exported from `@vitejs/devtools-kit`. Import them from devframe:
46+
47+
```diff
48+
- import type { WhenContext, WhenExpression } from '@vitejs/devtools-kit'
49+
+ import type { WhenContext, WhenExpression } from 'devframe/utils/when'
50+
```
51+
52+
The `@vitejs/devtools-kit/utils/when` subpath remains and re-exports these types alongside `evaluateWhen` and `resolveContextValue`.

docs/errors/DTK0014.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ outline: deep
1010
1111
## Cause
1212

13-
This error is thrown by `createDevToolsContext()` when a Vite plugin's `devtools.setup()` hook throws during initialization. The DevTools context iterates over all Vite plugins that define a `devtools` property and calls their `setup()` hook with the `DevToolsNodeContext`. If the hook throws, the error is caught, wrapped with this diagnostic (preserving the original error as `cause`), and re-thrown -- halting DevTools initialization.
13+
This error is thrown by `createDevToolsContext()` when a Vite plugin's `devtools.setup()` hook throws during initialization. The DevTools context iterates over all Vite plugins that define a `devtools` property and calls their `setup()` hook with the `ViteDevToolsNodeContext`. If the hook throws, the error is caught, wrapped with this diagnostic (preserving the original error as `cause`), and re-thrown -- halting DevTools initialization.
1414

1515
Plugins may be skipped entirely if their `devtools.capabilities` configuration indicates they do not support the current mode (dev or build).
1616

docs/kit/devtools-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default function myPlugin(): Plugin {
6868

6969
## DevTools context
7070

71-
The `setup` function receives a `DevToolsNodeContext` providing access to every DevTools API:
71+
The `setup` function receives a `ViteDevToolsNodeContext` providing access to every DevTools API:
7272

7373
```ts
7474
const plugin: Plugin = {

docs/kit/rpc.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const getModule = defineRpcFunction({
7878

7979
### Context in setup
8080

81-
The `setup` function receives the full `DevToolsNodeContext`:
81+
The `setup` function receives the full `ViteDevToolsNodeContext`:
8282

8383
```ts
8484
setup: (ctx) => {
@@ -255,15 +255,15 @@ Use a shared context helper (for example `WeakMap`-backed `set/get`) to provide
255255

256256
```ts
257257
// src/node/rpc/context.ts
258-
import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
258+
import type { ViteDevToolsNodeContext } from '@vitejs/devtools-kit'
259259

260-
const rpcContext = new WeakMap<DevToolsNodeContext, { targetDir: string }>()
260+
const rpcContext = new WeakMap<ViteDevToolsNodeContext, { targetDir: string }>()
261261

262-
export function setRpcContext(context: DevToolsNodeContext, options: { targetDir: string }) {
262+
export function setRpcContext(context: ViteDevToolsNodeContext, options: { targetDir: string }) {
263263
rpcContext.set(context, options)
264264
}
265265

266-
export function getRpcContext(context: DevToolsNodeContext) {
266+
export function getRpcContext(context: ViteDevToolsNodeContext) {
267267
const value = rpcContext.get(context)
268268
if (!value)
269269
throw new Error('Missing RPC context')
@@ -381,29 +381,29 @@ export default function setup(ctx: DockClientScriptContext) {
381381

382382
### Sharing state across RPC functions
383383

384-
When multiple RPC functions need the same plugin-specific state (a manager instance, plugin options, cached data), key a `WeakMap` by `DevToolsNodeContext`. This keeps the plugin state scoped, garbage-collectable, and out of the base context.
384+
When multiple RPC functions need the same plugin-specific state (a manager instance, plugin options, cached data), key a `WeakMap` by `ViteDevToolsNodeContext`. This keeps the plugin state scoped, garbage-collectable, and out of the base context.
385385

386386
Create a helper file with get/set functions:
387387

388388
```ts
389389
// src/node/rpc/context.ts
390-
import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
390+
import type { ViteDevToolsNodeContext } from '@vitejs/devtools-kit'
391391

392392
interface MyPluginContext {
393393
dataDir: string
394394
manager: DataManager
395395
}
396396

397-
const pluginContext = new WeakMap<DevToolsNodeContext, MyPluginContext>()
397+
const pluginContext = new WeakMap<ViteDevToolsNodeContext, MyPluginContext>()
398398

399-
export function getPluginContext(ctx: DevToolsNodeContext): MyPluginContext {
399+
export function getPluginContext(ctx: ViteDevToolsNodeContext): MyPluginContext {
400400
const value = pluginContext.get(ctx)
401401
if (!value)
402402
throw new Error('Plugin context not initialized')
403403
return value
404404
}
405405

406-
export function setPluginContext(ctx: DevToolsNodeContext, value: MyPluginContext) {
406+
export function setPluginContext(ctx: ViteDevToolsNodeContext, value: MyPluginContext) {
407407
pluginContext.set(ctx, value)
408408
}
409409
```

examples/plugin-file-explorer/src/node/rpc/context.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
1+
import type { ViteDevToolsNodeContext } from '@vitejs/devtools-kit'
22
import type { KitPluginFileExplorerResolvedOptions } from '../types'
33

4-
const fileExplorerOptions = new WeakMap<DevToolsNodeContext, KitPluginFileExplorerResolvedOptions>()
4+
const fileExplorerOptions = new WeakMap<ViteDevToolsNodeContext, KitPluginFileExplorerResolvedOptions>()
55

66
export function setFileExplorerOptions(
7-
context: DevToolsNodeContext,
7+
context: ViteDevToolsNodeContext,
88
options: KitPluginFileExplorerResolvedOptions,
99
): void {
1010
fileExplorerOptions.set(context, options)
1111
}
1212

13-
export function getFileExplorerOptions(context: DevToolsNodeContext): KitPluginFileExplorerResolvedOptions {
13+
export function getFileExplorerOptions(context: ViteDevToolsNodeContext): KitPluginFileExplorerResolvedOptions {
1414
const options = fileExplorerOptions.get(context)
1515
if (!options) {
1616
throw new Error('[kit-plugin-file-explorer] Missing plugin options in context. Ensure setup calls setFileExplorerOptions(context, options) before registering RPC functions.')

packages/core/src/client/webcomponents/state/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { DevToolsClientCommand, DevToolsCommandEntry, DevToolsCommandKeybinding, DevToolsDocksUserSettings, DevToolsServerCommandEntry, WhenContext } from '@vitejs/devtools-kit'
1+
import type { DevToolsClientCommand, DevToolsCommandEntry, DevToolsCommandKeybinding, DevToolsDocksUserSettings, DevToolsServerCommandEntry } from '@vitejs/devtools-kit'
22
import type { CommandsContext, DevToolsRpcClient } from '@vitejs/devtools-kit/client'
33
import type { SharedState } from 'devframe/utils/shared-state'
4+
import type { WhenContext } from 'devframe/utils/when'
45
import type { ShallowRef } from 'vue'
56
import { evaluateWhen } from 'devframe/utils/when'
67
import { computed, markRaw, reactive, ref } from 'vue'

packages/core/src/client/webcomponents/state/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { DevToolsClientCommand, WhenContext } from '@vitejs/devtools-kit'
1+
import type { DevToolsClientCommand } from '@vitejs/devtools-kit'
22
import type { CommandsContext, DevToolsRpcClient, DockClientScriptContext, DockEntryState, DockPanelStorage, DocksContext } from '@vitejs/devtools-kit/client'
33
import type { SharedState } from 'devframe/utils/shared-state'
4+
import type { WhenContext } from 'devframe/utils/when'
45
import type { Ref } from 'vue'
56
import type { DevToolsDocksUserSettings } from './dock-settings'
67
import { DEFAULT_STATE_USER_SETTINGS } from '@vitejs/devtools-kit/constants'

packages/core/src/client/webcomponents/state/dock-settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { DevToolsDockEntriesGrouped, DevToolsDockEntry, DevToolsDocksUserSettings, WhenContext } from '@vitejs/devtools-kit'
1+
import type { DevToolsDockEntriesGrouped, DevToolsDockEntry, DevToolsDocksUserSettings } from '@vitejs/devtools-kit'
22
import type { Immutable } from 'devframe/utils/shared-state'
3+
import type { WhenContext } from 'devframe/utils/when'
34
import { evaluateWhen } from 'devframe/utils/when'
45
import { DEFAULT_CATEGORIES_ORDER } from '../constants'
56

packages/core/src/client/webcomponents/state/keybindings.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { DevToolsCommandEntry, DevToolsCommandKeybinding } from '@vitejs/devtools-kit'
22

3-
// Re-export when utilities from kit
4-
export type { WhenContext } from '@vitejs/devtools-kit'
3+
export type { WhenContext } from 'devframe/utils/when'
54
export { evaluateWhen, resolveContextValue } from 'devframe/utils/when'
65

76
export const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform ?? '')

packages/core/src/node/__tests__/open-in-editor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
1+
import type { ViteDevToolsNodeContext } from '@vitejs/devtools-kit'
22
import { resolve } from 'node:path'
33
import { describe, expect, it, vi } from 'vitest'
44
import { openInEditor } from '../rpc/public/open-in-editor'
@@ -11,7 +11,7 @@ vi.mock('devframe/utils/launch-editor', () => ({
1111
describe('openInEditor – path traversal protection', () => {
1212
const cwd = resolve('/project/root')
1313
const workspaceRoot = resolve('/project')
14-
const mockContext = { cwd, workspaceRoot } as DevToolsNodeContext
14+
const mockContext = { cwd, workspaceRoot } as ViteDevToolsNodeContext
1515

1616
async function getHandler() {
1717
const setup = openInEditor.setup!

0 commit comments

Comments
 (0)