(o: TunnelOpts)
| 24 | |
| 25 | /** Build the `ssh` argv for a no-shell local port-forward with keepalive. PURE. */ |
| 26 | export function buildTunnelArgs(o: TunnelOpts): string[] { |
| 27 | const args = [ |
| 28 | '-N', // no remote command — forward only |
| 29 | '-o', 'ServerAliveInterval=30', // keep the tunnel from idling out |
| 30 | '-o', 'ExitOnForwardFailure=yes', // fail fast if the local port is taken |
| 31 | '-L', `${o.localPort}:localhost:${o.remotePort}`, |
| 32 | ]; |
| 33 | if (o.port) args.push('-p', String(o.port)); |
| 34 | if (o.identityFile) args.push('-i', o.identityFile); |
| 35 | args.push(`${o.user ? `${o.user}@` : ''}${o.host}`); |
| 36 | return args; |
| 37 | } |
| 38 | |
| 39 | /** Open the tunnel; resolves with a `close()` once ssh is spawned. Rejects if ssh exits early. */ |
| 40 | export async function openTunnel(o: TunnelOpts): Promise<{ close: () => void }> { |
no test coverage detected