From fac13aa14a9f5b03992b0910a602b59719a7e0c6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 30 Aug 2024 10:56:21 -1000 Subject: [PATCH] feat(where): allow all paths to be set by env vars --- packages/where/index.js | 12 ++++++-- packages/where/test/where-endo-state.test.js | 32 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/where/index.js b/packages/where/index.js index b45649e107..d776def4d1 100644 --- a/packages/where/index.js +++ b/packages/where/index.js @@ -38,7 +38,9 @@ const whereHomeWindows = (env, info) => { * @type {typeof import('./types.js').whereEndoState} */ export const whereEndoState = (platform, env, info) => { - if (env.XDG_STATE_HOME !== undefined) { + if (env.ENDO_STATE !== undefined) { + return env.ENDO_STATE; + } else if (env.XDG_STATE_HOME !== undefined) { return `${env.XDG_STATE_HOME}/endo`; } else if (platform === 'win32') { return `${whereHomeWindows(env, info)}\\Endo`; @@ -59,7 +61,9 @@ export const whereEndoState = (platform, env, info) => { * @type {typeof import('./types.js').whereEndoEphemeralState} */ export const whereEndoEphemeralState = (platform, env, info) => { - if (env.XDG_RUNTIME_DIR !== undefined) { + if (env.ENDO_TEMP_STATE !== undefined) { + return env.ENDO_TEMP_STATE; + } else if (env.XDG_RUNTIME_DIR !== undefined) { return `${env.XDG_RUNTIME_DIR}/endo`; } else if (platform === 'win32') { return `${whereHomeWindows(env, info)}\\Temp\\Endo`; @@ -102,7 +106,9 @@ export const whereEndoSock = (platform, env, info, protocol = 'captp0') => { * @type {typeof import('./types.js').whereEndoCache} */ export const whereEndoCache = (platform, env, info) => { - if (env.XDG_CACHE_HOME !== undefined) { + if (env.ENDO_CACHE !== undefined) { + return env.ENDO_CACHE; + } else if (env.XDG_CACHE_HOME !== undefined) { return `${env.XDG_CACHE_HOME}/endo`; } else if (platform === 'win32') { return `${whereHomeWindows(env, info)}\\Endo`; diff --git a/packages/where/test/where-endo-state.test.js b/packages/where/test/where-endo-state.test.js index 4c16c71592..b637a1a121 100644 --- a/packages/where/test/where-endo-state.test.js +++ b/packages/where/test/where-endo-state.test.js @@ -2,6 +2,18 @@ import test from 'ava'; import { whereEndoState } from '../index.js'; test('windows', t => { + t.is( + whereEndoState('win32', { + ENDO_STATE: 'C:\\Users\\Alice\\AppData\\Local\\Endo', + LOCALAPPDATA: 'IGNOREME', + APPDATA: 'IGNOREME', + USERPROFILE: 'IGNOREME', + HOMEDRIVE: 'IGNOREME', + HOMEPATH: 'IGNOREME', + }), + 'C:\\Users\\Alice\\AppData\\Local\\Endo', + 'Favor Endo env var state home if provided by the user', + ); t.is( whereEndoState('win32', { LOCALAPPDATA: 'C:\\Users\\Alice\\AppData\\Local', @@ -54,6 +66,16 @@ test('windows', t => { }); test('darwin', t => { + t.is( + whereEndoState('darwin', { + ENDO_STATE: '/Users/alice/.local/state/endo', + XDG_STATE_HOME: 'IGNOREME', + XDG_CONFIG_HOME: 'IGNOREME', + HOME: 'IGNOREME', + }), + '/Users/alice/.local/state/endo', + 'Favor Endo env var state home if provided by the user', + ); t.is( whereEndoState('darwin', { XDG_STATE_HOME: '/Users/alice/.local/state', @@ -84,6 +106,16 @@ test('darwin', t => { }); test('linux', t => { + t.is( + whereEndoState('linux', { + ENDO_STATE: '/Users/alice/.local/state/endo', + XDG_STATE_HOME: 'IGNOREME', + XDG_CONFIG_HOME: 'IGNOREME', + HOME: 'IGNOREME', + }), + '/Users/alice/.local/state/endo', + 'Favor Endo env var state home if provided by the user', + ); t.is( whereEndoState('linux', { XDG_STATE_HOME: '/Users/alice/.local/state',