From 2b620717603a6a2ba4d93ee1ca7334dc31500acf Mon Sep 17 00:00:00 2001 From: Nathan Faubion Date: Mon, 2 Nov 2015 14:04:58 -0600 Subject: Remove `require-path`, use relative paths for PS Fixes #15 Removes the `require-path` option and fixes it to '../'. When generating the temporary module for Webpack, use a relative path to the output directory so it doesn't need to be in `modulesDirectories`. --- src/PursLoader/Options.purs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/PursLoader/Options.purs') diff --git a/src/PursLoader/Options.purs b/src/PursLoader/Options.purs index e3957eb..1650652 100644 --- a/src/PursLoader/Options.purs +++ b/src/PursLoader/Options.purs @@ -2,9 +2,11 @@ module PursLoader.Options ( pscOptions , loaderSrcOption , loaderFFIOption + , Options() + , output ) where -import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const) +import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), ($), const, id) import Data.Array (concat) import Data.Either (either) @@ -44,13 +46,16 @@ newtype Options , noTco :: NullOrUndefined Boolean , verboseErrors :: NullOrUndefined Boolean , comments :: NullOrUndefined Boolean - , output :: NullOrUndefined String + , output :: String , noPrefix :: NullOrUndefined Boolean - , requirePath :: NullOrUndefined String + , requirePath :: String , src :: NullOrUndefined (Array String) , ffi :: NullOrUndefined (Array String) } +output :: Options -> String +output (Options o) = o.output + instance isForeignOptions :: IsForeign Options where read obj = Options <$> ({ noPrelude: _ , noOpts: _ @@ -60,7 +65,7 @@ instance isForeignOptions :: IsForeign Options where , comments: _ , output: _ , noPrefix: _ - , requirePath: _ + , requirePath: "../" , src: _ , ffi: _ } <$> readProp noPreludeOpt obj @@ -69,9 +74,8 @@ instance isForeignOptions :: IsForeign Options where <*> readProp noTcoOpt obj <*> readProp verboseErrorsOpt obj <*> readProp commentsOpt obj - <*> readProp outputOpt obj + <*> (maybe "output" id <<< runNullOrUndefined <$> readProp outputOpt obj) <*> readProp noPrefixOpt obj - <*> readProp requirePathOpt obj <*> readProp srcOpt obj <*> readProp ffiOpt obj) @@ -88,19 +92,17 @@ instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where opt key val = concat (opt key <$> (NullOrUndefined <<< Just) <$> (fromMaybe [] (runNullOrUndefined val))) -pscOptions :: Foreign -> Array String -pscOptions query = either (const []) fold parsed - where parsed = read query :: F Options - fold (Options a) = opt noPreludeOpt a.noPrelude <> - opt noOptsOpt a.noOpts <> - opt noMagicDoOpt a.noMagicDo <> - opt noTcoOpt a.noTco <> - opt verboseErrorsOpt a.verboseErrors <> - opt commentsOpt a.comments <> - opt outputOpt a.output <> - opt noPrefixOpt a.noPrefix <> - opt requirePathOpt a.requirePath <> - opt ffiOpt a.ffi +pscOptions :: Options -> Array String +pscOptions (Options a) = opt noPreludeOpt a.noPrelude <> + opt noOptsOpt a.noOpts <> + opt noMagicDoOpt a.noMagicDo <> + opt noTcoOpt a.noTco <> + opt verboseErrorsOpt a.verboseErrors <> + opt commentsOpt a.comments <> + opt outputOpt (NullOrUndefined $ Just a.output) <> + opt noPrefixOpt a.noPrefix <> + opt requirePathOpt (NullOrUndefined $ Just a.requirePath) <> + opt ffiOpt a.ffi loaderSrcOption :: Foreign -> Maybe (Array String) loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) -- cgit v1.2.3