diff --git a/packages/devtools/src/dev-auth.ts b/packages/devtools/src/dev-auth.ts index 1e5a47cf4..44af3b5f6 100644 --- a/packages/devtools/src/dev-auth.ts +++ b/packages/devtools/src/dev-auth.ts @@ -1,8 +1,8 @@ -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 @@ -10,7 +10,7 @@ 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') diff --git a/packages/devtools/src/utils/local-options.ts b/packages/devtools/src/utils/local-options.ts index 490ec6427..3b21dd9ec 100644 --- a/packages/devtools/src/utils/local-options.ts +++ b/packages/devtools/src/utils/local-options.ts @@ -10,6 +10,10 @@ interface LocalOptionSearchOptions { key?: string | boolean } +export function getHomeDir() { + return process.env.XDG_CONFIG_HOME || homedir() +} + export async function readLocalOptions(defaults: T, options: LocalOptionSearchOptions): Promise { const { filePath } = getOptionsFilepath(options) @@ -34,11 +38,15 @@ export async function readLocalOptions(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,