Skip to content

Commit

Permalink
feat: also support absolute socket and full pipe paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Mastercuber committed Sep 17, 2023
1 parent 8d1de7b commit 63c0f57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/_utils.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 63c0f57

Please sign in to comment.