From 63c0f579b637ada23fc2d0974f0810d02ae315ec Mon Sep 17 00:00:00 2001 From: Armin Kunkel Date: Sun, 10 Sep 2023 01:26:29 +0200 Subject: [PATCH] feat: also support absolute socket and full pipe paths --- src/_utils.ts | 9 ++++++--- src/cli.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/_utils.ts b/src/_utils.ts index 07c7d6e..d4e2131 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -1,5 +1,5 @@ import { networkInterfaces, platform, tmpdir } from "node:os"; -import { relative, join } from "pathe"; +import { relative, join, isAbsolute } from "pathe"; import { colors } from "consola/utils"; import { consola } from "consola"; import { provider } from "std-env"; @@ -85,11 +85,14 @@ export function getDefaultHost(preferPublic?: boolean) { } export function getSocketPath(name: true | string) { - const _name = typeof name === "string" ? name : "listhen"; + const _name = typeof name === "string" && name.length > 0 ? name : "listhen"; if (platform() === "win32") { + if (_name.startsWith("\\\\?\\pipe\\")) { + return _name; + } return `\\\\?\\pipe\\${_name}`; } - return join(tmpdir(), `${_name}.socket`); + return isAbsolute(_name) ? _name : join(tmpdir(), `${_name}.socket`); } export function getPublicURL( diff --git a/src/cli.ts b/src/cli.ts index 5adb553..334a3d3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -138,7 +138,7 @@ export function getArgs() { }, socket: { description: - "Listen on a Unix Domain Socket/Windows Pipe, optionally with custom name", + "Listen on a Unix Domain Socket/Windows Pipe, optionally with custom name or given absolute path", required: false, }, } as const satisfies ArgsDef;