Skip to content

Commit 1ff0ed6

Browse files
antfubotopencode
andauthored
feat(deps): migrate to Vite DevTools v0.5.0 and Devframe v0.9.2 (#1065)
Co-authored-by: opencode <noreply@opencode.ai>
1 parent 190ff43 commit 1ff0ed6

7 files changed

Lines changed: 642 additions & 517 deletions

File tree

‎packages/devtools/src/integrations/code-server.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { CodeServerIntegrationOptions, NuxtDevtoolsServerContext } from '..
44
import { createCodeServerDevframe } from '@devframes/plugin-code-server'
55
import { setupCodeServer } from '@devframes/plugin-code-server/node'
66
import { deprecate, NUXT_DEVTOOLS_GROUP_ID, onDevtoolsReady } from '@nuxt/devtools-kit'
7-
import { mountDevframe } from '@vitejs/devtools-kit/node'
87

98
const RESERVED_ARGS = ['--auth', '--bind-addr', '--cookie-suffix'] as const
109
const RESERVED_ENV = ['PASSWORD', 'HASHED_PASSWORD'] as const
@@ -91,9 +90,9 @@ export function setup(ctx: NuxtDevtoolsServerContext): void {
9190
})
9291

9392
onDevtoolsReady((kit) => {
94-
// `mountDevframe` is re-exported from the hub package while the hook uses
95-
// the Vite kit's enriched context type; they are the same runtime object.
96-
return mountDevframe(kit as any, mountedDefinition, {
93+
// `ctx.install` (from the hub context the Vite kit extends) serves the
94+
// definition's SPA, synthesizes its iframe dock, and runs its `setup`.
95+
return kit.install(mountedDefinition, {
9796
dock: {
9897
groupId: NUXT_DEVTOOLS_GROUP_ID,
9998
category: 'modules',

‎packages/devtools/src/integrations/data-inspector.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { NuxtDevtoolsServerContext, NuxtServerData } from '../types'
44
import type { AnyNitro } from '../utils/nitro-compat'
55
import { createDataInspectorDevframe, registerDataSource } from '@devframes/plugin-data-inspector'
66
import { deprecate, NUXT_DEVTOOLS_GROUP_ID, onDevtoolsReady } from '@nuxt/devtools-kit'
7-
import { mountDevframe } from '@vitejs/devtools-kit/node'
87

98
/**
109
* Live capture of the Nuxt server-side configuration surfaced by the Data
@@ -116,9 +115,9 @@ export function setup(ctx: NuxtDevtoolsServerContext): void {
116115
// overridden per-mount: group members do not inherit their group's category.
117116
const definition = createDataInspectorDevframe({ exampleSource: false })
118117
onDevtoolsReady((kit) => {
119-
// `mountDevframe` is re-exported from the hub package while the hook uses
120-
// the Vite kit's enriched context type; they are the same runtime object.
121-
return mountDevframe(kit as any, definition, {
118+
// `ctx.install` (from the hub context the Vite kit extends) serves the
119+
// definition's SPA, synthesizes its iframe dock, and runs its `setup`.
120+
return kit.install(definition, {
122121
dock: {
123122
groupId: NUXT_DEVTOOLS_GROUP_ID,
124123
category: 'advanced',

‎packages/devtools/src/module-main.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
7575
nuxt.options.vite.optimizeDeps ||= {}
7676
nuxt.options.vite.optimizeDeps.include ||= []
7777
nuxt.options.vite.optimizeDeps.include.push(
78-
'nuxt > @nuxt/devtools > @vitejs/devtools/client/inject',
78+
// Vite DevTools 0.5's embedded client is served by the hub as an external
79+
// `embedded.js` script (see `runtime/plugins/vite-devtools.client`), so it
80+
// is no longer a bundler-resolved `@vitejs/devtools/client/inject` import to
81+
// pre-bundle here.
7982
'nuxt > @nuxt/devtools > @vitejs/devtools-kit/client',
8083
'nuxt > @nuxt/devtools > error-stack-parser-es',
8184
'nuxt > @nuxt/devtools > vite-plugin-vue-tracer/client/overlay',
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import { DEVTOOLS_MOUNT_PATH } from '@vitejs/devtools-kit/constants'
12
import { defineNuxtPlugin } from '#imports'
23

34
export default defineNuxtPlugin(() => {
4-
import('@vitejs/devtools/client/inject')
5+
// Vite DevTools 0.5 no longer exposes an importable `@vitejs/devtools/client/inject`
6+
// entry; its embedded overlay client now ships as `@devframes/hub-ui` and is
7+
// served by the hub at `<mount>/embedded.js`. Load it the same way the upstream
8+
// `DevToolsInjection` Vite plugin does — a runtime-created module script, rather
9+
// than a bundler `import()`, so the hub-served URL stays out of Vite's module
10+
// graph and its `import.meta.url`-relative asset fetches (e.g. `branding.json`)
11+
// resolve against the real served URL.
12+
const script = document.createElement('script')
13+
script.type = 'module'
14+
script.src = `${DEVTOOLS_MOUNT_PATH}embedded.js`
15+
document.body.appendChild(script)
516
})

‎packages/devtools/test/code-server.test.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { resolveCodeServerOptions, setup } from '../src/integrations/code-server
66

77
const mocks = vi.hoisted(() => ({
88
createCodeServerDevframe: vi.fn(),
9-
mountDevframe: vi.fn(),
9+
install: vi.fn(),
1010
setupCodeServer: vi.fn(),
1111
dispose: vi.fn(),
1212
}))
@@ -19,10 +19,6 @@ vi.mock('@devframes/plugin-code-server/node', () => ({
1919
setupCodeServer: mocks.setupCodeServer,
2020
}))
2121

22-
vi.mock('@vitejs/devtools-kit/node', () => ({
23-
mountDevframe: mocks.mountDevframe,
24-
}))
25-
2622
function fakeContext(moduleOptions: Record<string, any> = {}) {
2723
const hooks = createHooks()
2824
const nuxt = {
@@ -52,7 +48,7 @@ beforeEach(() => {
5248
setup: vi.fn(),
5349
}))
5450
mocks.setupCodeServer.mockResolvedValue({ dispose: mocks.dispose })
55-
mocks.mountDevframe.mockImplementation(async (_kit, definition) => {
51+
mocks.install.mockImplementation(async (definition) => {
5652
await definition.setup({ cwd: '/project' })
5753
})
5854
})
@@ -114,7 +110,7 @@ describe('code server setup', () => {
114110
await nuxt.callHook('devtools:ready', {} as any)
115111

116112
expect(mocks.createCodeServerDevframe).not.toHaveBeenCalled()
117-
expect(mocks.mountDevframe).not.toHaveBeenCalled()
113+
expect(mocks.install).not.toHaveBeenCalled()
118114
})
119115

120116
it('mounts the plugin in the Nuxt group and disposes its supervisor on close', async () => {
@@ -127,10 +123,9 @@ describe('code server setup', () => {
127123
serverPort: 9090,
128124
}))
129125

130-
const kit = { id: 'kit' }
126+
const kit = { id: 'kit', install: mocks.install }
131127
await nuxt.callHook('devtools:ready', kit as any)
132-
expect(mocks.mountDevframe).toHaveBeenCalledWith(
133-
kit,
128+
expect(mocks.install).toHaveBeenCalledWith(
134129
expect.objectContaining({ id: 'devframes_plugin_code-server' }),
135130
{
136131
dock: {
@@ -157,7 +152,7 @@ describe('code server setup', () => {
157152
const { ctx, nuxt } = fakeContext()
158153
setup(ctx)
159154

160-
const ready = nuxt.callHook('devtools:ready', { id: 'kit' } as any)
155+
const ready = nuxt.callHook('devtools:ready', { id: 'kit', install: mocks.install } as any)
161156
await vi.waitFor(() => {
162157
expect(mocks.setupCodeServer).toHaveBeenCalledOnce()
163158
})

0 commit comments

Comments
 (0)