Skip to content

Commit 7acf9a9

Browse files
refactor(server): name the login-shell read with Effect.fn
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent efc94ab commit 7acf9a9

1 file changed

Lines changed: 28 additions & 27 deletions

File tree

‎apps/server/src/os-jank.ts‎

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,33 +129,34 @@ export const fixPath = Effect.fn("fixPath")(function* (options?: {
129129
);
130130
});
131131

132-
const readLoginShellOutput = (shell: string) =>
133-
Effect.scoped(
134-
Effect.gen(function* () {
135-
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
136-
const child = yield* spawner.spawn(
137-
ChildProcess.make(
138-
shell,
139-
["-ilc", buildEnvironmentCaptureCommand(shell, LOGIN_SHELL_ENV_NAMES)],
140-
{
141-
stdin: "ignore",
142-
stdout: "pipe",
143-
stderr: "ignore",
144-
// A profile that traps SIGTERM would otherwise hold the scope open
145-
// past the timeout while cleanup waits for the exit.
146-
forceKillAfter: "1 second",
147-
},
148-
),
149-
);
150-
const [stdout, exitCode] = yield* Effect.all(
151-
[Stream.mkString(Stream.decodeText(child.stdout)), child.exitCode],
152-
{ concurrency: 2 },
153-
);
154-
return exitCode === 0 ? stdout : "";
155-
}),
156-
).pipe(
157-
Effect.timeoutOption(LOGIN_SHELL_TIMEOUT),
132+
const readLoginShellOutput = Effect.fn("readLoginShellOutput")(
133+
function* (shell: string) {
134+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
135+
const child = yield* spawner.spawn(
136+
ChildProcess.make(
137+
shell,
138+
["-ilc", buildEnvironmentCaptureCommand(shell, LOGIN_SHELL_ENV_NAMES)],
139+
{
140+
stdin: "ignore",
141+
stdout: "pipe",
142+
stderr: "ignore",
143+
// A profile that traps SIGTERM would otherwise hold the scope open
144+
// past the timeout while cleanup waits for the exit.
145+
forceKillAfter: "1 second",
146+
},
147+
),
148+
);
149+
const [stdout, exitCode] = yield* Effect.all(
150+
[Stream.mkString(Stream.decodeText(child.stdout)), child.exitCode],
151+
{ concurrency: 2 },
152+
);
153+
return exitCode === 0 ? stdout : "";
154+
},
155+
Effect.scoped,
156+
Effect.timeoutOption(LOGIN_SHELL_TIMEOUT),
157+
(effect, shell) =>
158158
Effect.flatMap(
159+
effect,
159160
Option.match({
160161
onSome: Effect.succeed,
161162
onNone: () =>
@@ -164,7 +165,7 @@ const readLoginShellOutput = (shell: string) =>
164165
).pipe(Effect.as("")),
165166
}),
166167
),
167-
);
168+
);
168169

169170
/**
170171
* Re-reads PATH from the login shell so tools installed after startup become

0 commit comments

Comments
 (0)