Conversation
The JSON branch called process.exit() after writing, which could terminate before a buffered stdout pipe finished flushing, truncating the output when the exit code was non-zero (arethetypeswrong#279, a recurrence of arethetypeswrong#184). - write() now resolves once stdout has actually handled the data (via the write callback) instead of when the source string is exhausted, so it delivers the flush its comment promises. - the JSON branch sets process.exitCode and returns, matching the human-readable branch, rather than calling process.exit(). Adds a regression test for write().
🦋 Changeset detectedLatest commit: 5d03a30 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Reproduced the truncation locally and confirmed the fix. Fixture: a failing package with 17 entrypoints (≈311 KB of Before (base After (this PR): Writing to a file ( The added unit test also fails on the base |
Closes #279 (a recurrence of #184)
--format jsonoutput is truncated when stdout is a pipe and the exit code is non-zero. Two root causes, both fixed here:write()resolved on the sourceReadable'sendevent, not on stdout draining —out.write()'s return value was ignored, so it resolved with bytes still buffered. It now usesout.write(data, callback)and resolves when the chunk is actually handled, delivering the flush its comment promises.process.exit(exitCode), terminating before a buffered pipe finishes flushing. It now setsprocess.exitCodeand returns, matching the human-readable branch (which already worked for exactly this reason).Added a regression test for
write()that fails on the old implementation and passes on the new one. Changeset included (patch).Verified: full cli suite (31 tests, incl. the existing
-f jsonsnapshot) passes; prettier + tsgo clean.Written with AI assistance; I've reviewed and tested the change and will maintain it.