* Sends a spawn request, at most once. A proxy process that is no longer * ready to take spawns, or whose credentials are out of date, fails the * spawn without sending it, so every command it holds has been sent.
(
command: string,
args: ReadonlyArray<string>,
options: NodeChildProcess.SpawnOptions,
halfOpen: ReadonlyArray<number>
)
| 268 | * spawn without sending it, so every command it holds has been sent. |
| 269 | */ |
| 270 | spawn( |
| 271 | command: string, |
| 272 | args: ReadonlyArray<string>, |
| 273 | options: NodeChildProcess.SpawnOptions, |
| 274 | halfOpen: ReadonlyArray<number> |
| 275 | ): ProxiedProcess { |
| 276 | if (!this.ready || this.exited || this.retired || this.credentials !== credentials()) { |
| 277 | const refused = new ProxiedProcess(noOwner, 0, []) |
| 278 | const error = new Error("The proxy process stopped taking spawns before the command was sent to it") |
| 279 | globalThis.process.nextTick(() => refused.onError(error)) |
| 280 | return refused |
| 281 | } |
| 282 | const id = this.nextId |
| 283 | this.nextId = (this.nextId + 1) % 0x1_0000_0000 |
| 284 | const stdio = (options.stdio as ReadonlyArray<NodeChildProcess.IOType | undefined>).map((mode) => |
| 285 | mode === undefined || mode === "overlapped" ? "pipe" : mode |
| 286 | ) |
| 287 | const child = new ProxiedProcess(this, id, stdio.map((mode) => mode === "pipe"), halfOpen) |
| 288 | this.commands.set(id, child) |
| 289 | this.startTimer(id) |
| 290 | this.send({ |
| 291 | id, |
| 292 | command, |
| 293 | args, |
| 294 | options: { |
| 295 | cwd: options.cwd ?? globalThis.process.cwd(), |
| 296 | env: options.env ?? globalThis.process.env, |
| 297 | detached: options.detached, |
| 298 | shell: options.shell, |
| 299 | windowsHide: options.windowsHide, |
| 300 | stdio |
| 301 | } |
| 302 | }) |
| 303 | return child |
| 304 | } |
| 305 | |
| 306 | ref(): void { |
| 307 | this.refs++ |
no test coverage detected