mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 00:35:51 +00:00
feat: add VS Code IDE bridge extension
This commit is contained in:
56
packages/vscode-ide-bridge/src/server/lockfile.ts
Normal file
56
packages/vscode-ide-bridge/src/server/lockfile.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { mkdir, rm, writeFile } from 'node:fs/promises'
|
||||
import { homedir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import type { LockfilePayload } from './protocol.js'
|
||||
|
||||
type BuildLockfilePayloadInput = {
|
||||
pid: number
|
||||
ideName: string
|
||||
workspaceFolders: string[]
|
||||
authToken: string
|
||||
runningInWindows: boolean
|
||||
}
|
||||
|
||||
function getClaudeConfigDir(): string {
|
||||
return (process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude')).normalize(
|
||||
'NFC',
|
||||
)
|
||||
}
|
||||
|
||||
export function buildLockfilePayload(
|
||||
input: BuildLockfilePayloadInput,
|
||||
): LockfilePayload {
|
||||
return {
|
||||
workspaceFolders: input.workspaceFolders,
|
||||
pid: input.pid,
|
||||
ideName: input.ideName,
|
||||
transport: 'ws',
|
||||
runningInWindows: input.runningInWindows,
|
||||
authToken: input.authToken,
|
||||
}
|
||||
}
|
||||
|
||||
export function getLockfileDir(): string {
|
||||
return join(getClaudeConfigDir(), 'ide')
|
||||
}
|
||||
|
||||
export function getLockfilePath(port: number): string {
|
||||
return join(getLockfileDir(), `${port}.lock`)
|
||||
}
|
||||
|
||||
export async function writeLockfile(
|
||||
port: number,
|
||||
payload: LockfilePayload,
|
||||
): Promise<string> {
|
||||
const lockfilePath = getLockfilePath(port)
|
||||
await mkdir(getLockfileDir(), { recursive: true })
|
||||
await writeFile(lockfilePath, JSON.stringify(payload), 'utf8')
|
||||
return lockfilePath
|
||||
}
|
||||
|
||||
export async function removeLockfile(lockfilePath: string | null): Promise<void> {
|
||||
if (!lockfilePath) {
|
||||
return
|
||||
}
|
||||
await rm(lockfilePath, { force: true })
|
||||
}
|
||||
Reference in New Issue
Block a user