fix(where): Fix XDG conventions
MODIFY
packages/where/index.js
packages/where/index.js
@@ -9,7 +9,7 @@ const { raw } = String;
/**
* @param {{[name: string]: string}} env
*/
-const whereEndoStateWindows = env => {
+const whereEndoHomeWindows = env => {
// Favoring local app data over roaming app data since I don't expect to be
// able to listen on one host and connect on another.
if (env.LOCALAPPDATA !== undefined) {
@@ -24,28 +24,25 @@ const whereEndoStateWindows = env => {
if (env.HOMEDRIVE !== undefined && env.HOMEPATH !== undefined) {
return `${env.HOMEDRIVE}${env.HOMEPATH}\\AppData\\Endo`;
}
- return '.';
+ return 'Endo';
};
/**
* @type {typeof import('./types.js').whereEndoState}
*/
export const whereEndoState = (platform, env) => {
- if (platform === 'win32') {
- return whereEndoStateWindows(env);
+ if (env.XDG_STATE_HOME !== undefined) {
+ return `${env.XDG_STATE_HOME}/endo`;
+ } else if (platform === 'win32') {
+ return whereEndoHomeWindows(env);
} else if (platform === 'darwin') {
if (env.HOME !== undefined) {
return `${env.HOME}/Library/Application Support/Endo`;
}
- } else {
- if (env.XDG_CONFIG_DIR !== undefined) {
- return `${env.XDG_CONFIG_DIR}/endo`;
- }
- if (env.HOME !== undefined) {
- return `${env.HOME}/.config/endo`;
- }
+ } else if (env.HOME !== undefined) {
+ return `${env.HOME}/.local/state/endo`;
}
- return 'endo';
+ return 'endo/state';
};
/**
@@ -59,32 +56,32 @@ export const whereEndoSock = (platform, env) => {
} else {
return raw`\\?\pipe\Endo\endo.pipe`;
}
+ } else if (env.XDG_RUNTIME_DIR !== undefined) {
+ return `${env.XDG_RUNTIME_DIR}/endo/endo.sock`;
} else if (platform === 'darwin') {
if (env.HOME !== undefined) {
return `${env.HOME}/Library/Application Support/Endo/endo.sock`;
}
- } else if (env.XDG_RUNTIME_DIR !== undefined) {
- return `${env.XDG_RUNTIME_DIR}/endo/endo.sock`;
} else if (env.USER !== undefined) {
return `/tmp/endo-${env.USER}/endo.sock`;
}
- return 'endo.sock';
+ return 'endo/endo.sock';
};
/**
* @type {typeof import('./types.js').whereEndoCache}
*/
export const whereEndoCache = (platform, env) => {
- if (platform === 'win32') {
- return `${whereEndoStateWindows(env)}`;
+ if (env.XDG_CACHE_HOME !== undefined) {
+ return `${env.XDG_CACHE_HOME}/endo`;
+ } else if (platform === 'win32') {
+ return `${whereEndoHomeWindows(env)}`;
} else if (platform === 'darwin') {
if (env.HOME !== undefined) {
return `${env.HOME}/Library/Caches/Endo`;
}
- } else if (env.XDG_CACHE_HOME !== undefined) {
- return `${env.XDG_CACHE_HOME}/endo`;
} else if (env.HOME !== undefined) {
return `${env.HOME}/.cache/endo`;
}
- return '';
+ return 'endo/cache';
};

MODIFY
packages/where/test/test-where-endo-cache.js
packages/where/test/test-where-endo-cache.js
@@ -36,7 +36,7 @@ test('windows', t => {
}),
'C:\\Users\\Alice\\AppData\\Endo',
);
- t.is(whereEndoCache('win32', {}), '.');
+ t.is(whereEndoCache('win32', {}), 'Endo');
});
test('darwin', t => {
@@ -46,7 +46,7 @@ test('darwin', t => {
}),
'/Users/alice/Library/Caches/Endo',
);
- t.is(whereEndoCache('darwin', {}), '');
+ t.is(whereEndoCache('darwin', {}), 'endo/cache');
});
test('linux', t => {
@@ -65,5 +65,5 @@ test('linux', t => {
}),
'/Users/alice/.cache/endo',
);
- t.is(whereEndoCache('linux', {}), '');
+ t.is(whereEndoCache('linux', {}), 'endo/cache');
});

MODIFY
packages/where/test/test-where-endo-sock.js
packages/where/test/test-where-endo-sock.js
@@ -4,6 +4,7 @@ import { whereEndoSock } from '../index.js';
test('windows', t => {
t.is(
whereEndoSock('win32', {
+ XDG_RUNTIME_DIR: 'IGNORE_ME',
USERNAME: 'alice',
}),
'\\\\?\\pipe\\alice-Endo\\endo.pipe',
@@ -12,13 +13,20 @@ test('windows', t => {
});
test('darwin', t => {
+ t.is(
+ whereEndoSock('darwin', {
+ XDG_RUNTIME_DIR: '/var/run/user/alice',
+ USER: 'alice',
+ }),
+ '/var/run/user/alice/endo/endo.sock',
+ );
t.is(
whereEndoSock('darwin', {
HOME: '/Users/alice',
}),
'/Users/alice/Library/Application Support/Endo/endo.sock',
);
- t.is(whereEndoSock('darwin', {}), 'endo.sock');
+ t.is(whereEndoSock('darwin', {}), 'endo/endo.sock');
});
test('linux', t => {
@@ -35,5 +43,5 @@ test('linux', t => {
}),
'/tmp/endo-alice/endo.sock',
);
- t.is(whereEndoSock('linux', {}), 'endo.sock');
+ t.is(whereEndoSock('linux', {}), 'endo/endo.sock');
});

MODIFY
packages/where/test/test-where-endo-state.js
packages/where/test/test-where-endo-state.js
@@ -36,7 +36,7 @@ test('windows', t => {
}),
'C:\\Users\\Alice\\AppData\\Endo',
);
- t.is(whereEndoState('win32', {}), '.');
+ t.is(whereEndoState('win32', {}), 'Endo');
});
test('darwin', t => {
@@ -46,22 +46,23 @@ test('darwin', t => {
}),
'/Users/alice/Library/Application Support/Endo',
);
- t.is(whereEndoState('darwin', {}), 'endo');
+ t.is(whereEndoState('darwin', {}), 'endo/state');
});
test('linux', t => {
t.is(
whereEndoState('linux', {
- XDG_CONFIG_DIR: '/Users/alice/.config2',
+ XDG_CONFIG_HOME: '/Users/alice/.config2',
+ XDG_STATE_HOME: '/Users/alice/.local/state',
HOME: '/Users/alice',
}),
- '/Users/alice/.config2/endo',
+ '/Users/alice/.local/state/endo',
);
t.is(
whereEndoState('linux', {
HOME: '/Users/alice',
}),
- '/Users/alice/.config/endo',
+ '/Users/alice/.local/state/endo',
);
- t.is(whereEndoState('linux', {}), 'endo');
+ t.is(whereEndoState('linux', {}), 'endo/state');
});

fix(where): Fix XDG conventions