diff --git a/README.md b/README.md index 620b259..0a44cd8 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ There is also [a more complete example](#full-example) that makes use of all the 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. +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. + ### `purescript.psc(options)` Invokes the `psc` command. The following options are supported. @@ -74,6 +76,10 @@ Sets `--output=` the specifies the output directory, `output` by default Toggles `--no-prefix` that does not include the comment header. +###### `requirePath` (String) + +Sets `--require-path=` that specifies the path prefix to use for `require()` calls in the generated JavaScript. + ### `purescript.pscBundle(options)` Invokes the `psc-bundle` command. The following options are supported. @@ -100,7 +106,7 @@ Sets `--namespace=` that specifies the namespace that PureScript modules ###### `requirePath` (String) -Sets `--require-path=` that specifies the path prefix to use for `require()` calls in the generated JavaScript. +Sets `--require-path=` 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. ### `purescript.pscDocs(options)` diff --git a/bower.json b/bower.json index 11ab059..d6e617e 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "gulp-purescript", "private": true, "devDependencies": { - "purescript-aff": "~0.12.0", + "purescript-aff": "~0.13.0", "purescript-foreign": "~0.7.0" } } diff --git a/src/GulpPurescript/Options.purs b/src/GulpPurescript/Options.purs index 763ac9c..dd02139 100644 --- a/src/GulpPurescript/Options.purs +++ b/src/GulpPurescript/Options.purs @@ -99,6 +99,7 @@ newtype PscBundle , "module" :: NullOrUndefined (Either String (Array String)) , main :: NullOrUndefined (Either Boolean String) , namespace :: NullOrUndefined String + , requirePath :: NullOrUndefined String } newtype PscDocs @@ -148,11 +149,13 @@ instance isForeignPscBundle :: IsForeign PscBundle where , "module": _ , main: _ , namespace: _ + , requirePath: _ } <$> (readProp srcKey obj >>= readEither) <*> readProp outputKey obj <*> (readProp moduleKey obj >>= readEitherNU) <*> (readProp mainKey obj >>= readEitherNU) - <*> readProp namespaceKey obj) + <*> readProp namespaceKey obj + <*> readProp requirePathKey obj) instance isForeignPscDocs :: IsForeign PscDocs where read obj = @@ -253,7 +256,8 @@ pscBundleOptions opts = fold <$> parsed opt outputOpt a.output <> opt moduleOpt a."module" <> opt mainOpt a.main <> - opt namespaceOpt a.namespace + opt namespaceOpt a.namespace <> + opt requirePathOpt a.requirePath pscDocsOptions :: Foreign -> Either ForeignError (Array String) pscDocsOptions opts = fold <$> parsed diff --git a/src/GulpPurescript/Plugin.js b/src/GulpPurescript/Plugin.js index a96241d..9bf806a 100644 --- a/src/GulpPurescript/Plugin.js +++ b/src/GulpPurescript/Plugin.js @@ -5,3 +5,4 @@ var cwd = process.cwd(); exports.cwd = cwd; +exports.argv = process.argv; diff --git a/src/GulpPurescript/Plugin.purs b/src/GulpPurescript/Plugin.purs index 0b559dd..2c35f74 100644 --- a/src/GulpPurescript/Plugin.purs +++ b/src/GulpPurescript/Plugin.purs @@ -16,17 +16,17 @@ import Control.Monad.Eff.Class (liftEff) import Control.Monad.Eff.Exception (Error()) import Control.Monad.Error.Class (catchError, throwError) -import Data.Array (concat) +import Data.Array as A import Data.Either (Either(..), either) import Data.Foreign (Foreign()) -import Data.Foreign.Class (IsForeign, read, readProp) +import Data.Foreign.Class (read) import Data.Foreign.NullOrUndefined (runNullOrUndefined) -import Data.Maybe (Maybe(Just), maybe, fromMaybe) +import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.String (joinWith, null) import Data.Tuple (Tuple(..)) import Data.Tuple.Nested (tuple2) -import GulpPurescript.Buffer (Buffer(), mkBufferFromString) +import GulpPurescript.Buffer (mkBufferFromString) import GulpPurescript.ChildProcess (ChildProcess(), spawn) import GulpPurescript.Glob (Glob(), globAll) import GulpPurescript.GulpUtil (File(), mkFile, mkPluginError) @@ -39,6 +39,15 @@ import GulpPurescript.ResolveBin (ResolveBin(), resolveBin) import GulpPurescript.Stream (Stream(), ReadableStream(), mkReadableStreamFromAff) import GulpPurescript.Which (Which(), which) +foreign import argv :: Array String + +rtsOpts :: Array String +rtsOpts = + let startIndex = A.elemIndex "--psc-rts-flags" argv + in case startIndex of + Just i -> ["+RTS"] <> A.drop (i + 1) argv <> ["-RTS"] + _ -> [] + type Effects eff = ( cp :: ChildProcess , glob :: Glob @@ -55,20 +64,28 @@ type Errorback eff = Error -> Eff (Effects eff) Unit type Callback eff a = a -> Eff (Effects eff) Unit +nodeCommand :: String nodeCommand = "node" +pursPackage :: String pursPackage = "purescript" +psciFilename :: String psciFilename = ".psci" +psciLoadModuleCommand :: String psciLoadModuleCommand = ":m" +psciLoadForeignCommand :: String psciLoadForeignCommand = ":f" +pscCommand :: String pscCommand = "psc" +pscBundleCommand :: String pscBundleCommand = "psc-bundle" +pscDocsCommand :: String pscDocsCommand = "psc-docs" foreign import cwd :: String @@ -103,7 +120,7 @@ execute cmd args = do psc :: forall eff. Foreign -> Eff (Effects eff) (ReadableStream Unit) psc opts = mkReadableStreamFromAff $ do output <- either (throwPluginError <<< show) - (execute pscCommand) + (execute pscCommand <<< (<> rtsOpts)) (pscOptions opts) if null output then pure unit @@ -131,7 +148,7 @@ psci opts = mkReadableStreamFromAff (either (throwPluginError <<< show) run (rea srcs <- globAll (either pure id a.src) ffis <- globAll (either pure id (fromMaybe (Right []) (runNullOrUndefined a.ffi))) - let lines = (loadModule <$> concat srcs) <> (loadForeign <$> concat ffis) + let lines = (loadModule <$> A.concat srcs) <> (loadForeign <$> A.concat ffis) buffer = mkBufferFromString (joinWith "\n" lines) return (mkFile psciFilename buffer)