Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

hostProcess.ts

62 lines1.7 KB

1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as NodeOS from "node:os";
4​
5export const HostProcessPlatform = Context.Reference<NodeJS.Platform>(
6 "@t3tools/shared/hostProcess/HostProcessPlatform",
7 {
8 defaultValue: () => process.platform,
9 },
10);
11​
12export const HostProcessArchitecture = Context.Reference<NodeJS.Architecture>(
13 "@t3tools/shared/hostProcess/HostProcessArchitecture",
14 {
15 defaultValue: () => process.arch,
16 },
17);
18​
19export const HostProcessHostname = Context.Reference<string>(
20 "@t3tools/shared/hostProcess/HostProcessHostname",
21 {
22 defaultValue: () => NodeOS.hostname(),
23 },
24);
25​
26export const HostProcessEnvironment = Context.Reference<NodeJS.ProcessEnv>(
27 "@t3tools/shared/hostProcess/HostProcessEnvironment",
28 {
29 defaultValue: () => process.env,
30 },
31);
32​
33export const HostProcessWorkingDirectory = Context.Reference<string>(
34 "@t3tools/shared/hostProcess/HostProcessWorkingDirectory",
35 {
36 defaultValue: () => process.cwd(),
37 },
38);
39​
40export const HostProcessExecutablePath = Context.Reference<string>(
41 "@t3tools/shared/hostProcess/HostProcessExecutablePath",
42 {
43 defaultValue: () => process.execPath,
44 },
45);
46​
47export const HostProcessArguments = Context.Reference<ReadonlyArray<string>>(
48 "@t3tools/shared/hostProcess/HostProcessArguments",
49 {
50 defaultValue: () => process.argv,
51 },
52);
53​
54/** Undefined on platforms without POSIX uids (Windows). */
55export const HostProcessUserId = Context.Reference<number | undefined>(
56 "@t3tools/shared/hostProcess/HostProcessUserId",
57 {
58 defaultValue: () => process.getuid?.(),
59 },
60);
61​
62export const isHostWindows = Effect.map(HostProcessPlatform, (platform) => platform === "win32");