Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/adr/0001-leeway.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ shell line with it fails rather than lose its quotes.

**Environment variables are the transport.** They pass through `concurrently`, `tsx`, package scripts and shells to every child process
with no integration. `leeway` runs the command through the system shell: one argument is a shell line, several are an argv quoted for
the shell. Stopping leeway stops the tree: on POSIX the command gets its own process group and SIGINT, SIGTERM and SIGHUP are forwarded to
it; on Windows, which has no process groups to signal, Ctrl+C, Ctrl+Break and console close run `taskkill /T /F`.
the shell. Stopping leeway stops the tree: on POSIX the command gets its own process group and SIGINT, SIGTERM, SIGHUP and SIGQUIT are
forwarded to it; on Windows, which has no process groups to signal, Ctrl+C, Ctrl+Break and console close run `taskkill /T /F`.

**Browser and vite.** `devPorts` is browser-safe. `leeway/vite` sets `server.port` and `preview.port` with `strictPort`, so a taken port
fails instead of drifting. `preview.port` uses the dev server's port name unless `preview` names another: left alone, vite previews on
Expand Down
6 changes: 5 additions & 1 deletion packages/leeway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ folder still claims its own range, and an explicit `--default` or `--inherit` ke
- The command runs through the system shell (`sh`, `cmd.exe` on Windows).
- leeway exits with the shell's exit code (a missing command: 127 from `sh`, 1 from `cmd.exe`; a command killed by a signal: usually
128 plus the signal number from `sh`), or 1 if the shell itself died from a signal or could not start.
- Stopping leeway (Ctrl+C, a signal, closing the terminal) stops the whole command tree.
- Stopping leeway stops the whole command tree: Ctrl+C, `Ctrl+\`, closing the terminal, or SIGINT, SIGTERM, SIGHUP
or SIGQUIT on Linux and macOS; Ctrl+C, Ctrl+Break or closing the console on Windows. On Linux and macOS the tree gets the signal
leeway got, so a command that handles it and keeps running is not stopped ([Limits](#limits)).

`leeway --help` (or `-h`) prints the usage, `leeway --version` the version.

Expand Down Expand Up @@ -492,6 +494,8 @@ eval "$(npx leeway env --export)"
it still reads keys from stdin, but tools that open `/dev/tty` directly (some password prompts, full-screen TUIs) fail.
- Ctrl+Z on Linux and macOS suspends `leeway` alone: the command, in its own session, keeps running on its ports. `fg`, then Ctrl+C,
stops it.
- On Linux and macOS a command that handles a signal and keeps running can outlive `leeway` and stay on its ports: a JVM prints a
thread dump on `Ctrl+\` and carries on, while the `sh` above it dies and `leeway` exits. `leeway kill` stops it.
- `nohup leeway <command>` doesn't outlive the terminal: `leeway` still gets the hangup and stops the command tree. In bash or zsh, use
`leeway <command> > leeway.log 2>&1 & disown` instead.
- On Windows, Ctrl+C force-kills the command tree at once, so a command that cleans up on Ctrl+C may die before it finishes. Run such a
Expand Down
2 changes: 1 addition & 1 deletion packages/leeway/src/os/run-with-ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ProcessTree } from "./process-tree.ts";

const WINDOWS_STOP_SIGNALS: NodeJS.Signals[] = ["SIGINT", "SIGBREAK", "SIGHUP"];

const POSIX_FORWARDED_SIGNALS: NodeJS.Signals[] = ["SIGINT", "SIGTERM", "SIGHUP"];
const POSIX_FORWARDED_SIGNALS: NodeJS.Signals[] = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];

export class RunWithPorts {
static runAndExit(commandLine: string, env: Record<string, string | number>): void {
Expand Down
29 changes: 16 additions & 13 deletions packages/leeway/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,22 @@ describe("leeway errors", () => {
});

describe.skipIf(process.platform === "win32")("leeway <command> on a signal", () => {
it.each(["SIGINT", "SIGTERM", "SIGHUP"] as const)("%s stops the whole command tree, so nothing is left listening", async signal => {
const { dir, home } = temporaryFolder();
const leeway = startLeeway(["node", "launcher.mjs"], dir, home);
const port = await listeningPort(leeway);
const exitCode = new Promise(resolve => leeway.once("exit", resolve));

expect(await answers(port)).toBe(true);

leeway.kill(signal);

expect(await exitCode).not.toBe(0);
expect(await stopsAnswering(port)).toBe(true);
});
it.each(["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"] as const)(
"%s stops the whole command tree, so nothing is left listening",
async signal => {
const { dir, home } = temporaryFolder();
const leeway = startLeeway(["node", "launcher.mjs"], dir, home);
const port = await listeningPort(leeway);
const exitCode = new Promise(resolve => leeway.once("exit", resolve));

expect(await answers(port)).toBe(true);

leeway.kill(signal);

expect(await exitCode).not.toBe(0);
expect(await stopsAnswering(port)).toBe(true);
},
);
});

describe.runIf(process.platform === "win32")("leeway <command> on Ctrl+C in its console", () => {
Expand Down
Loading