@procedures/shell 0.3.0 → 0.5.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 +34 -0
- package/README.md +24 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/command/index.d.ts +1 -1
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +1 -1
- package/dist/command/index.js.map +1 -1
- package/dist/command/processes.d.ts +69 -0
- package/dist/command/processes.d.ts.map +1 -1
- package/dist/command/processes.js +129 -7
- package/dist/command/processes.js.map +1 -1
- package/package.json +2 -2
- package/src/command/index.ts +5 -0
- package/src/command/processes.ts +167 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @procedures/shell
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [0f75644]
|
|
8
|
+
- Updated dependencies [09e5566]
|
|
9
|
+
- Updated dependencies [ab77f75]
|
|
10
|
+
- Updated dependencies [a47bee6]
|
|
11
|
+
- Updated dependencies [bc74091]
|
|
12
|
+
- @procedures/client@0.5.0
|
|
13
|
+
|
|
14
|
+
## 0.4.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 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.
|
|
19
|
+
|
|
20
|
+
`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 }`.
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [d919678]
|
|
25
|
+
- Updated dependencies [057d69a]
|
|
26
|
+
- Updated dependencies [b2a1a1e]
|
|
27
|
+
- Updated dependencies [057d69a]
|
|
28
|
+
- Updated dependencies [057d69a]
|
|
29
|
+
- Updated dependencies [057d69a]
|
|
30
|
+
- Updated dependencies [057d69a]
|
|
31
|
+
- Updated dependencies [057d69a]
|
|
32
|
+
- Updated dependencies [afd6a19]
|
|
33
|
+
- Updated dependencies [057d69a]
|
|
34
|
+
- Updated dependencies [4e751da]
|
|
35
|
+
- @procedures/client@0.4.0
|
|
36
|
+
|
|
3
37
|
## 0.3.0
|
|
4
38
|
|
|
5
39
|
### 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
|