Commit 79eedf7
committed
fix(inquirerer): defer process.stdin/stdout access in defaultCLIOptions
Evaluating `input: process.stdin` / `output: process.stdout` as plain
properties on the `defaultCLIOptions` object literal meant those streams
were constructed at module-load time, not when a `CLI` was actually
instantiated.
`process.stdin` and `process.stdout` are lazy getters on the process
object that materialise Readable/Writable streams on first access. When
fd 0 is a pipe (Jest workers, spawned children, backgrounded processes),
constructing stdin registers a libuv PIPEWRAP handle that the runtime
must close before exit. As a result, any library that transitively
required `inquirerer` (e.g. pgsql-test -> pgsql-client -> @pgpmjs/core
-> genomic -> inquirerer) would open stdin as a pure import side-effect
and trigger false positives under `jest --detectOpenHandles`.
Convert the two fields to accessor properties so the stream references
are only evaluated when someone reads them (i.e. when `new CLI(...)`
actually runs). No behavioural change for direct CLI consumers; the
fields still return `process.stdin` / `process.stdout` on read.
Add a regression test that (1) asserts the descriptors are getters and
(2) spawns a fresh Node process with piped stdin, requires the built
package, and verifies no Socket/WriteStream handles remain active.1 parent b1d40ce commit 79eedf7
2 files changed
Lines changed: 74 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
22 | | - | |
23 | | - | |
| 32 | + | |
| 33 | + | |
24 | 34 | | |
25 | 35 | | |
26 | 36 | | |
| |||
0 commit comments