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
4 changes: 2 additions & 2 deletions packages/devtools/src/dev-auth.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { homedir } from 'node:os'
import { join } from 'node:path'
import { existsSync } from 'node:fs'
import fs from 'node:fs/promises'
import { randomStr } from '@antfu/utils'
import { getHomeDir } from './utils/local-options'

let token: string | undefined

export async function getDevAuthToken() {
if (token)
return token

const home = homedir()
const home = getHomeDir()
const dir = join(home, '.nuxt/devtools')
const filepath = join(dir, 'dev-auth-token.txt')

Expand Down
10 changes: 9 additions & 1 deletion packages/devtools/src/utils/local-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ interface LocalOptionSearchOptions {
key?: string | boolean
}

export function getHomeDir() {
return process.env.XDG_CONFIG_HOME || homedir()
}

export async function readLocalOptions<T>(defaults: T, options: LocalOptionSearchOptions): Promise<T> {
const { filePath } = getOptionsFilepath(options)

Expand All @@ -34,11 +38,15 @@ export async function readLocalOptions<T>(defaults: T, options: LocalOptionSearc

function getOptionsFilepath(options: LocalOptionSearchOptions) {
let hashedKey

if (options.key)
hashedKey = hash(`${options.root}:${options.key}`)
else
hashedKey = hash(options.root)
const filePath = join(homedir(), '.nuxt/devtools', `${hashedKey}.json`)

const home = getHomeDir()
const filePath = join(home, '.nuxt/devtools', `${hashedKey}.json`)

return {
filePath,
hashedKey,
Expand Down