1
1
-- | Bindings to the global `process` object in Node.js. See also [the Node API documentation](https://nodejs.org/api/process.html)
2
2
module Node.Process
3
- ( PROCESS
4
- , onBeforeExit
3
+ ( onBeforeExit
5
4
, onExit
6
5
, onSignal
7
6
, argv
@@ -25,89 +24,82 @@ module Node.Process
25
24
26
25
import Prelude
27
26
28
- import Control.Monad.Eff (Eff , kind Effect )
29
- import Control.Monad.Eff.Console (CONSOLE )
30
- import Control.Monad.Eff.Exception (EXCEPTION )
27
+ import Effect (Effect )
31
28
32
29
import Data.Maybe (Maybe )
33
30
import Data.Posix (Pid )
34
31
import Data.Posix.Signal (Signal )
35
32
import Data.Posix.Signal as Signal
36
- import Data.StrMap (StrMap )
37
- import Data.StrMap as StrMap
38
-
33
+ import Foreign.Object as FO
39
34
import Node.Platform (Platform )
40
35
import Node.Platform as Platform
41
36
import Node.Stream (Readable , Writable )
42
37
43
38
import Unsafe.Coerce (unsafeCoerce )
44
39
45
- -- | An effect tracking interaction with the global `process` object.
46
- foreign import data PROCESS :: Effect
47
-
48
40
-- YOLO
49
41
foreign import process :: forall props . { | props }
50
42
51
- mkEff :: forall eff a . (Unit -> a ) -> Eff eff a
52
- mkEff = unsafeCoerce
43
+ mkEffect :: forall a . (Unit -> a ) -> Effect a
44
+ mkEffect = unsafeCoerce
53
45
54
46
-- | Register a callback to be performed when the event loop empties, and
55
47
-- | Node.js is about to exit. Asynchronous calls can be made in the callback,
56
48
-- | and if any are made, it will cause the process to continue a little longer.
57
- foreign import onBeforeExit :: forall eff . Eff ( process :: PROCESS | eff ) Unit -> Eff ( process :: PROCESS | eff ) Unit
49
+ foreign import onBeforeExit :: Effect Unit -> Effect Unit
58
50
59
51
-- | Register a callback to be performed when the process is about to exit.
60
52
-- | Any work scheduled via asynchronous calls made here will not be performed
61
53
-- | in time.
62
54
-- |
63
55
-- | The argument to the callback is the exit code which the process is about
64
56
-- | to exit with.
65
- foreign import onExit :: forall eff . (Int -> Eff ( process :: PROCESS | eff ) Unit ) -> Eff ( process :: PROCESS | eff ) Unit
57
+ foreign import onExit :: (Int -> Effect Unit ) -> Effect Unit
66
58
67
- foreign import onSignalImpl :: forall eff . String -> Eff ( process :: PROCESS | eff ) Unit -> Eff ( process :: PROCESS | eff ) Unit
59
+ foreign import onSignalImpl :: String -> Effect Unit -> Effect Unit
68
60
69
61
-- | Install a handler for a particular signal.
70
- onSignal :: forall eff . Signal -> Eff ( process :: PROCESS | eff ) Unit -> Eff ( process :: PROCESS | eff ) Unit
62
+ onSignal :: Signal -> Effect Unit -> Effect Unit
71
63
onSignal sig = onSignalImpl (Signal .toString sig)
72
64
73
65
-- | Register a callback to run as soon as the current event loop runs to
74
66
-- | completion.
75
- nextTick :: forall eff . Eff eff Unit -> Eff eff Unit
76
- nextTick callback = mkEff \_ -> process.nextTick callback
67
+ nextTick :: Effect Unit -> Effect Unit
68
+ nextTick callback = mkEffect \_ -> process.nextTick callback
77
69
78
70
-- | Get an array containing the command line arguments. Be aware
79
71
-- | that this can change over the course of the program.
80
- argv :: forall eff . Eff ( process :: PROCESS | eff ) (Array String )
81
- argv = mkEff \_ -> process.argv
72
+ argv :: Effect (Array String )
73
+ argv = mkEffect \_ -> process.argv
82
74
83
75
-- | Node-specific options passed to the `node` executable. Be aware that
84
76
-- | this can change over the course of the program.
85
- execArgv :: forall eff . Eff ( process :: PROCESS | eff ) (Array String )
86
- execArgv = mkEff \_ -> process.execArgv
77
+ execArgv :: Effect (Array String )
78
+ execArgv = mkEffect \_ -> process.execArgv
87
79
88
80
-- | The absolute pathname of the `node` executable that started the
89
81
-- | process.
90
- execPath :: forall eff . Eff ( process :: PROCESS | eff ) String
91
- execPath = mkEff \_ -> process.execPath
82
+ execPath :: Effect String
83
+ execPath = mkEffect \_ -> process.execPath
92
84
93
85
-- | Change the current working directory of the process. If the current
94
86
-- | directory could not be changed, an exception will be thrown.
95
- foreign import chdir :: forall eff . String -> Eff ( exception :: EXCEPTION , process :: PROCESS | eff ) Unit
87
+ foreign import chdir :: String -> Effect Unit
96
88
97
89
-- | Get the current working directory of the process.
98
- cwd :: forall eff . Eff ( process :: PROCESS | eff ) String
90
+ cwd :: Effect String
99
91
cwd = process.cwd
100
92
101
93
-- | Get a copy of the current environment.
102
- getEnv :: forall eff . Eff ( process :: PROCESS | eff ) ( StrMap String )
103
- getEnv = mkEff \_ -> process.env
94
+ getEnv :: Effect ( FO.Object String )
95
+ getEnv = mkEffect \_ -> process.env
104
96
105
97
-- | Lookup a particular environment variable.
106
- lookupEnv :: forall eff . String -> Eff ( process :: PROCESS | eff ) (Maybe String )
107
- lookupEnv k = StrMap .lookup k <$> getEnv
98
+ lookupEnv :: String -> Effect (Maybe String )
99
+ lookupEnv k = FO .lookup k <$> getEnv
108
100
109
101
-- | Set an environment variable.
110
- foreign import setEnv :: forall eff . String -> String -> Eff ( process :: PROCESS | eff ) Unit
102
+ foreign import setEnv :: String -> String -> Effect Unit
111
103
112
104
pid :: Pid
113
105
pid = process.pid
@@ -121,21 +113,21 @@ platformStr = process.platform
121
113
-- | Cause the process to exit with the supplied integer code. An exit code
122
114
-- | of 0 is normally considered successful, and anything else is considered a
123
115
-- | failure.
124
- foreign import exit :: forall eff a . Int -> Eff ( process :: PROCESS | eff ) a
116
+ foreign import exit :: forall a . Int -> Effect a
125
117
126
118
-- | The standard input stream. Note that this stream will never emit an `end`
127
119
-- | event, so any handlers attached via `onEnd` will never be called.
128
- stdin :: forall eff . Readable () ( console :: CONSOLE | eff )
120
+ stdin :: Readable ()
129
121
stdin = process.stdin
130
122
131
123
-- | The standard output stream. Note that this stream cannot be closed; calling
132
124
-- | `end` will result in an exception being thrown.
133
- stdout :: forall eff . Writable () ( console :: CONSOLE , exception :: EXCEPTION | eff )
125
+ stdout :: Writable ()
134
126
stdout = process.stdout
135
127
136
128
-- | The standard error stream. Note that this stream cannot be closed; calling
137
129
-- | `end` will result in an exception being thrown.
138
- stderr :: forall eff . Writable () ( console :: CONSOLE , exception :: EXCEPTION | eff )
130
+ stderr :: Writable ()
139
131
stderr = process.stderr
140
132
141
133
-- | Check whether the standard output stream appears to be attached to a TTY.
0 commit comments