@reelout/core 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/{HookDispatcher-Di79rwtu.js → HookDispatcher-B_TrMRLU.js} +3 -3
  2. package/dist/{HookDispatcher-Di79rwtu.js.map → HookDispatcher-B_TrMRLU.js.map} +1 -1
  3. package/dist/analyzer.js +4 -4
  4. package/dist/{buildChangelog-Cxm9_lq2.js → buildChangelog-CkytKypk.js} +2 -2
  5. package/dist/{buildChangelog-Cxm9_lq2.js.map → buildChangelog-CkytKypk.js.map} +1 -1
  6. package/dist/{buildReleaseNotes-S6HcEQnE.js → buildReleaseNotes-Dk4bEclG.js} +4 -4
  7. package/dist/{buildReleaseNotes-S6HcEQnE.js.map → buildReleaseNotes-Dk4bEclG.js.map} +1 -1
  8. package/dist/builder.js +3 -3
  9. package/dist/changelog.js +4 -4
  10. package/dist/index.js +104 -20
  11. package/dist/index.js.map +1 -1
  12. package/dist/{package-Bczytil1.js → package-la-hLPRR.js} +2 -2
  13. package/dist/{package-Bczytil1.js.map → package-la-hLPRR.js.map} +1 -1
  14. package/dist/{propagateDependencyUpdates-QWn0H1qa.js → propagateDependencyUpdates-xcPvP5SP.js} +3 -3
  15. package/dist/{propagateDependencyUpdates-QWn0H1qa.js.map → propagateDependencyUpdates-xcPvP5SP.js.map} +1 -1
  16. package/dist/{readPackageHistory-CN5nqMcE.js → readPackageHistory-6dC72rZk.js} +2 -2
  17. package/dist/{readPackageHistory-CN5nqMcE.js.map → readPackageHistory-6dC72rZk.js.map} +1 -1
  18. package/dist/{resolvePackageTag-cwqG1GGt.js → resolvePackageTag-2ldvH7PC.js} +2 -2
  19. package/dist/{resolvePackageTag-cwqG1GGt.js.map → resolvePackageTag-2ldvH7PC.js.map} +1 -1
  20. package/package.json +1 -1
  21. package/src/types.ts +1 -0
  22. package/src/util/captureCommandOutput.ts +140 -0
  23. package/src/util/index.ts +1 -0
  24. package/src/util/isQuietEnvironment.ts +19 -13
