Skip to content

Commit

Permalink
docs: describe $.preferLocal, abort()API and ProcessPromise for…
Browse files Browse the repository at this point in the history
…matters (#817)
  • Loading branch information
antongolub authored May 21, 2024
1 parent d8cd974 commit cc36915
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ Like a `$.prefix`, but for the end of the command.
$.postfix = '; exit $LastExitCode' // for PowerShell compatibility
```

## $.preferLocal

Specifies whether to prefer `node_modules/.bin` located binaries over globally system installed ones.

```js
$.preferLocal = true

await $`c8 npm test`
```

## $.quote

Specifies a function for escaping special characters during
Expand Down
38 changes: 38 additions & 0 deletions process-promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ if (await $`[[ -d path ]]`.exitCode == 0) {
}
```

## `json(), text(), lines(), buffer(), blob()`

Output formatters collection.

```js
const p = $`echo 'foo\nbar'`

await p.text() // foo\n\bar\n
await p.text('hex') // 666f6f0a0861720a
await p.buffer() // Buffer.from('foo\n\bar\n')
await p.lines() // ['foo', 'bar']
await $`echo '{"foo": "bar"}'`.json() // {foo: 'bar'}
```


## `pipe()`

Redirects the stdout of the process.
Expand Down Expand Up @@ -92,6 +107,29 @@ setTimeout(() => p.kill('SIGINT'), 100)
await p
```

## `abort()`

Terminates the process via an `AbortController` signal.

```js
const ac = new AbortController()
const {signal} = ac
const p = $({signal})`sleep 999`

setTimeout(() => ac.abort('reason'), 100)
await p
```

If `ac` or `signal` is not provided, it will be autocreated and could be used to control external processes.

```js
const p = $`sleep 999`
const {signal} = p

const res = fetch('https://example.com', {signal})
p.abort('reason')
```

## `stdio()`

Specifies a stdio for the process.
Expand Down

0 comments on commit cc36915

Please sign in to comment.