1313module Node.ChildProcess
1414 ( Handle
1515 , ChildProcess
16- , CHILD_PROCESS
1716 , stderr
1817 , stdout
1918 , stdin
@@ -48,18 +47,19 @@ module Node.ChildProcess
4847import Prelude
4948
5049import Control.Alt ((<|>))
51- import Control.Monad.Eff ( kind Effect , Eff )
52- import Control.Monad.Eff .Exception as Exception
53- import Control.Monad.Eff .Exception.Unsafe (unsafeThrow )
50+ import Effect ( Effect )
51+ import Effect .Exception as Exception
52+ import Effect .Exception.Unsafe (unsafeThrow )
5453
55- import Data.Foreign (Foreign )
5654import Data.Function.Uncurried (Fn2 , runFn2 )
5755import Data.Maybe (Maybe (..), fromMaybe )
5856import Data.Nullable (Nullable , toNullable , toMaybe )
5957import Data.Posix (Pid , Gid , Uid )
6058import Data.Posix.Signal (Signal )
6159import Data.Posix.Signal as Signal
62- import Data.StrMap (StrMap )
60+
61+ import Foreign (Foreign )
62+ import Foreign.Object (Object )
6363
6464import Node.Buffer (Buffer )
6565import Node.FS as FS
@@ -70,9 +70,6 @@ import Unsafe.Coerce (unsafeCoerce)
7070-- | A handle for inter-process communication (IPC).
7171foreign import data Handle :: Type
7272
73- -- | The effect for creating and interacting with child processes.
74- foreign import data CHILD_PROCESS :: Effect
75-
7673newtype ChildProcess = ChildProcess ChildProcessRec
7774
7875runChildProcess :: ChildProcess -> ChildProcessRec
@@ -81,29 +78,29 @@ runChildProcess (ChildProcess r) = r
8178-- | Note: some of these types are lies, and so it is unsafe to access some of
8279-- | these record fields directly.
8380type ChildProcessRec =
84- { stdin :: forall eff . Nullable (Writable () ( cp :: CHILD_PROCESS | eff ))
85- , stdout :: forall eff . Nullable (Readable () ( cp :: CHILD_PROCESS | eff ))
86- , stderr :: forall eff . Nullable (Readable () ( cp :: CHILD_PROCESS | eff ))
81+ { stdin :: Nullable (Writable ())
82+ , stdout :: Nullable (Readable ())
83+ , stderr :: Nullable (Readable ())
8784 , pid :: Pid
8885 , connected :: Boolean
8986 , kill :: String -> Boolean
9087 , send :: forall r . Fn2 { | r } Handle Boolean
91- , disconnect :: forall eff . Eff eff Unit
88+ , disconnect :: Effect Unit
9289 }
9390
9491-- | The standard input stream of a child process. Note that this is only
9592-- | available if the process was spawned with the stdin option set to "pipe".
96- stdin :: forall eff . ChildProcess -> Writable () ( cp :: CHILD_PROCESS | eff )
93+ stdin :: ChildProcess -> Writable ()
9794stdin = unsafeFromNullable (missingStream " stdin" ) <<< _.stdin <<< runChildProcess
9895
9996-- | The standard output stream of a child process. Note that this is only
10097-- | available if the process was spawned with the stdout option set to "pipe".
101- stdout :: forall eff . ChildProcess -> Readable () ( cp :: CHILD_PROCESS | eff )
98+ stdout :: ChildProcess -> Readable ()
10299stdout = unsafeFromNullable (missingStream " stdout" ) <<< _.stdout <<< runChildProcess
103100
104101-- | The standard error stream of a child process. Note that this is only
105102-- | available if the process was spawned with the stderr option set to "pipe".
106- stderr :: forall eff . ChildProcess -> Readable () ( cp :: CHILD_PROCESS | eff )
103+ stderr :: ChildProcess -> Readable ()
107104stderr = unsafeFromNullable (missingStream " stderr" ) <<< _.stderr <<< runChildProcess
108105
109106missingStream :: String -> String
@@ -119,23 +116,23 @@ foreign import unsafeFromNullable :: forall a. String -> Nullable a -> a
119116pid :: ChildProcess -> Pid
120117pid = _.pid <<< runChildProcess
121118
122- connected :: forall eff . ChildProcess -> Eff ( cp :: CHILD_PROCESS | eff ) Boolean
123- connected (ChildProcess cp) = mkEff \_ -> cp.connected
119+ connected :: ChildProcess -> Effect Boolean
120+ connected (ChildProcess cp) = mkEffect \_ -> cp.connected
124121
125- send :: forall eff props . { | props } -> Handle -> ChildProcess -> Eff ( cp :: CHILD_PROCESS | eff ) Boolean
126- send msg handle (ChildProcess cp) = mkEff \_ -> runFn2 cp.send msg handle
122+ send :: forall props . { | props } -> Handle -> ChildProcess -> Effect Boolean
123+ send msg handle (ChildProcess cp) = mkEffect \_ -> runFn2 cp.send msg handle
127124
128- disconnect :: forall eff . ChildProcess -> Eff ( cp :: CHILD_PROCESS | eff ) Unit
125+ disconnect :: ChildProcess -> Effect Unit
129126disconnect = _.disconnect <<< runChildProcess
130127
131128-- | Send a signal to a child process. It's an unfortunate historical decision
132129-- | that this function is called "kill", as sending a signal to a child
133130-- | process won't necessarily kill it.
134- kill :: forall eff . Signal -> ChildProcess -> Eff ( cp :: CHILD_PROCESS | eff ) Boolean
135- kill sig (ChildProcess cp) = mkEff \_ -> cp.kill (Signal .toString sig)
131+ kill :: Signal -> ChildProcess -> Effect Boolean
132+ kill sig (ChildProcess cp) = mkEffect \_ -> cp.kill (Signal .toString sig)
136133
137- mkEff :: forall eff a . (Unit -> a ) -> Eff eff a
138- mkEff = unsafeCoerce
134+ mkEffect :: forall a . (Unit -> a ) -> Effect a
135+ mkEffect = unsafeCoerce
139136
140137-- | Specifies how a child process exited; normally (with an exit code), or
141138-- | due to a signal.
@@ -156,45 +153,43 @@ mkExit code signal =
156153 fromCode = toMaybe >>> map Normally
157154 fromSignal = toMaybe >=> Signal .fromString >>> map BySignal
158155
159- onExit :: forall eff . ChildProcess -> (Exit -> Eff eff Unit ) -> Eff eff Unit
156+ onExit :: ChildProcess -> (Exit -> Effect Unit ) -> Effect Unit
160157onExit = mkOnExit mkExit
161158
162159foreign import mkOnExit
163- :: forall eff
164- . (Nullable Int -> Nullable String -> Exit )
160+ :: (Nullable Int -> Nullable String -> Exit )
165161 -> ChildProcess
166- -> (Exit -> Eff eff Unit )
167- -> Eff eff Unit
162+ -> (Exit -> Effect Unit )
163+ -> Effect Unit
168164
169- onClose :: forall eff . ChildProcess -> (Exit -> Eff eff Unit ) -> Eff eff Unit
165+ onClose :: ChildProcess -> (Exit -> Effect Unit ) -> Effect Unit
170166onClose = mkOnClose mkExit
171167
172168foreign import mkOnClose
173- :: forall eff
174- . (Nullable Int -> Nullable String -> Exit )
169+ :: (Nullable Int -> Nullable String -> Exit )
175170 -> ChildProcess
176- -> (Exit -> Eff eff Unit )
177- -> Eff eff Unit
171+ -> (Exit -> Effect Unit )
172+ -> Effect Unit
178173
179- onMessage :: forall eff . ChildProcess -> (Foreign -> Maybe Handle -> Eff eff Unit ) -> Eff eff Unit
174+ onMessage :: ChildProcess -> (Foreign -> Maybe Handle -> Effect Unit ) -> Effect Unit
180175onMessage = mkOnMessage Nothing Just
181176
182177foreign import mkOnMessage
183- :: forall a eff
178+ :: forall a
184179 . Maybe a
185180 -> (a -> Maybe a )
186181 -> ChildProcess
187- -> (Foreign -> Maybe Handle -> Eff eff Unit )
188- -> Eff eff Unit
182+ -> (Foreign -> Maybe Handle -> Effect Unit )
183+ -> Effect Unit
189184
190- foreign import onDisconnect :: forall eff . ChildProcess -> Eff eff Unit -> Eff eff Unit
191- foreign import onError :: forall eff . ChildProcess -> (Error -> Eff eff Unit ) -> Eff eff Unit
185+ foreign import onDisconnect :: ChildProcess -> Effect Unit -> Effect Unit
186+ foreign import onError :: ChildProcess -> (Error -> Effect Unit ) -> Effect Unit
192187
193188-- | Spawn a child process. Note that, in the event that a child process could
194189-- | not be spawned (for example, if the executable was not found) this will
195190-- | not throw an error. Instead, the `ChildProcess` will be created anyway,
196191-- | but it will immediately emit an 'error' event.
197- spawn :: forall eff . String -> Array String -> SpawnOptions -> Eff ( cp :: CHILD_PROCESS | eff ) ChildProcess
192+ spawn :: String -> Array String -> SpawnOptions -> Effect ChildProcess
198193spawn cmd args = spawnImpl cmd args <<< convertOpts
199194 where
200195 convertOpts opts =
@@ -206,15 +201,15 @@ spawn cmd args = spawnImpl cmd args <<< convertOpts
206201 , gid: fromMaybe undefined opts.gid
207202 }
208203
209- foreign import spawnImpl :: forall opts eff . String -> Array String -> { | opts } -> Eff ( cp :: CHILD_PROCESS | eff ) ChildProcess
204+ foreign import spawnImpl :: forall opts . String -> Array String -> { | opts } -> Effect ChildProcess
210205
211206-- There's gotta be a better way.
212207foreign import undefined :: forall a . a
213208
214209type SpawnOptions =
215210 { cwd :: Maybe String
216211 , stdio :: Array (Maybe StdIOBehaviour )
217- , env :: Maybe (StrMap String )
212+ , env :: Maybe (Object String )
218213 , detached :: Boolean
219214 , uid :: Maybe Uid
220215 , gid :: Maybe Gid
@@ -238,11 +233,10 @@ defaultSpawnOptions =
238233-- | Note that the child process will be killed if the amount of output exceeds
239234-- | a certain threshold (the default is defined by Node.js).
240235exec
241- :: forall eff
242- . String
236+ :: String
243237 -> ExecOptions
244- -> (ExecResult -> Eff ( cp :: CHILD_PROCESS | eff ) Unit )
245- -> Eff ( cp :: CHILD_PROCESS | eff ) Unit
238+ -> (ExecResult -> Effect Unit )
239+ -> Effect Unit
246240exec cmd opts callback =
247241 execImpl cmd (convertExecOptions opts) \err stdout' stderr' ->
248242 callback
@@ -252,21 +246,19 @@ exec cmd opts callback =
252246 }
253247
254248foreign import execImpl
255- :: forall eff
256- . String
249+ :: String
257250 -> ActualExecOptions
258- -> (Nullable Exception.Error -> Buffer -> Buffer -> Eff ( cp :: CHILD_PROCESS | eff ) Unit )
259- -> Eff ( cp :: CHILD_PROCESS | eff ) Unit
251+ -> (Nullable Exception.Error -> Buffer -> Buffer -> Effect Unit )
252+ -> Effect Unit
260253
261254-- | Like `exec`, except instead of using a shell, it passes the arguments
262255-- | directly to the specified command.
263256execFile
264- :: forall eff
265- . String
257+ :: String
266258 -> Array String
267259 -> ExecOptions
268- -> (ExecResult -> Eff ( cp :: CHILD_PROCESS | eff ) Unit )
269- -> Eff ( cp :: CHILD_PROCESS | eff ) Unit
260+ -> (ExecResult -> Effect Unit )
261+ -> Effect Unit
270262execFile cmd args opts callback =
271263 execFileImpl cmd args (convertExecOptions opts) \err stdout' stderr' ->
272264 callback
@@ -276,12 +268,11 @@ execFile cmd args opts callback =
276268 }
277269
278270foreign import execFileImpl
279- :: forall eff
280- . String
271+ :: String
281272 -> Array String
282273 -> ActualExecOptions
283- -> (Nullable Exception.Error -> Buffer -> Buffer -> Eff ( cp :: CHILD_PROCESS | eff ) Unit )
284- -> Eff ( cp :: CHILD_PROCESS | eff ) Unit
274+ -> (Nullable Exception.Error -> Buffer -> Buffer -> Effect Unit )
275+ -> Effect Unit
285276
286277foreign import data ActualExecOptions :: Type
287278
@@ -298,7 +289,7 @@ convertExecOptions opts = unsafeCoerce
298289
299290type ExecOptions =
300291 { cwd :: Maybe String
301- , env :: Maybe (StrMap String )
292+ , env :: Maybe (Object String )
302293 , timeout :: Maybe Number
303294 , maxBuffer :: Maybe Int
304295 , killSignal :: Maybe Signal
@@ -326,7 +317,7 @@ type ExecResult =
326317-- | A special case of `spawn` for creating Node.js child processes. The first
327318-- | argument is the module to be run, and the second is the argv (command line
328319-- | arguments).
329- foreign import fork :: forall eff . String -> Array String -> Eff ( cp :: CHILD_PROCESS | eff ) ChildProcess
320+ foreign import fork :: String -> Array String -> Effect ChildProcess
330321
331322-- | An error which occurred inside a child process.
332323type Error =
@@ -336,7 +327,7 @@ type Error =
336327 }
337328
338329-- | Convert a ChildProcess.Error to a standard Error, which can then be thrown
339- -- | inside an Eff or Aff computation (for example).
330+ -- | inside an Effect or Aff computation (for example).
340331toStandardError :: Error -> Exception.Error
341332toStandardError = unsafeCoerce
342333
@@ -355,7 +346,7 @@ toStandardError = unsafeCoerce
355346data StdIOBehaviour
356347 = Pipe
357348 | Ignore
358- | ShareStream (forall r eff . Stream r eff )
349+ | ShareStream (forall r . Stream r )
359350 | ShareFD FS.FileDescriptor
360351
361352-- | Create pipes for each of the three standard IO streams.
0 commit comments