@@ -0,0 +1,140 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { Writable } from 'node:stream'
5
+ import type { ReleaseContext } from '../types'
6
+
7
+ /** Maximum bytes of command output kept per stream for failure diagnostics. */
8
+ const MAX_TAIL_BYTES = 64 * 1024
9
+
10
+ /** Wrapping streams that keep a bounded tail of everything written through them. */
11
+ export interface CommandOutputCapture {
12
+ stdout: NodeJS.WritableStream
13
+ stderr: NodeJS.WritableStream
14
+ readStdout(): string
15
+ readDiagnostics(): string
16
+ }
17
+
18
+ /** Options controlling where the captured output is streamed. */
19
+ export interface CaptureCommandOutputOptions {
20
+ pipe: boolean
21
+ }
22
+
23
+ /**
24
+ * Capture command output at the call site, optionally streaming it live.
25
+ *
26
+ * The returned wrappers keep a tail-bounded capture of everything written
27
+ * through them. When `pipe` is set they also forward the output to the
28
+ * context streams, so it keeps flowing live into the terminal or the CI
29
+ * job log; otherwise the output stays inside the capture.
30
+ *
31
+ * @param context Release context carrying the destination streams
32
+ * @param options Whether the captured output is forwarded to the context
33
+ * streams
34
+ * @returns Wrapping streams plus the captured tail readers
35
+ */
36
+ export function captureCommandOutput(
37
+ context: Pick<ReleaseContext, 'stdout' | 'stderr'>,
38
+ options: CaptureCommandOutputOptions
39
+ ): CommandOutputCapture {
40
+ const stdoutTail = new OutputTail()
41
+ const stderrTail = new OutputTail()
42
+
43
+ return {
44
+ stdout: createCapturingStream(
45
+ options.pipe ? context.stdout : undefined,
46
+ stdoutTail
47
+ ),
48
+ stderr: createCapturingStream(
49
+ options.pipe ? context.stderr : undefined,
50
+ stderrTail
51
+ ),
52
+ readStdout: () => stdoutTail.read().trim(),
53
+ readDiagnostics: () => stderrTail.read().trim() || stdoutTail.read().trim(),
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Append captured command output to a failure error message.
59
+ *
60
+ * Command runs that stream through call-site wrappers carry no
61
+ * `execCommand` diagnostics of their own; this appends the captured tail
62
+ * so the publish-rejection classifiers keep reading the command output
63
+ * from the error message.
64
+ *
65
+ * @param cause The error thrown by the command
66
+ * @param capture The capture created for the run
67
+ * @returns The error, with the captured output appended to its message
68
+ */
69
+ export function appendCapturedDiagnostics(
70
+ cause: unknown,
71
+ capture: CommandOutputCapture
72
+ ): unknown {
73
+ const error = cause instanceof Error ? cause : new Error(String(cause))
74
+ const diagnostics = capture.readDiagnostics()
75
+
76
+ if (diagnostics) {
77
+ error.message = `${error.message}\n${diagnostics}`
78
+ }
79
+
80
+ return error
81
+ }
82
+
83
+ class OutputTail {
84
+ private chunks: Buffer[] = []
85
+ private size = 0
86
+
87
+ push(chunk: Buffer): void {
88
+ this.chunks.push(chunk)
89
+ this.size += chunk.length
90
+
91
+ while (this.size > MAX_TAIL_BYTES && this.chunks.length > 1) {
92
+ const head = this.chunks.shift()
93
+
94
+ if (!head) break
95
+
96
+ this.size -= head.length
97
+ }
98
+ }
99
+
100
+ read(): string {
101
+ let buffer: Buffer = Buffer.concat(this.chunks)
102
+
103
+ if (buffer.length > MAX_TAIL_BYTES) {
104
+ buffer = trimUtf8Start(buffer.subarray(buffer.length - MAX_TAIL_BYTES))
105
+ }
106
+
107
+ return buffer.toString('utf-8')
108
+ }
109
+ }
110
+
111
+ function trimUtf8Start(buffer: Buffer): Buffer {
112
+ let start = 0
113
+
114
+ while (start < 3 && start < buffer.length) {
115
+ const byte = buffer[start]
116
+
117
+ if (byte === undefined || (byte & 0xc0) !== 0x80) break
118
+
119
+ start += 1
120
+ }
121
+
122
+ return start === 0 ? buffer : buffer.subarray(start)
123
+ }
124
+
125
+ function createCapturingStream(
126
+ target: NodeJS.WritableStream | undefined,
127
+ tail: OutputTail
128
+ ): Writable {
129
+ return new Writable({
130
+ write(chunk, _encoding, callback) {
131
+ tail.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
132
+
133
+ if (target) {
134
+ target.write(chunk, callback)
135
+ } else {
136
+ callback()
137
+ }
138
+ },
139
+ })
140
+ }
package/src/util/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
4
  export * from './buildTrailerPattern'
5
+ export * from './captureCommandOutput'
5
6
  export * from './compact'
6
7
  export * from './execCommand'
7
8
  export * from './execGit'
@@ -7,27 +7,33 @@ import { isCI } from './isCI'
7
7
  /**
8
8
  * Determine whether the current run should stay quiet about verbose output.
9
9
  *
10
- * A run is quiet when nothing will keep what it prints: no terminal is attached
11
- * for a human, and no CI provider is recording a job log. A plain pipe outside
12
- * of CI — an agent sandbox, a script capturing output, a detached daemon — only
13
- * accumulates noise, so verbose output should be withheld and left to
14
- * `execCommand` for error reporting instead.
10
+ * A run is quiet when its verbose output would only accumulate noise: no
11
+ * terminal is attached for a human to read it live, or the run is inside CI
12
+ * where the provider records a job log that publish noise would pollute.
13
+ * The debug flag opts back in: a debug run is never quiet, not even inside
14
+ * CI, so `--debug` keeps the verbose output flowing. Quiet runs still
15
+ * surface command output on failure — `execCommand` attaches it to the
16
+ * failure diagnostics and captured commands attach their recorded output
17
+ * to the thrown error — so failures stay diagnosable.
15
18
  *
16
- * CI is deliberately *not* quiet even though its streams are not TTYs: the
17
- * provider persists the job log, so the output does reach someone. A caller
18
- * that wants output from a pipe in a non-CI environment can set `CI=1` as an
19
- * escape hatch.
19
+ * CI runs stay quiet even when the provider attaches a pseudo-terminal: the
20
+ * `isCI` check guarantees it on top of the TTY check, so the job log keeps
21
+ * the publish results without the package manager noise.
20
22
  *
21
23
  * The verdict is per environment, not per stream, so a redirected stdout inside
22
24
  * an interactive terminal still counts as quiet.
23
25
  *
24
- * @param context Release context carrying the destination stream and environment
25
- * @returns `true` when no TTY is attached and the run is not part of CI
26
+ * @param context Release context carrying the debug flag, destination
27
+ * stream, and environment
28
+ * @returns `true` when the run is part of CI or no TTY is attached, unless
29
+ * the debug flag is set
26
30
  */
27
31
  export function isQuietEnvironment(
28
- context: Pick<ReleaseContext, 'env' | 'stdout'>
32
+ context: Pick<ReleaseContext, 'debug' | 'env' | 'stdout'>
29
33
  ): boolean {
30
- if (isCI(context.env)) return false
34
+ if (context.debug) return false
35
+
36
+ if (isCI(context.env)) return true
31
37
 
32
38
  const stream = context.stdout as NodeJS.WriteStream | undefined
33
39