Skip to content

Commit cb2fc7f

Browse files
committed
Refactoring
1 parent 8bb82a7 commit cb2fc7f

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

src/Node/Process.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
"use strict";
22
// module Node.Process
33

4-
exports.globalProcessObject = process;
5-
6-
exports.readMutableProperty = function(propName) {
7-
return function() {
8-
return process[propName];
9-
}
10-
}
4+
exports.process = process;

src/Node/Process.purs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ import Node.Stream (Readable(), Writable())
3636
foreign import data PROCESS :: !
3737

3838
-- YOLO
39-
foreign import globalProcessObject :: forall props. { | props }
39+
foreign import process :: forall props. { | props }
4040

41-
-- | Very unsafe. Be careful. Reads a mutable property off the global `process`
42-
-- | object.
43-
foreign import readMutableProperty :: forall eff a. String -> Eff eff a
44-
45-
-- | Read an immutable property off the global `process` object.
46-
readImmutableProperty :: forall a. String -> a
47-
readImmutableProperty = unsafePerformEff <<< readMutableProperty
41+
mutable :: forall eff a. a -> Eff eff a
42+
mutable = pure
4843

4944
-- | Register a callback to be performed when the event loop empties, and
5045
-- | Node.js is about to exit. Asynchronous calls can be made in the callback,
@@ -65,28 +60,29 @@ foreign import onSignal :: forall eff. String -> Eff (process :: PROCESS | eff)
6560
-- | Get an array containing the command line arguments. Be aware
6661
-- | that this can change over the course of the program.
6762
argv :: forall eff. Eff (process :: PROCESS | eff) (Array String)
68-
argv = readMutableProperty "argv"
63+
argv = mutable process.argv
6964

7065
-- | Node-specific options passed to the `node` executable. Be aware that
7166
-- | this can change over the course of the program.
7267
execArgv :: forall eff. Eff (process :: PROCESS | eff) (Array String)
73-
execArgv = readMutableProperty "execArgv"
68+
execArgv = mutable process.execArgv
7469

7570
-- | The absolute pathname of the `node` executable that started the
7671
-- | process.
7772
execPath :: forall eff. Eff (process :: PROCESS | eff) String
78-
execPath = readMutableProperty "execPath"
73+
execPath = mutable process.execPath
7974

8075
-- | Change the current working directory of the process. If the current
8176
-- | directory could not be changed, an exception will be thrown.
8277
foreign import chdir :: forall eff. String -> Eff (err :: EXCEPTION, process :: PROCESS | eff) Unit
8378

8479
-- | Get the current working directory of the process.
85-
foreign import cwd :: forall eff. Eff (process :: PROCESS | eff) String
80+
cwd :: forall eff. Eff (process :: PROCESS | eff) String
81+
cwd = process.cwd
8682

8783
-- | Get a copy of the current environment.
8884
getEnv :: forall eff. Eff (process :: PROCESS | eff) (StrMap String)
89-
getEnv = readMutableProperty "env"
85+
getEnv = mutable process.env
9086

9187
-- | Lookup a particular environment variable.
9288
lookupEnv :: forall eff. String -> Eff (process :: PROCESS | eff) (Maybe String)
@@ -96,28 +92,29 @@ lookupEnv k = StrMap.lookup k <$> getEnv
9692
foreign import setEnv :: forall eff. String -> String -> Eff (process :: PROCESS | eff) Unit
9793

9894
pid :: Int
99-
pid = readImmutableProperty "pid"
95+
pid = process.pid
10096

10197
platform :: String
102-
platform = readImmutableProperty "platform"
98+
platform = process.platform
10399

104100
-- | Cause the process to exit with the supplied integer code. An exit code
105101
-- | of 0 is normally considered successful, and anything else is considered a
106102
-- | failure.
107103
foreign import exit :: forall eff. Int -> Eff (process :: PROCESS | eff) Unit
108104

109105
stdin :: forall eff. Readable () (console :: CONSOLE | eff)
110-
stdin = readImmutableProperty "stdin"
106+
stdin = process.stdin
111107

112108
stdout :: forall eff. Writable () (console :: CONSOLE | eff)
113-
stdout = readImmutableProperty "stdout"
109+
stdout = process.stdout
114110

115111
stderr :: forall eff. Writable () (console :: CONSOLE | eff)
116-
stderr = readImmutableProperty "stderr"
112+
stderr = process.stderr
117113

118114
-- | Check whether the process is being run inside a TTY context
119-
foreign import stdoutIsTTY :: forall eff. Eff (process :: PROCESS | eff) Boolean
115+
stdoutIsTTY :: Boolean
116+
stdoutIsTTY = process.stdout.isTTY
120117

121118
-- | Get the Node.js version.
122119
version :: String
123-
version = readImmutableProperty "version"
120+
version = process.version

0 commit comments

Comments
 (0)