Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 06a81fa

Browse files
committed
Merge pull request #57 from purescript-contrib/updates
Add RTS options reading from argv
2 parents 4ee675b + 7c4c883 commit 06a81fa

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ There is also [a more complete example](#full-example) that makes use of all the
3434

3535
Refer to the PureScript [compiler usage](https://github.com/purescript/purescript/wiki/Language-Guide:-Getting-Started#compiler-usage) section of the Github wiki for additional details on the behaviour of each option below.
3636

37+
Options can be passed to the Haskell runtime system for `psc` by passing a `--psc-rts-opts` argument to `gulp`. Any values that follow this flag will be passed through to the runtime. There is no need to include `+RTS`/`-RTS` options as these are inserted automatically. See [the GHC documentation](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/runtime-control.html#rts-opts-cmdline) for information on the available RTS options.
38+
3739
### `purescript.psc(options)`
3840

3941
Invokes the `psc` command. The following options are supported.
@@ -74,6 +76,10 @@ Sets `--output=<string>` the specifies the output directory, `output` by default
7476

7577
Toggles `--no-prefix` that does not include the comment header.
7678

79+
###### `requirePath` (String)
80+
81+
Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript.
82+
7783
### `purescript.pscBundle(options)`
7884

7985
Invokes the `psc-bundle` command. The following options are supported.
@@ -100,7 +106,7 @@ Sets `--namespace=<string>` that specifies the namespace that PureScript modules
100106

101107
###### `requirePath` (String)
102108

103-
Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript.
109+
Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript. This should be set any value used in the `psc` task.
104110

105111
### `purescript.pscDocs(options)`
106112

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gulp-purescript",
33
"private": true,
44
"devDependencies": {
5-
"purescript-aff": "~0.12.0",
5+
"purescript-aff": "~0.13.0",
66
"purescript-foreign": "~0.7.0"
77
}
88
}

src/GulpPurescript/Options.purs

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ newtype PscBundle
9999
, "module" :: NullOrUndefined (Either String (Array String))
100100
, main :: NullOrUndefined (Either Boolean String)
101101
, namespace :: NullOrUndefined String
102+
, requirePath :: NullOrUndefined String
102103
}
103104

104105
newtype PscDocs
@@ -148,11 +149,13 @@ instance isForeignPscBundle :: IsForeign PscBundle where
148149
, "module": _
149150
, main: _
150151
, namespace: _
152+
, requirePath: _
151153
} <$> (readProp srcKey obj >>= readEither)
152154
<*> readProp outputKey obj
153155
<*> (readProp moduleKey obj >>= readEitherNU)
154156
<*> (readProp mainKey obj >>= readEitherNU)
155-
<*> readProp namespaceKey obj)
157+
<*> readProp namespaceKey obj
158+
<*> readProp requirePathKey obj)
156159

157160
instance isForeignPscDocs :: IsForeign PscDocs where
158161
read obj =
@@ -253,7 +256,8 @@ pscBundleOptions opts = fold <$> parsed
253256
opt outputOpt a.output <>
254257
opt moduleOpt a."module" <>
255258
opt mainOpt a.main <>
256-
opt namespaceOpt a.namespace
259+
opt namespaceOpt a.namespace <>
260+
opt requirePathOpt a.requirePath
257261

258262
pscDocsOptions :: Foreign -> Either ForeignError (Array String)
259263
pscDocsOptions opts = fold <$> parsed

src/GulpPurescript/Plugin.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
var cwd = process.cwd();
66

77
exports.cwd = cwd;
8+
exports.argv = process.argv;

src/GulpPurescript/Plugin.purs

+23-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ import Control.Monad.Eff.Class (liftEff)
1616
import Control.Monad.Eff.Exception (Error())
1717
import Control.Monad.Error.Class (catchError, throwError)
1818

19-
import Data.Array (concat)
19+
import Data.Array as A
2020
import Data.Either (Either(..), either)
2121
import Data.Foreign (Foreign())
22-
import Data.Foreign.Class (IsForeign, read, readProp)
22+
import Data.Foreign.Class (read)
2323
import Data.Foreign.NullOrUndefined (runNullOrUndefined)
24-
import Data.Maybe (Maybe(Just), maybe, fromMaybe)
24+
import Data.Maybe (Maybe(..), maybe, fromMaybe)
2525
import Data.String (joinWith, null)
2626
import Data.Tuple (Tuple(..))
2727
import Data.Tuple.Nested (tuple2)
2828

29-
import GulpPurescript.Buffer (Buffer(), mkBufferFromString)
29+
import GulpPurescript.Buffer (mkBufferFromString)
3030
import GulpPurescript.ChildProcess (ChildProcess(), spawn)
3131
import GulpPurescript.Glob (Glob(), globAll)
3232
import GulpPurescript.GulpUtil (File(), mkFile, mkPluginError)
@@ -39,6 +39,15 @@ import GulpPurescript.ResolveBin (ResolveBin(), resolveBin)
3939
import GulpPurescript.Stream (Stream(), ReadableStream(), mkReadableStreamFromAff)
4040
import GulpPurescript.Which (Which(), which)
4141

42+
foreign import argv :: Array String
43+
44+
rtsOpts :: Array String
45+
rtsOpts =
46+
let startIndex = A.elemIndex "--psc-rts-flags" argv
47+
in case startIndex of
48+
Just i -> ["+RTS"] <> A.drop (i + 1) argv <> ["-RTS"]
49+
_ -> []
50+
4251
type Effects eff =
4352
( cp :: ChildProcess
4453
, glob :: Glob
@@ -55,20 +64,28 @@ type Errorback eff = Error -> Eff (Effects eff) Unit
5564

5665
type Callback eff a = a -> Eff (Effects eff) Unit
5766

67+
nodeCommand :: String
5868
nodeCommand = "node"
5969

70+
pursPackage :: String
6071
pursPackage = "purescript"
6172

73+
psciFilename :: String
6274
psciFilename = ".psci"
6375

76+
psciLoadModuleCommand :: String
6477
psciLoadModuleCommand = ":m"
6578

79+
psciLoadForeignCommand :: String
6680
psciLoadForeignCommand = ":f"
6781

82+
pscCommand :: String
6883
pscCommand = "psc"
6984

85+
pscBundleCommand :: String
7086
pscBundleCommand = "psc-bundle"
7187

88+
pscDocsCommand :: String
7289
pscDocsCommand = "psc-docs"
7390

7491
foreign import cwd :: String
@@ -103,7 +120,7 @@ execute cmd args = do
103120
psc :: forall eff. Foreign -> Eff (Effects eff) (ReadableStream Unit)
104121
psc opts = mkReadableStreamFromAff $ do
105122
output <- either (throwPluginError <<< show)
106-
(execute pscCommand)
123+
(execute pscCommand <<< (<> rtsOpts))
107124
(pscOptions opts)
108125
if null output
109126
then pure unit
@@ -131,7 +148,7 @@ psci opts = mkReadableStreamFromAff (either (throwPluginError <<< show) run (rea
131148
srcs <- globAll (either pure id a.src)
132149
ffis <- globAll (either pure id (fromMaybe (Right []) (runNullOrUndefined a.ffi)))
133150

134-
let lines = (loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)
151+
let lines = (loadModule <$> A.concat srcs) <> (loadForeign <$> A.concat ffis)
135152
buffer = mkBufferFromString (joinWith "\n" lines)
136153

137154
return (mkFile psciFilename buffer)

0 commit comments

Comments
 (0)