From 10d9dcb221719fdf3ef25b196464a93f13ea86d3 Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 7 Oct 2026 15:02:11 +0200 Subject: [PATCH 1/2] fix(core): type DevTools() options as the config they are applied as --- .../src/node/__tests__/plugin-options.test.ts | 16 ++++++++++++++++ packages/core/src/node/plugin-options.ts | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/core/src/node/__tests__/plugin-options.test.ts diff --git a/packages/core/src/node/__tests__/plugin-options.test.ts b/packages/core/src/node/__tests__/plugin-options.test.ts new file mode 100644 index 000000000..9eda36be9 --- /dev/null +++ b/packages/core/src/node/__tests__/plugin-options.test.ts @@ -0,0 +1,16 @@ +import type { Plugin } from 'vite' +import { describe, expect, it } from 'vitest' +import { DevTools } from '../plugins' + +describe('devTools() options', () => { + it('accepts config options such as clientAuth', async () => { + const plugins = await DevTools({ clientAuth: false, clientAuthTokens: ['token'] }) + const configPlugin = plugins.find(p => p.name === 'vite:devtools') as Plugin + const viteConfig = { plugins, server: { host: undefined } } as any + const hook = configPlugin.configResolved as { handler: (config: any) => void } + hook.handler(viteConfig) + + expect(viteConfig.devtools.config.clientAuth).toBe(false) + expect(viteConfig.devtools.config.clientAuthTokens).toEqual(['token']) + }) +}) diff --git a/packages/core/src/node/plugin-options.ts b/packages/core/src/node/plugin-options.ts index 5714b87aa..9786367cd 100644 --- a/packages/core/src/node/plugin-options.ts +++ b/packages/core/src/node/plugin-options.ts @@ -1,3 +1,5 @@ +import type { DevToolsConfig } from './config' + export type DevToolsBrandingLogo = | string | { light: string, dark: string } @@ -72,7 +74,12 @@ export interface DevToolsUserOptions { } } -export interface DevToolsOptions extends DevToolsUserOptions { +/** + * Options for the `DevTools()` plugin. They are applied as the DevTools config, + * so everything the `devtools` Vite option accepts works here too (e.g. `clientAuth`), + * except `enabled` and `apply`: adding the plugin enables it, and Vite's own `apply` picks the command. + */ +export interface DevToolsOptions extends Omit { /** Directory to search for installed integrations. */ cwd?: string } From 2c60c11904afb4e4bafea693e8838ea71944050c Mon Sep 17 00:00:00 2001 From: arlo Date: Wed, 7 Oct 2026 22:18:09 +0800 Subject: [PATCH 2/2] chore: unit test --- .../src/node/__tests__/plugin-options.test.ts | 22 ++++++++----------- packages/core/src/node/plugin-options.ts | 5 ----- .../src/node/plugins/__tests__/index.test.ts | 6 +++-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/core/src/node/__tests__/plugin-options.test.ts b/packages/core/src/node/__tests__/plugin-options.test.ts index 9eda36be9..8b7db9255 100644 --- a/packages/core/src/node/__tests__/plugin-options.test.ts +++ b/packages/core/src/node/__tests__/plugin-options.test.ts @@ -1,16 +1,12 @@ -import type { Plugin } from 'vite' -import { describe, expect, it } from 'vitest' -import { DevTools } from '../plugins' +import type { DevToolsConfig } from '../config' +import type { DevTools } from '../plugins' +import { expectTypeOf, it } from 'vitest' -describe('devTools() options', () => { - it('accepts config options such as clientAuth', async () => { - const plugins = await DevTools({ clientAuth: false, clientAuthTokens: ['token'] }) - const configPlugin = plugins.find(p => p.name === 'vite:devtools') as Plugin - const viteConfig = { plugins, server: { host: undefined } } as any - const hook = configPlugin.configResolved as { handler: (config: any) => void } - hook.handler(viteConfig) +it('accepts config options and an integration directory', () => { + type Options = Parameters[0] + type Expected = (Omit & { cwd?: string }) | undefined - expect(viteConfig.devtools.config.clientAuth).toBe(false) - expect(viteConfig.devtools.config.clientAuthTokens).toEqual(['token']) - }) + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toExtend() + expectTypeOf().toExtend() }) diff --git a/packages/core/src/node/plugin-options.ts b/packages/core/src/node/plugin-options.ts index 9786367cd..6ba4a72be 100644 --- a/packages/core/src/node/plugin-options.ts +++ b/packages/core/src/node/plugin-options.ts @@ -74,11 +74,6 @@ export interface DevToolsUserOptions { } } -/** - * Options for the `DevTools()` plugin. They are applied as the DevTools config, - * so everything the `devtools` Vite option accepts works here too (e.g. `clientAuth`), - * except `enabled` and `apply`: adding the plugin enables it, and Vite's own `apply` picks the command. - */ export interface DevToolsOptions extends Omit { /** Directory to search for installed integrations. */ cwd?: string diff --git a/packages/core/src/node/plugins/__tests__/index.test.ts b/packages/core/src/node/plugins/__tests__/index.test.ts index 4d1a81ac7..27fec17f0 100644 --- a/packages/core/src/node/plugins/__tests__/index.test.ts +++ b/packages/core/src/node/plugins/__tests__/index.test.ts @@ -38,6 +38,8 @@ describe('devTools', () => { const plugins = await DevTools({ builtinDevTools: false, embeddedVisibility: 'passive', + clientAuth: false, + clientAuthTokens: ['token'], }) const config = await resolveConfig({ configFile: false, @@ -56,8 +58,8 @@ describe('devTools', () => { apply: 'all', config: { builtinDevTools: false, - clientAuth: true, - clientAuthTokens: [], + clientAuth: false, + clientAuthTokens: ['token'], embeddedVisibility: 'passive', host: 'localhost', },