Skip to content

Commit 4abd280

Browse files
paro-paroantfu
andauthored
feat(devtools): support for xdg-home-config (#526)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 68b8cfc commit 4abd280

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/devtools/src/dev-auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { homedir } from 'node:os'
21
import { join } from 'node:path'
32
import { existsSync } from 'node:fs'
43
import fs from 'node:fs/promises'
54
import { randomStr } from '@antfu/utils'
5+
import { getHomeDir } from './utils/local-options'
66

77
let token: string | undefined
88

99
export async function getDevAuthToken() {
1010
if (token)
1111
return token
1212

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

packages/devtools/src/utils/local-options.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ interface LocalOptionSearchOptions {
1010
key?: string | boolean
1111
}
1212

13+
export function getHomeDir() {
14+
return process.env.XDG_CONFIG_HOME || homedir()
15+
}
16+
1317
export async function readLocalOptions<T>(defaults: T, options: LocalOptionSearchOptions): Promise<T> {
1418
const { filePath } = getOptionsFilepath(options)
1519

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

3539
function getOptionsFilepath(options: LocalOptionSearchOptions) {
3640
let hashedKey
41+
3742
if (options.key)
3843
hashedKey = hash(`${options.root}:${options.key}`)
3944
else
4045
hashedKey = hash(options.root)
41-
const filePath = join(homedir(), '.nuxt/devtools', `${hashedKey}.json`)
46+
47+
const home = getHomeDir()
48+
const filePath = join(home, '.nuxt/devtools', `${hashedKey}.json`)
49+
4250
return {
4351
filePath,
4452
hashedKey,

0 commit comments

Comments
 (0)