Skip to content

Commit 5210893

Browse files
committed
Add Node.Globals for other global objects
Also update docs + fix jshint problems
1 parent fd882f0 commit 5210893

File tree

6 files changed

+107
-5
lines changed

6 files changed

+107
-5
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"purescript-node-streams": "~0.3.0",
2121
"purescript-maybe": "~0.3.5",
2222
"purescript-exceptions": "~0.3.3",
23-
"purescript-unsafe-coerce": "~0.1.0"
23+
"purescript-unsafe-coerce": "~0.1.0",
24+
"purescript-node-fs": "~0.9.2"
2425
}
2526
}

docs/Node/Globals.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Module Node.Globals
2+
3+
Global objects exposed by Node.js. See also the [Node.js API
4+
documentation](https://nodejs.org/api/globals.html).
5+
6+
#### `__dirname`
7+
8+
``` purescript
9+
__dirname :: String
10+
```
11+
12+
The name of the directory that the currently executing script resides in.
13+
14+
Note that this will probably not give you a very useful answer unless you
15+
have bundled up your PureScript code using `psc-bundle`!
16+
17+
#### `__filename`
18+
19+
``` purescript
20+
__filename :: String
21+
```
22+
23+
The absolute path of the code file being executed.
24+
25+
Note that this will probably not give you a very useful answer unless you
26+
have bundled up your PureScript code using `psc-bundle`!
27+
28+
#### `unsafeRequire`
29+
30+
``` purescript
31+
unsafeRequire :: forall a. String -> a
32+
```
33+
34+
Just calls `require`. You might also consider using the FFI instead. This
35+
function is, in general, horribly unsafe, and may perform side effects.
36+
37+
#### `requireResolve`
38+
39+
``` purescript
40+
requireResolve :: forall eff. String -> Eff (fs :: FS | eff) String
41+
```
42+
43+
`require.resolve()`. Use the internal `require` machinery to look up the
44+
location of a module, but rather than loading the module, just return the
45+
resolved filename.
46+
47+

docs/Node/Process.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,17 @@ setEnv :: forall eff. String -> String -> Eff (process :: PROCESS | eff) Unit
109109

110110
Set an environment variable.
111111

112+
#### `Pid`
113+
114+
``` purescript
115+
newtype Pid
116+
= Pid Int
117+
```
118+
112119
#### `pid`
113120

114121
``` purescript
115-
pid :: Int
122+
pid :: Pid
116123
```
117124

118125
#### `platform`
@@ -143,7 +150,7 @@ event, so any handlers attached via `onEnd` will never be called.
143150
#### `stdout`
144151

145152
``` purescript
146-
stdout :: forall eff. Writable () (console :: CONSOLE | eff)
153+
stdout :: forall eff. Writable () (console :: CONSOLE, err :: EXCEPTION | eff)
147154
```
148155

149156
The standard output stream. Note that this stream cannot be closed; calling
@@ -152,7 +159,7 @@ The standard output stream. Note that this stream cannot be closed; calling
152159
#### `stderr`
153160

154161
``` purescript
155-
stderr :: forall eff. Writable () (console :: CONSOLE | eff)
162+
stderr :: forall eff. Writable () (console :: CONSOLE, err :: EXCEPTION | eff)
156163
```
157164

158165
The standard error stream. Note that this stream cannot be closed; calling

src/Node/Globals.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
/* global exports */
3+
/* global require */
4+
/* global __dirname */
5+
/* global __filename */
6+
7+
// module Node.Globals
8+
9+
exports.__dirname = __dirname;
10+
exports.__filename = __filename;
11+
exports.unsafeRequire = require;
12+
13+
exports.requireResolve = function(mod) {
14+
return function() {
15+
return require.resolve(mod);
16+
};
17+
};

src/Node/Globals.purs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- | Global objects exposed by Node.js. See also the [Node.js API
2+
-- | documentation](https://nodejs.org/api/globals.html).
3+
module Node.Globals where
4+
5+
import Control.Monad.Eff
6+
import Node.FS (FS())
7+
8+
-- | The name of the directory that the currently executing script resides in.
9+
-- |
10+
-- | Note that this will probably not give you a very useful answer unless you
11+
-- | have bundled up your PureScript code using `psc-bundle`!
12+
foreign import __dirname :: String
13+
14+
-- | The absolute path of the code file being executed.
15+
-- |
16+
-- | Note that this will probably not give you a very useful answer unless you
17+
-- | have bundled up your PureScript code using `psc-bundle`!
18+
foreign import __filename :: String
19+
20+
-- | Just calls `require`. You might also consider using the FFI instead. This
21+
-- | function is, in general, horribly unsafe, and may perform side effects.
22+
foreign import unsafeRequire :: forall a. String -> a
23+
24+
-- | `require.resolve()`. Use the internal `require` machinery to look up the
25+
-- | location of a module, but rather than loading the module, just return the
26+
-- | resolved filename.
27+
foreign import requireResolve :: forall eff. String -> Eff (fs :: FS | eff) String

src/Node/Process.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"use strict";
22
// module Node.Process
33

4+
/* global exports */
5+
/* global process */
6+
47
exports.process = process;
58

69
exports.onBeforeExit = function(callback) {
710
return function() {
811
process.on('beforeExit', callback);
9-
}
12+
};
1013
};
1114

1215
exports.onExit = function(callback) {

0 commit comments

Comments
 (0)