aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/Loader.purs
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2015-08-11 20:57:07 -0400
committereric thul <thul.eric@gmail.com>2015-08-11 20:57:07 -0400
commit03b840cb5fb8ff5217fefc9e1240a3131db309fc (patch)
tree6183f4453aa15ad67ee0249fb8d35702cef5ecad /src/PursLoader/Loader.purs
parentfa01c5a4cb42d80ac147dc5ab512a0795dbe14da (diff)
downloadpurs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.tar.gz
purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.tar.zst
purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.zip
PureScript 0.7 updates and migration to pulp
Diffstat (limited to 'src/PursLoader/Loader.purs')
-rw-r--r--src/PursLoader/Loader.purs19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs
index e9e03c4..5373d2f 100644
--- a/src/PursLoader/Loader.purs
+++ b/src/PursLoader/Loader.purs
@@ -4,6 +4,8 @@ module PursLoader.Loader
4 , loaderFn 4 , loaderFn
5 ) where 5 ) where
6 6
7import Prelude (Unit(), ($), (<>), (>>=), (<$>), (++), bind, flip, id, pure, return, unit)
8
7import Control.Monad.Aff (Aff(), runAff) 9import Control.Monad.Aff (Aff(), runAff)
8import Control.Monad.Eff (Eff()) 10import Control.Monad.Eff (Eff())
9import Control.Monad.Eff.Class (liftEff) 11import Control.Monad.Eff.Class (liftEff)
@@ -36,18 +38,11 @@ psciFilename = ".psci"
36 38
37(!!!) = flip (!!) 39(!!!) = flip (!!)
38 40
39foreign import cwd "var cwd = process.cwd();" :: String 41foreign import cwd :: String
40 42
41foreign import relative """ 43foreign import relative :: String -> String -> String
42function relative(from) {
43 return function(to){
44 var path = require('path');
45 return path.relative(from, to);
46 };
47}
48""" :: String -> String -> String
49 44
50mkPsci :: [[String]] -> [[String]] -> String 45mkPsci :: Array (Array String) -> Array (Array String) -> String
51mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) 46mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis))
52 where 47 where
53 loadModule :: String -> String 48 loadModule :: String -> String
@@ -56,7 +51,7 @@ mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <
56 loadForeign :: String -> String 51 loadForeign :: String -> String
57 loadForeign a = ":f " ++ relative cwd a 52 loadForeign a = ":f " ++ relative cwd a
58 53
59findFFI :: forall eff. [[String]] -> String -> Aff (fs :: FS | eff) (Maybe String) 54findFFI :: forall eff. Array (Array String) -> String -> Aff (fs :: FS | eff) (Maybe String)
60findFFI ffiss name = findFileUtf8 re (concat ffiss) 55findFFI ffiss name = findFileUtf8 re (concat ffiss)
61 where 56 where
62 re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags 57 re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags
@@ -79,7 +74,7 @@ loader' ref source = do
79 74
80 writeFileUtf8 psciFilename psciFile 75 writeFileUtf8 psciFilename psciFile
81 76
82 let moduleName = match moduleRegex source >>= (!!!) 1 77 let moduleName = match moduleRegex source >>= (!!!) 1 >>= id
83 hasForeign = test foreignRegex source 78 hasForeign = test foreignRegex source
84 result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName 79 result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName
85 80