From fb46d677efd36974f3cc7f7904b8efdfd6419d09 Mon Sep 17 00:00:00 2001 From: Computed Functions <215638926+computed-fn@users.noreply.github.com> Date: Wed, 22 Jul 2026 16:13:57 +0700 Subject: [PATCH 1/3] fix(devtools): proper XDG base dir support --- packages/devtools/src/dev-auth.ts | 5 ++--- packages/devtools/src/utils/local-options.ts | 21 +++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/devtools/src/dev-auth.ts b/packages/devtools/src/dev-auth.ts index eebdfab0d6..236bc25988 100644 --- a/packages/devtools/src/dev-auth.ts +++ b/packages/devtools/src/dev-auth.ts @@ -2,7 +2,7 @@ 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 @@ -10,8 +10,7 @@ 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)) diff --git a/packages/devtools/src/utils/local-options.ts b/packages/devtools/src/utils/local-options.ts index 7e5eb02aca..d0ead11d1a 100644 --- a/packages/devtools/src/utils/local-options.ts +++ b/packages/devtools/src/utils/local-options.ts @@ -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' @@ -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') } export async function readLocalOptions(defaults: T, options: LocalOptionSearchOptions): Promise { @@ -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, '.nuxt/devtools', `${hashedKey}.json`) return { filePath, From 13f9be94e533ec3488b8cd42c7363bd0464ba7dc Mon Sep 17 00:00:00 2001 From: Computed Functions <215638926+computed-fn@users.noreply.github.com> Date: Wed, 22 Jul 2026 16:44:21 +0700 Subject: [PATCH 2/3] fix(devtools): accidental path nesting --- packages/devtools/src/utils/local-options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/devtools/src/utils/local-options.ts b/packages/devtools/src/utils/local-options.ts index d0ead11d1a..7f2a2e6472 100644 --- a/packages/devtools/src/utils/local-options.ts +++ b/packages/devtools/src/utils/local-options.ts @@ -56,7 +56,7 @@ function getOptionsFilepath(options: LocalOptionSearchOptions) { hashedKey = hash(options.root) const dir = getOptionsDir() - const filePath = join(dir, '.nuxt/devtools', `${hashedKey}.json`) + const filePath = join(dir, `${hashedKey}.json`) return { filePath, From 1fd8475eb58606666f80d4b2bd31adeba3c3a941 Mon Sep 17 00:00:00 2001 From: Computed Functions <215638926+computed-fn@users.noreply.github.com> Date: Wed, 22 Jul 2026 16:44:49 +0700 Subject: [PATCH 3/3] fix(devtools): accidental nullish coalesce --- packages/devtools/src/utils/local-options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/devtools/src/utils/local-options.ts b/packages/devtools/src/utils/local-options.ts index 7f2a2e6472..dc247ba9b6 100644 --- a/packages/devtools/src/utils/local-options.ts +++ b/packages/devtools/src/utils/local-options.ts @@ -21,7 +21,7 @@ export function getOptionsDir() { // 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') + const xdgBase = process.env.XDG_CONFIG_HOME || join(home, '.config') return join(xdgBase, 'nuxt/devtools') }