From 3943d39cace65b0a05922ba7b14cca9d4bc0fafa Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Tue, 13 Jul 2021 00:23:22 -0400 Subject: [PATCH] Add shell and encoding options to exec (#29) --- CHANGELOG.md | 15 ++++++++++----- src/Node/ChildProcess.purs | 9 ++++++++- test/Main.purs | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d427d4..4f6a524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Breaking changes: New features: +- Added `shell` and `encoding` options to `exec` functions (#29 by @thomashoneyman) + Bugfixes: Other improvements: @@ -15,11 +17,13 @@ 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 @@ -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`. diff --git a/src/Node/ChildProcess.purs b/src/Node/ChildProcess.purs index dacdc18..310d838 100644 --- a/src/Node/ChildProcess.purs +++ b/src/Node/ChildProcess.purs @@ -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) @@ -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) @@ -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 @@ -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 @@ -358,6 +363,8 @@ defaultExecOptions :: ExecOptions defaultExecOptions = { cwd: Nothing , env: Nothing + , encoding: Nothing + , shell: Nothing , timeout: Nothing , maxBuffer: Nothing , killSignal: Nothing diff --git a/test/Main.purs b/test/Main.purs index 1e409d5..8c34b5d 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -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 ->