@@ -16,17 +16,17 @@ import Control.Monad.Eff.Class (liftEff)
1616import Control.Monad.Eff.Exception (Error ())
1717import Control.Monad.Error.Class (catchError , throwError )
1818
19- import Data.Array ( concat )
19+ import Data.Array as A
2020import Data.Either (Either (..), either )
2121import Data.Foreign (Foreign ())
22- import Data.Foreign.Class (IsForeign , read , readProp )
22+ import Data.Foreign.Class (read )
2323import Data.Foreign.NullOrUndefined (runNullOrUndefined )
24- import Data.Maybe (Maybe (Just ), maybe , fromMaybe )
24+ import Data.Maybe (Maybe (.. ), maybe , fromMaybe )
2525import Data.String (joinWith , null )
2626import Data.Tuple (Tuple (..))
2727import Data.Tuple.Nested (tuple2 )
2828
29- import GulpPurescript.Buffer (Buffer (), mkBufferFromString )
29+ import GulpPurescript.Buffer (mkBufferFromString )
3030import GulpPurescript.ChildProcess (ChildProcess (), spawn )
3131import GulpPurescript.Glob (Glob (), globAll )
3232import GulpPurescript.GulpUtil (File (), mkFile , mkPluginError )
@@ -39,6 +39,15 @@ import GulpPurescript.ResolveBin (ResolveBin(), resolveBin)
3939import GulpPurescript.Stream (Stream (), ReadableStream (), mkReadableStreamFromAff )
4040import 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+
4251type Effects eff =
4352 ( cp :: ChildProcess
4453 , glob :: Glob
@@ -55,20 +64,28 @@ type Errorback eff = Error -> Eff (Effects eff) Unit
5564
5665type Callback eff a = a -> Eff (Effects eff ) Unit
5766
67+ nodeCommand :: String
5868nodeCommand = " node"
5969
70+ pursPackage :: String
6071pursPackage = " purescript"
6172
73+ psciFilename :: String
6274psciFilename = " .psci"
6375
76+ psciLoadModuleCommand :: String
6477psciLoadModuleCommand = " :m"
6578
79+ psciLoadForeignCommand :: String
6680psciLoadForeignCommand = " :f"
6781
82+ pscCommand :: String
6883pscCommand = " psc"
6984
85+ pscBundleCommand :: String
7086pscBundleCommand = " psc-bundle"
7187
88+ pscDocsCommand :: String
7289pscDocsCommand = " psc-docs"
7390
7491foreign import cwd :: String
@@ -103,7 +120,7 @@ execute cmd args = do
103120psc :: forall eff . Foreign -> Eff (Effects eff ) (ReadableStream Unit )
104121psc 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