Commit 60101c5
fix(node): split CLI streaming from library API to prevent stdout double-write (#473)
Objective: CLI users without --quiet see every output line printed twice.
The earlier streaming-flag-on-the-Promise approach (d6cded2 / 7e750d2)
fixed CLI behavior at the cost of a library API regression — convert(),
when called with quiet undefined, returned an empty string instead of
the real stdout.
Approach: Separate concerns at the layer boundary.
- convert() (library API) is pinned to streamOutput: false. It always
returns the full stdout string and never touches the parent process's
stdio. No quiet-dependent return shape, no surprise side-effects.
- _runForCli() (internal helper, used only by the bundled CLI) is
pinned to streamOutput: true. It forwards Java's stdout and stderr
to the parent process in real time and resolves to void — so the
CLI cannot re-print what was already streamed.
- cli.ts now calls _runForCli() and never touches the resolved value,
closing the double-write loop at the source.
This keeps Java's progress logs flowing in real time on stderr — the
property that makes long hybrid runs observable — while the result text
streams once on stdout.
Evidence: Added a deterministic mock-based unit suite
(executeJar.unit.test.ts, 9 tests) and a real-jar integration suite
(streaming.integration.test.ts, 3 tests). Manual verification on the
bundled CLI:
| Scenario | Expected | Actual |
|-----------------------------------------|--------------------------------|-------------------------------------------------|
| CLI, no --quiet, --to-stdout (1 page) | 459 bytes (single copy) | 459 bytes |
| CLI, no --quiet, --to-stdout (14 pages) | 63006 bytes (single copy) | 63006 bytes |
| 14-page CLI: stderr progress logs | streamed before stdout | confirmed (28 lines, "Number of pages" present) |
| Library: convert(quiet:true) returns | full stdout string | 459 bytes |
| Library: convert(quiet:undef) returns | full stdout string | 459 bytes |
| Library: process.stdout side-effect | none | none |
| Library: process.stderr side-effect | none | none |
vitest: 30/30 pass.
Fixes #398
Co-authored-by: kuishou68 <54054995+kuishou68@users.noreply.github.com>1 parent 07d0bdc commit 60101c5
5 files changed
Lines changed: 533 additions & 23 deletions
File tree
- node/opendataloader-pdf
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
66 | 62 | | |
67 | 63 | | |
68 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | 26 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
43 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
44 | 60 | | |
| 61 | + | |
| 62 | + | |
45 | 63 | | |
46 | | - | |
47 | 64 | | |
48 | 65 | | |
49 | | - | |
50 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
51 | 69 | | |
52 | 70 | | |
53 | 71 | | |
| 72 | + | |
| 73 | + | |
54 | 74 | | |
55 | 75 | | |
56 | 76 | | |
57 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
58 | 95 | | |
59 | 96 | | |
60 | 97 | | |
| |||
80 | 117 | | |
81 | 118 | | |
82 | 119 | | |
83 | | - | |
| 120 | + | |
84 | 121 | | |
85 | | - | |
86 | | - | |
| 122 | + | |
| 123 | + | |
87 | 124 | | |
88 | 125 | | |
89 | | - | |
| 126 | + | |
90 | 127 | | |
91 | 128 | | |
92 | 129 | | |
93 | 130 | | |
94 | | - | |
| 131 | + | |
95 | 132 | | |
96 | 133 | | |
97 | 134 | | |
98 | | - | |
| 135 | + | |
| 136 | + | |
99 | 137 | | |
100 | | - | |
101 | | - | |
102 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
103 | 172 | | |
104 | 173 | | |
105 | 174 | | |
| |||
0 commit comments