Skip to content
Open
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
35 changes: 35 additions & 0 deletions packages/kit/src/node/vite-host.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { ResolvedConfig } from 'vite'
import { homedir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { createViteDevToolsHost } from './vite-host'

/** Only `root` is read off the Vite config by the host's storage layout. */
function storageDir(scope: 'workspace' | 'project' | 'global', workspaceRoot?: string): string {
return createViteDevToolsHost({
viteConfig: { root: '/repo/apps/site' } as unknown as ResolvedConfig,
workspaceRoot,
}).getStorageDir(scope)
}

describe('storage scopes', () => {
it('keeps the workspace scope committable', () => {
expect(storageDir('workspace', '/repo')).toBe(join('/repo', '.vite/devtools'))
})

it('places the per-checkout scope under node_modules', () => {
expect(storageDir('project', '/repo')).toBe(join('/repo', 'node_modules/.vite/devtools'))
})

it('places the per-user scope in the home directory', () => {
expect(storageDir('global', '/repo')).toBe(join(homedir(), '.vite/devtools'))
})

it('keeps per-checkout data out of the per-user directory', () => {
expect(storageDir('project', '/repo')).not.toBe(storageDir('global', '/repo'))
})

it('falls back to the Vite root for the workspace root', () => {
expect(storageDir('workspace')).toBe(join('/repo/apps/site', '.vite/devtools'))
})
})
17 changes: 14 additions & 3 deletions packages/kit/src/node/vite-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,21 @@ export function createViteDevToolsHost(options: CreateViteDevToolsHostOptions):
const reachable = host === '0.0.0.0' || host === '::' || !host ? 'localhost' : host
return `${https ? 'https' : 'http'}://${reachable}:${port}`
},
/**
* Mirror devframe's storage layout: `workspace` is committable and
* team-shared, `project` rotates with the checkout's `node_modules`, and
* `global` is per-user. Each scope needs its own directory, or a
* per-checkout file lands where every other project reads it.
*
* The workspace dir deliberately avoids `.vite-devtools`, which is the
* CLI's default build `outDir` and gets wiped by every build.
*/
getStorageDir(scope) {
return scope === 'workspace'
? join(workspaceRoot, 'node_modules/.vite/devtools')
: join(homedir(), '.vite/devtools')
if (scope === 'workspace')
return join(workspaceRoot, '.vite/devtools')
if (scope === 'project')
return join(workspaceRoot, 'node_modules/.vite/devtools')
return join(homedir(), '.vite/devtools')
},
}
}