Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(where): allow all paths to be set by env vars #2441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/where/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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`;
Expand Down Expand Up @@ -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`;
Expand Down
32 changes: 32 additions & 0 deletions packages/where/test/where-endo-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Loading