Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/core/src/node/plugins/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isPackageExists } from 'local-pkg'
import { resolve } from 'pathe'
import { describe, expect, it, vi } from 'vitest'
import { DevTools } from '../index'

vi.mock('local-pkg', () => ({
isPackageExists: vi.fn(() => false),
}))

describe('devTools', () => {
Comment thread
webfansplz marked this conversation as resolved.
it('resolves optional integrations from the configured project directory', async () => {
const cwd = 'project/root'
const resolvedCwd = resolve(cwd)

await DevTools({ cwd })

expect(vi.mocked(isPackageExists)).toHaveBeenCalledTimes(4)
expect(vi.mocked(isPackageExists).mock.calls).toEqual([
['@vitejs/devtools-rolldown', { paths: [resolvedCwd] }],
['@vitejs/devtools-vite', { paths: [resolvedCwd] }],
['@vitejs/devtools-vitest', { paths: [resolvedCwd] }],
['@vitejs/devtools-oxc', { paths: [resolvedCwd] }],
])
})
})
5 changes: 4 additions & 1 deletion packages/core/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createTerminalsDevframe } from '@devframes/plugin-terminals'
import { DEVTOOLS_INSPECTOR_DOCK_ID, DEVTOOLS_VITEPLUS_GROUP_ID } from '@vitejs/devtools-kit/constants'
import { createInstallLauncher, createPluginFromDevframe } from '@vitejs/devtools-kit/node'
import { isPackageExists } from 'local-pkg'
import { resolve } from 'pathe'
import { version } from '../../../package.json'
import { hideDockWhenEmpty } from './auto-hide'
import { DevToolsBuild } from './build'
Expand Down Expand Up @@ -90,6 +91,8 @@ const BUILTIN_INTEGRATIONS: BuiltinIntegration[] = [
]

export interface DevToolsOptions {
/** Directory to search for installed integrations. */
cwd?: string
/**
* Include the Vite builtin devtools UI.
*
Expand Down Expand Up @@ -120,6 +123,7 @@ export async function DevTools(options: DevToolsOptions = {}): Promise<Plugin[]>
builtinDevTools = true,
build,
} = options
const cwd = resolve(options.cwd ?? process.cwd())

const plugins = [
DevToolsInjection(),
Expand All @@ -137,7 +141,6 @@ export async function DevTools(options: DevToolsOptions = {}): Promise<Plugin[]>
// package is installed, its real plugin is mounted; when absent, a
// discovery launcher is shown that installs it on demand, then prompts a
// restart so the next config resolution mounts the real plugin.
const cwd = process.cwd()
for (const integration of BUILTIN_INTEGRATIONS) {
if (isPackageExists(integration.pkg, { paths: [cwd] })) {
plugins.push(...await integration.load())
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function startStandaloneDevTools(options: StandaloneDevToolsOptions
configFile: options.config,
root: cwd,
plugins: [
DevTools(),
DevTools({ cwd }),
],
},
command,
Expand Down
Loading