feat(where): Distinguish protocol in socket or pipe name
MODIFY
packages/where/index.js
packages/where/index.js
// @ts-check
-const { raw } = String;
-
/**
* Returns a path for local Endo application user data on Windows.
*
@@ -87,24 +85,24 @@ export const whereEndoEphemeralState = (platform, env) => {
*
* @type {typeof import('./types.js').whereEndoSock}
*/
-export const whereEndoSock = (platform, env) => {
+export const whereEndoSock = (platform, env, protocol = 'captp0') => {
if (platform === 'win32') {
// Named pipes have a special place in Windows (and in our ashen hearts).
if (env.USERNAME !== undefined) {
- return `\\\\?\\pipe\\${env.USERNAME}-Endo\\endo.pipe`;
+ return `\\\\?\\pipe\\${env.USERNAME}-Endo\\${protocol}.pipe`;
} else {
- return raw`\\?\pipe\Endo\endo.pipe`;
+ return `\\\\?\\pipe\\Endo\\${protocol}.pipe`;
}
} else if (env.XDG_RUNTIME_DIR !== undefined) {
- return `${env.XDG_RUNTIME_DIR}/endo/endo.sock`;
+ return `${env.XDG_RUNTIME_DIR}/endo/${protocol}.sock`;
} else if (platform === 'darwin') {
if (env.HOME !== undefined) {
- return `${env.HOME}/Library/Application Support/Endo/endo.sock`;
+ return `${env.HOME}/Library/Application Support/Endo/${protocol}.sock`;
}
} else if (env.USER !== undefined) {
- return `/tmp/endo-${env.USER}/endo.sock`;
+ return `/tmp/endo-${env.USER}/${protocol}.sock`;
}
- return 'endo/endo.sock';
+ return `endo/${protocol}.sock`;
};
/**

MODIFY
packages/where/test/test-where-endo-sock.js
packages/where/test/test-where-endo-sock.js
@@ -7,12 +7,12 @@ test('windows', t => {
XDG_RUNTIME_DIR: 'IGNOREME', // Not necessarily suitable for named pipes
USERNAME: 'alice',
}),
- '\\\\?\\pipe\\alice-Endo\\endo.pipe',
+ '\\\\?\\pipe\\alice-Endo\\captp0.pipe',
'Use Windows named pipe namespace, scoped to the user when possible',
);
t.is(
whereEndoSock('win32', {}),
- '\\\\?\\pipe\\Endo\\endo.pipe',
+ '\\\\?\\pipe\\Endo\\captp0.pipe',
'Under duress, fall back to a location shared by all users',
);
});
@@ -23,19 +23,19 @@ test('darwin', t => {
XDG_RUNTIME_DIR: '/var/run/user/alice',
USER: 'IGNOREME',
}),
- '/var/run/user/alice/endo/endo.sock',
+ '/var/run/user/alice/endo/captp0.sock',
'Favor XDG over local conventions, even on a Mac',
);
t.is(
whereEndoSock('darwin', {
HOME: '/Users/alice',
}),
- '/Users/alice/Library/Application Support/Endo/endo.sock',
+ '/Users/alice/Library/Application Support/Endo/captp0.sock',
'Infer Darwin/Mac conventional socket location from HOME',
);
t.is(
whereEndoSock('darwin', {}),
- 'endo/endo.sock',
+ 'endo/captp0.sock',
'Under duress, fall through to a relative path',
);
});
@@ -46,19 +46,19 @@ test('linux', t => {
XDG_RUNTIME_DIR: '/var/run/user/alice',
USER: 'IGNOREME',
}),
- '/var/run/user/alice/endo/endo.sock',
+ '/var/run/user/alice/endo/captp0.sock',
'XDG takes precedence over USER on Linux',
);
t.is(
whereEndoSock('linux', {
USER: 'alice',
}),
- '/tmp/endo-alice/endo.sock',
+ '/tmp/endo-alice/captp0.sock',
'Under duress, assume the host has a /tmp file system and scope the UNIX domain socket to the user by name',
);
t.is(
whereEndoSock('linux', {}),
- 'endo/endo.sock',
+ 'endo/captp0.sock',
'Under extreme duress, just use a relative path for the socket',
);
});

feat(where): Distinguish protocol in socket or pipe name