Skip to content

Commit cc36915

Browse files
authored
docs: describe $.preferLocal, abort()API and ProcessPromise formatters (#817)
1 parent d8cd974 commit cc36915

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

configuration.md

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ Like a `$.prefix`, but for the end of the command.
3232
$.postfix = '; exit $LastExitCode' // for PowerShell compatibility
3333
```
3434

35+
## $.preferLocal
36+
37+
Specifies whether to prefer `node_modules/.bin` located binaries over globally system installed ones.
38+
39+
```js
40+
$.preferLocal = true
41+
42+
await $`c8 npm test`
43+
```
44+
3545
## $.quote
3646

3747
Specifies a function for escaping special characters during

process-promise.md

+38
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ if (await $`[[ -d path ]]`.exitCode == 0) {
4444
}
4545
```
4646

47+
## `json(), text(), lines(), buffer(), blob()`
48+
49+
Output formatters collection.
50+
51+
```js
52+
const p = $`echo 'foo\nbar'`
53+
54+
await p.text() // foo\n\bar\n
55+
await p.text('hex') // 666f6f0a0861720a
56+
await p.buffer() // Buffer.from('foo\n\bar\n')
57+
await p.lines() // ['foo', 'bar']
58+
await $`echo '{"foo": "bar"}'`.json() // {foo: 'bar'}
59+
```
60+
61+
4762
## `pipe()`
4863

4964
Redirects the stdout of the process.
@@ -92,6 +107,29 @@ setTimeout(() => p.kill('SIGINT'), 100)
92107
await p
93108
```
94109

110+
## `abort()`
111+
112+
Terminates the process via an `AbortController` signal.
113+
114+
```js
115+
const ac = new AbortController()
116+
const {signal} = ac
117+
const p = $({signal})`sleep 999`
118+
119+
setTimeout(() => ac.abort('reason'), 100)
120+
await p
121+
```
122+
123+
If `ac` or `signal` is not provided, it will be autocreated and could be used to control external processes.
124+
125+
```js
126+
const p = $`sleep 999`
127+
const {signal} = p
128+
129+
const res = fetch('https://example.com', {signal})
130+
p.abort('reason')
131+
```
132+
95133
## `stdio()`
96134

97135
Specifies a stdio for the process.

0 commit comments

Comments
 (0)