From 8d4687885afde2f48c1a60c3776a4fbdbd654146 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 10 Mar 2026 19:39:04 +0900 Subject: [PATCH] wip: --- packages/devtools-kit/src/_types/options.ts | 8 - packages/devtools-kit/src/index.test.ts | 96 ++++++++++ .../client/components/DockingPanel.vue | 1 - packages/devtools/client/pages/index.vue | 15 -- packages/devtools/client/pages/settings.vue | 40 ----- packages/devtools/package.json | 8 +- .../src/integrations/vite-devtools.test.ts | 57 ++++++ .../src/integrations/vite-devtools.ts | 61 +++++++ packages/devtools/src/module-main.ts | 49 ++--- .../src/runtime/plugins/devtools.client.ts | 12 +- .../src/runtime/plugins/view/client.ts | 169 +++--------------- .../src/runtime/plugins/view/state.ts | 3 - .../runtime/plugins/view/vite-dock.test.ts | 83 +++++++++ .../src/runtime/plugins/view/vite-dock.ts | 58 ++++++ .../runtime/plugins/vite-devtools.client.ts | 5 - playgrounds/module-starter/test/basic.test.js | 41 +++++ playgrounds/module-starter/test/basic.test.ts | 15 -- playgrounds/module-starter/tsconfig.json | 2 +- pnpm-lock.yaml | 84 ++++----- 19 files changed, 485 insertions(+), 322 deletions(-) create mode 100644 packages/devtools-kit/src/index.test.ts create mode 100644 packages/devtools/src/integrations/vite-devtools.test.ts create mode 100644 packages/devtools/src/integrations/vite-devtools.ts create mode 100644 packages/devtools/src/runtime/plugins/view/vite-dock.test.ts create mode 100644 packages/devtools/src/runtime/plugins/view/vite-dock.ts delete mode 100644 packages/devtools/src/runtime/plugins/vite-devtools.client.ts create mode 100644 playgrounds/module-starter/test/basic.test.js delete mode 100644 playgrounds/module-starter/test/basic.test.ts diff --git a/packages/devtools-kit/src/_types/options.ts b/packages/devtools-kit/src/_types/options.ts index b0ac0ae05a..b246594a3f 100644 --- a/packages/devtools-kit/src/_types/options.ts +++ b/packages/devtools-kit/src/_types/options.ts @@ -43,14 +43,6 @@ export interface ModuleOptions { */ viteInspect?: boolean - /** - * Enable Vite DevTools integration - * - * @experimental - * @default false - */ - viteDevTools?: boolean - /** * Disable dev time authorization check. * diff --git a/packages/devtools-kit/src/index.test.ts b/packages/devtools-kit/src/index.test.ts new file mode 100644 index 0000000000..fa2885f671 --- /dev/null +++ b/packages/devtools-kit/src/index.test.ts @@ -0,0 +1,96 @@ +import { Buffer } from 'node:buffer' +import { EventEmitter } from 'node:events' +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { extendServerRpc, startSubprocess } from './index' + +const { execaMock } = vi.hoisted(() => ({ + execaMock: vi.fn(), +})) + +vi.mock('execa', () => ({ + execa: execaMock, +})) + +class MockProcess extends EventEmitter { + stdout = new EventEmitter() + stderr = new EventEmitter() + kill = vi.fn() +} + +describe('@nuxt/devtools-kit compat helpers', () => { + beforeEach(() => { + execaMock.mockReset() + }) + + it('extends server rpc through devtools context', () => { + const rpc = { + broadcast: { + ping: vi.fn(), + }, + } + const nuxt = { + devtools: { + extendServerRpc: vi.fn(() => rpc), + }, + } + + const result = extendServerRpc('custom-rpc', { + hello() { + return 'hi' + }, + }, nuxt as any) + + expect((nuxt.devtools.extendServerRpc as any).mock.calls[0]?.[0]).toBe('custom-rpc') + expect(result).toBe(rpc as any) + }) + + it('streams subprocess output to terminal hooks', () => { + const process = new MockProcess() + execaMock.mockReturnValue(process) + + const callHook = vi.fn() + const closeHooks: (() => void)[] = [] + const nuxt = { + callHook, + hook(name: string, fn: () => void) { + if (name === 'close') + closeHooks.push(fn) + }, + } + + const subprocess = startSubprocess( + { + command: 'node', + args: ['-e', 'console.log("hello")'], + }, + { + id: 'devtools:test', + name: 'Test Terminal', + }, + nuxt as any, + ) + + expect(callHook).toHaveBeenCalledWith('devtools:terminal:register', expect.objectContaining({ + id: 'devtools:test', + name: 'Test Terminal', + })) + expect(callHook).toHaveBeenCalledWith('devtools:terminal:write', expect.objectContaining({ + id: 'devtools:test', + data: expect.stringContaining('node -e console.log("hello")'), + })) + + process.stdout.emit('data', Buffer.from('stdout')) + process.stderr.emit('data', Buffer.from('stderr')) + process.emit('exit', 0) + + expect(callHook).toHaveBeenCalledWith('devtools:terminal:write', { id: 'devtools:test', data: 'stdout' }) + expect(callHook).toHaveBeenCalledWith('devtools:terminal:write', { id: 'devtools:test', data: 'stderr' }) + expect(callHook).toHaveBeenCalledWith('devtools:terminal:exit', { id: 'devtools:test', code: 0 }) + + subprocess.terminate() + expect(callHook).toHaveBeenCalledWith('devtools:terminal:remove', { id: 'devtools:test' }) + + closeHooks.forEach(fn => fn()) + expect((process as any).kill).toHaveBeenCalled() + }) +}) diff --git a/packages/devtools/client/components/DockingPanel.vue b/packages/devtools/client/components/DockingPanel.vue index d5a4d2bc40..8f3f994b91 100644 --- a/packages/devtools/client/components/DockingPanel.vue +++ b/packages/devtools/client/components/DockingPanel.vue @@ -31,7 +31,6 @@ function toggleSplitScreen() {
{{ splitScreenEnabled ? 'Close Split Screen' : 'Split Screen' }} -
diff --git a/packages/devtools/client/pages/index.vue b/packages/devtools/client/pages/index.vue index 5ed6f7514e..1b3f298f11 100644 --- a/packages/devtools/client/pages/index.vue +++ b/packages/devtools/client/pages/index.vue @@ -1,31 +1,19 @@