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

let token: string | undefined

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

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

if (existsSync(filepath))
Expand Down
21 changes: 16 additions & 5 deletions packages/devtools/src/utils/local-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'node:fs'
import fs from 'node:fs/promises'
import { homedir } from 'node:os'
import { homedir, platform } from 'node:os'
import { dirname } from 'node:path'
import { hash } from 'ohash'
import { join } from 'pathe'
Expand All @@ -10,8 +10,19 @@ interface LocalOptionSearchOptions {
key?: string | boolean
}

export function getHomeDir() {
return process.env.XDG_CONFIG_HOME || homedir()
export function getOptionsDir() {
const home = homedir()
const osPlatform = platform()

// From research, there three are not trying to be XDG compliant. Leave it as before
if (osPlatform === 'win32' || osPlatform === 'darwin' || osPlatform === 'haiku') {
return join(home, '.nuxt/devtools')
}

// https://specifications.freedesktop.org/basedir/latest/#variables
// Check if env var is set, otherwise fallback to $HOME/.config
const xdgBase = process.env.XDG_CONFIG_HOME || join(home, '.config')
return join(xdgBase, 'nuxt/devtools')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

export async function readLocalOptions<T>(defaults: T, options: LocalOptionSearchOptions): Promise<T> {
Expand Down Expand Up @@ -44,8 +55,8 @@ function getOptionsFilepath(options: LocalOptionSearchOptions) {
else
hashedKey = hash(options.root)

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

return {
filePath,
Expand Down
Loading