Skip to content

Add shell and encoding options to exec #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ Breaking changes:

New features:

- Added `shell` and `encoding` options to `exec` functions (#29 by @thomashoneyman)

Bugfixes:

Other improvements:

## [v7.0.0](https://github.com/purescript-node/purescript-node-child-process/releases/tag/v7.0.0) - 2021-02-26

Breaking changes:
- Updated dependencies for PureScript 0.14 (#25)


- Updated dependencies for PureScript 0.14 (#25)

Other improvements:
- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#24)
- Added a CHANGELOG.md file and pull request template (#26)

- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#24)
- Added a CHANGELOG.md file and pull request template (#26)

## [v6.0.0](https://github.com/purescript-node/purescript-node-child-process/releases/tag/v6.0.0) - 2019-03-15

Expand Down Expand Up @@ -83,8 +87,9 @@ Other improvements:
## [v0.4.0](https://github.com/purescript-node/purescript-node-child-process/releases/tag/v0.4.0) - 2015-12-29

- **Breaking change**:

- `SpawnOptions` now uses the `Uid` and `Gid` types from `purescript-posix-types` for its `uid` and `gid` options, instead of `Int`.

- **New features**:
- Added `exec`.

Expand Down
9 changes: 8 additions & 1 deletion src/Node/ChildProcess.purs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import Prelude

import Control.Alt ((<|>))
import Data.Function.Uncurried (Fn2, runFn2)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Nullable (Nullable, toNullable, toMaybe)
import Data.Posix (Pid, Gid, Uid)
import Data.Posix.Signal (Signal)
Expand All @@ -64,6 +64,7 @@ import Effect.Exception.Unsafe (unsafeThrow)
import Foreign (Foreign)
import Foreign.Object (Object)
import Node.Buffer (Buffer)
import Node.Encoding (Encoding, encodingToNode)
import Node.FS as FS
import Node.Stream (Readable, Writable, Stream)
import Unsafe.Coerce (unsafeCoerce)
Expand Down Expand Up @@ -334,6 +335,8 @@ convertExecOptions :: ExecOptions -> ActualExecOptions
convertExecOptions opts = unsafeCoerce
{ cwd: fromMaybe undefined opts.cwd
, env: fromMaybe undefined opts.env
, encoding: maybe undefined encodingToNode opts.encoding
, shell: fromMaybe undefined opts.shell
, timeout: fromMaybe undefined opts.timeout
, maxBuffer: fromMaybe undefined opts.maxBuffer
, killSignal: fromMaybe undefined opts.killSignal
Expand All @@ -346,6 +349,8 @@ convertExecOptions opts = unsafeCoerce
type ExecOptions =
{ cwd :: Maybe String
, env :: Maybe (Object String)
, encoding :: Maybe Encoding
, shell :: Maybe String
, timeout :: Maybe Number
, maxBuffer :: Maybe Int
, killSignal :: Maybe Signal
Expand All @@ -358,6 +363,8 @@ defaultExecOptions :: ExecOptions
defaultExecOptions =
{ cwd: Nothing
, env: Nothing
, encoding: Nothing
, shell: Nothing
, timeout: Nothing
, maxBuffer: Nothing
, killSignal: Nothing
Expand Down
2 changes: 1 addition & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ main = do

log "doesn't perform effects too early"
spawn "ls" ["-la"] defaultSpawnOptions >>= \ls -> do
let unused = kill SIGTERM ls
let _ = kill SIGTERM ls
onExit ls \exit ->
case exit of
Normally 0 ->
Expand Down