@procedures/shell 0.3.0 → 0.4.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @procedures/shell
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4c51727: The process registry of `@procedures/shell/command` gives the output of a process after a time. `processes.subscribe(id, { output, end })` calls `output` with each new piece of output and its stream, and `end` with the record at the end of the process. `processes.follow(id, { backlog, signal, maxBufferedBytes })` gives the output as an async stream: the kept output without a gap, the new pieces in UTF-8, a `dropped` item for a slow reader, and an `end` item. The end of the process removes each subscriber, and a follow that ends removes its subscriber.
8
+
9
+ `node.logs` has the option `follow` (short `-f`). With it, the result is a stream: the kept output as `output` lines (`lines` limits them), each new line of stdout and stderr, and an `exit` item at the end of the process. The stream ends at the end of the process, at an abort of the caller and when the reader stops. `node.logs` declares `stream: { unbounded: true }`.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [d919678]
14
+ - Updated dependencies [057d69a]
15
+ - Updated dependencies [b2a1a1e]
16
+ - Updated dependencies [057d69a]
17
+ - Updated dependencies [057d69a]
18
+ - Updated dependencies [057d69a]
19
+ - Updated dependencies [057d69a]
20
+ - Updated dependencies [057d69a]
21
+ - Updated dependencies [afd6a19]
22
+ - Updated dependencies [057d69a]
23
+ - Updated dependencies [4e751da]
24
+ - @procedures/client@0.4.0
25
+
3
26
  ## 0.3.0
4
27
 
5
28
  ### Patch Changes
package/README.md CHANGED
@@ -49,7 +49,7 @@ The wrapper packages start their programs with the helpers of `@procedures/shell
49
49
  |---|---|
50
50
  | `runCommand(command, options)` | It runs a program to its end and gives `exitCode`, `stdout`, `stderr` and `duration`. It does not throw. |
51
51
  | `streamCommand(command, options)` | It gives each output line while the program runs, then an `exit` item. |
52
- | `processes` | It records a long-running program: `start`, `list`, `waitFor`, `output`, `stop`. |
52
+ | `processes` | It records a long-running program: `start`, `list`, `waitFor`, `output`, `subscribe`, `follow`, `stop`. |
53
53
  | `killTree(child)` | It kills a child process and all the processes that it started. |
54
54
 
55
55
  The rules of the helpers:
@@ -67,6 +67,29 @@ import { runCommand } from "@procedures/shell/command";
67
67
  const result = await runCommand("git", { args: ["status", "--porcelain"], cwd, signal: ctx.signal });
68
68
  ```
69
69
 
70
+ #### The output of a recorded process
71
+
72
+ `processes.output(id)` gives the end of the output that the registry keeps: the last 64 KiB. Two functions give the output that comes later:
73
+
74
+ | Function | What it does |
75
+ |---|---|
76
+ | `subscribe(id, { output, end })` | `output` gets each new piece with its stream (`stdout` or `stderr`) and its bytes. `end` gets the record at the end of the process. The result removes the subscriber. |
77
+ | `follow(id, { backlog, signal, maxBufferedBytes })` | It gives an async stream of items: `backlog`, `output`, `dropped` and the last item `end`. |
78
+
79
+ - The end of the process removes each subscriber, so a subscriber of an ended process does not stay.
80
+ - `follow` subscribes when the reader asks for the first item. The end of the process, an abort of `signal` and a reader that stops end the stream and remove its subscriber.
81
+ - With `backlog: true`, the first item has the kept output. The kept output and the new output have no gap between them.
82
+ - `follow` decodes UTF-8 for each stream, so a character in two pieces stays whole.
83
+ - The registry cannot slow the process. When more than `maxBufferedBytes` (1 MiB by default) wait for a slow reader, `follow` drops the oldest pieces and gives a `dropped` item with the number of bytes.
84
+
85
+ ```typescript
86
+ import { processes } from "@procedures/shell/command";
87
+
88
+ for await (const item of processes.follow(id, { backlog: true, signal: ctx.signal })) {
89
+ if (item.type === "output") process.stdout.write(item.text);
90
+ }
91
+ ```
92
+
70
93
  ---
71
94
 
72
95
  ## Installation