Skip to content

Commit de91f38

Browse files
committed
Add ENV.XDG_DATA_HOME env
1 parent 6752bfc commit de91f38

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

registry/lib/bin.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,19 @@ function findRealPnpm() {
251251
const commonPaths = WIN32
252252
? [
253253
// Windows common paths.
254-
path.join(ENV.APPDATA || '', 'npm', 'pnpm.cmd'),
255-
path.join(ENV.APPDATA || '', 'npm', 'pnpm'),
256-
path.join(ENV.LOCALAPPDATA || '', 'pnpm', 'pnpm.cmd'),
257-
path.join(ENV.LOCALAPPDATA || '', 'pnpm', 'pnpm'),
254+
path.join(ENV.APPDATA, 'npm', 'pnpm.cmd'),
255+
path.join(ENV.APPDATA, 'npm', 'pnpm'),
256+
path.join(ENV.LOCALAPPDATA, 'pnpm', 'pnpm.cmd'),
257+
path.join(ENV.LOCALAPPDATA, 'pnpm', 'pnpm'),
258258
'C:\\Program Files\\nodejs\\pnpm.cmd',
259259
'C:\\Program Files\\nodejs\\pnpm'
260260
].filter(Boolean)
261261
: [
262262
// Unix common paths.
263263
'/usr/local/bin/pnpm',
264264
'/usr/bin/pnpm',
265-
path.join(ENV.HOME || '', '.local/share/pnpm/pnpm'),
266-
path.join(ENV.HOME || '', '.pnpm/pnpm')
265+
path.join(ENV.XDG_DATA_HOME, 'pnpm/pnpm'),
266+
path.join(ENV.HOME, '.pnpm/pnpm')
267267
].filter(Boolean)
268268

269269
return findRealBin('pnpm', commonPaths)
@@ -281,8 +281,8 @@ function findRealYarn() {
281281
const commonPaths = [
282282
'/usr/local/bin/yarn',
283283
'/usr/bin/yarn',
284-
path.join(ENV.HOME || '', '.yarn/bin/yarn'),
285-
path.join(ENV.HOME || '', '.config/yarn/global/node_modules/.bin/yarn')
284+
path.join(ENV.HOME, '.yarn/bin/yarn'),
285+
path.join(ENV.HOME, '.config/yarn/global/node_modules/.bin/yarn')
286286
].filter(Boolean)
287287

288288
return findRealBin('yarn', commonPaths)

registry/lib/constants/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare interface ENV {
1111
readonly PRE_COMMIT: boolean
1212
readonly SOCKET_CLI_DEBUG: boolean
1313
readonly VITEST: boolean
14+
readonly XDG_DATA_HOME: string
1415
}
1516
declare const ENV: ENV
1617
export = ENV

registry/lib/constants/env.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict'
22

33
const { freeze: ObjectFreeze, hasOwn: ObjectHasOwn } = Object
4+
const { env } = process
45

56
const { envAsBoolean, envAsString } = /*@__PURE__*/ require('../env')
6-
7-
const { env } = process
7+
const WIN32 = /*@__PURE__*/ require('./win32')
88

99
const DEBUG = envAsString(env.DEBUG)
10+
const HOME = envAsString(env.HOME)
1011

1112
module.exports = ObjectFreeze({
1213
__proto__: null,
@@ -21,7 +22,7 @@ module.exports = ObjectFreeze({
2122
// https://socket.dev/npm/package/debug/overview/4.4.1
2223
DEBUG,
2324
// User home directory.
24-
HOME: envAsString(env.HOME),
25+
HOME,
2526
// The absolute location of the %localappdata% folder on Windows used to store
2627
// user-specific, non-roaming application data, like temporary files, cached
2728
// data, and program settings, that are specific to the current machine and user.
@@ -49,5 +50,10 @@ module.exports = ObjectFreeze({
4950
SOCKET_CLI_DEBUG: !!DEBUG || envAsBoolean(env.SOCKET_CLI_DEBUG),
5051
// VITEST=true is set by the Vitest test runner.
5152
// https://vitest.dev/config/#configuring-vitest
52-
VITEST: envAsBoolean(env.VITEST)
53+
VITEST: envAsBoolean(env.VITEST),
54+
// The location of the base directory on Linux and MacOS used to store
55+
// user-specific data files, defaulting to $HOME/.local/share if not set or empty.
56+
XDG_DATA_HOME: WIN32
57+
? ''
58+
: envAsString(env['XDG_DATA_HOME']) || (HOME ? `${HOME}/.local/share` : '')
5359
})

0 commit comments

Comments
 (0)