Showing the changes to scripts/dev-runner.ts (1 of 11 files). Show all
Unified · Split
| @@ -9,11 +9,12 @@ import { Config, Data, Effect, Hash, Layer, Logger, Option, Path, Schema } from · 8 unmodified lines | |||
| 9 | import { Argument, Command, Flag } from "effect/unstable/cli"; | 9 | import { Argument, Command, Flag } from "effect/unstable/cli"; |
| 10 | import { ChildProcess } from "effect/unstable/process"; | 10 | import { ChildProcess } from "effect/unstable/process"; |
| 11 | 11 | ||
| 12 | const BASE_SERVER_PORT = 3773; | 12 | const BASE_SERVER_PORT = 13773; |
| 13 | const BASE_WEB_PORT = 5733; | 13 | const BASE_WEB_PORT = 5733; |
| 14 | const MAX_HASH_OFFSET = 3000; | 14 | const MAX_HASH_OFFSET = 3000; |
| 15 | const MAX_PORT = 65535; | 15 | const MAX_PORT = 65535; |
| 16 | const DESKTOP_DEV_LOOPBACK_HOST = "127.0.0.1"; | 16 | const DESKTOP_DEV_LOOPBACK_HOST = "127.0.0.1"; |
| 17 | const DEV_PORT_PROBE_HOSTS = ["127.0.0.1", "0.0.0.0", "::1", "::"] as const; | ||
| 17 | 18 | ||
| 18 | export const DEFAULT_T3_HOME = Effect.map(Effect.service(Path.Path), (path) => | 19 | export const DEFAULT_T3_HOME = Effect.map(Effect.service(Path.Path), (path) => |
| 19 | path.join(homedir(), ".t3"), | 20 | path.join(homedir(), ".t3"), |
| @@ -221,10 +222,28 @@ function portPairForOffset(offset: number): { · 201 unmodified lines | |||
| 221 | }; | 222 | }; |
| 222 | } | 223 | } |
| 223 | 224 | ||
| 225 | export function checkPortAvailabilityOnHosts<R>( | ||
| 226 | port: number, | ||
| 227 | hosts: ReadonlyArray<string>, | ||
| 228 | canListenOnHost: (port: number, host: string) => Effect.Effect<boolean, never, R>, | ||
| 229 | ): Effect.Effect<boolean, never, R> { | ||
| 230 | return Effect.gen(function* () { | ||
| 231 | for (const host of hosts) { | ||
| 232 | if (!(yield* canListenOnHost(port, host))) { | ||
| 233 | return false; | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | return true; | ||
| 238 | }); | ||
| 239 | } | ||
| 240 | |||
| 224 | const defaultCheckPortAvailability: PortAvailabilityCheck<NetService> = (port) => | 241 | const defaultCheckPortAvailability: PortAvailabilityCheck<NetService> = (port) => |
| 225 | Effect.gen(function* () { | 242 | Effect.gen(function* () { |
| 226 | const net = yield* NetService; | 243 | const net = yield* NetService; |
| 227 | return yield* net.isPortAvailableOnLoopback(port); | 244 | return yield* checkPortAvailabilityOnHosts(port, DEV_PORT_PROBE_HOSTS, (candidatePort, host) => |
| 245 | net.canListenOnHost(candidatePort, host), | ||
| 246 | ); | ||
| 228 | }); | 247 | }); |
| 229 | 248 | ||
| 230 | interface FindFirstAvailableOffsetInput<R = NetService> { | 249 | interface FindFirstAvailableOffsetInput<R = NetService> { |