aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bower.json3
-rw-r--r--docs/PursLoader/Loader.md12
-rw-r--r--docs/PursLoader/Plugin.md2
-rw-r--r--src/PursLoader/Loader.purs40
-rw-r--r--src/PursLoader/Plugin.purs2
5 files changed, 40 insertions, 19 deletions
diff --git a/bower.json b/bower.json
index 761c24c..681612d 100644
--- a/bower.json
+++ b/bower.json
@@ -5,6 +5,7 @@
5 "purescript-aff": "^0.13.0", 5 "purescript-aff": "^0.13.0",
6 "purescript-foreign": "^0.7.0", 6 "purescript-foreign": "^0.7.0",
7 "purescript-unsafe-coerce": "~0.1.0", 7 "purescript-unsafe-coerce": "~0.1.0",
8 "purescript-nullable": "~0.2.1" 8 "purescript-nullable": "~0.2.1",
9 "purescript-node-process": "~0.4.1"
9 } 10 }
10} 11}
diff --git a/docs/PursLoader/Loader.md b/docs/PursLoader/Loader.md
index bb02470..d05e3b7 100644
--- a/docs/PursLoader/Loader.md
+++ b/docs/PursLoader/Loader.md
@@ -3,19 +3,25 @@
3#### `Effects` 3#### `Effects`
4 4
5``` purescript 5``` purescript
6type Effects eff = (loader :: Loader | eff) 6type Effects eff = (console :: CONSOLE, err :: EXCEPTION | eff)
7```
8
9#### `Effects_`
10
11``` purescript
12type Effects_ eff = Effects (loader :: Loader | eff)
7``` 13```
8 14
9#### `loader` 15#### `loader`
10 16
11``` purescript 17``` purescript
12loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit 18loader :: forall eff. LoaderRef -> String -> Eff (Effects_ eff) Unit
13``` 19```
14 20
15#### `loaderFn` 21#### `loaderFn`
16 22
17``` purescript 23``` purescript
18loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) 24loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects_ eff) Unit)
19``` 25```
20 26
21 27
diff --git a/docs/PursLoader/Plugin.md b/docs/PursLoader/Plugin.md
index 7a524da..9f9f852 100644
--- a/docs/PursLoader/Plugin.md
+++ b/docs/PursLoader/Plugin.md
@@ -3,7 +3,7 @@
3#### `Compile` 3#### `Compile`
4 4
5``` purescript 5``` purescript
6type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit 6type Compile eff = Nullable Error -> DependencyGraph -> String -> Eff eff Unit
7``` 7```
8 8
9#### `Context` 9#### `Context`
diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs
index 402e805..c50c63c 100644
--- a/src/PursLoader/Loader.purs
+++ b/src/PursLoader/Loader.purs
@@ -1,23 +1,28 @@
1module PursLoader.Loader 1module PursLoader.Loader
2 ( Effects() 2 ( Effects()
3 , Effects_()
3 , loader 4 , loader
4 , loaderFn 5 , loaderFn
5 ) where 6 ) where
6 7
7import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit) 8import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit, void)
8 9
9import Control.Alt ((<|>))
10import Control.Bind (join) 10import Control.Bind (join)
11import Control.Monad.Eff (Eff(), foreachE) 11import Control.Monad.Eff (Eff(), foreachE)
12import Control.Monad.Eff.Exception (Error(), error) 12import Control.Monad.Eff.Console (CONSOLE())
13import Control.Monad.Eff.Exception (EXCEPTION(), Error(), error, message)
13 14
14import Data.Array ((!!)) 15import Data.Array ((!!))
15import Data.Either (Either(..), either) 16import Data.Either (Either(..), either)
16import Data.Function (Fn2(), mkFn2) 17import Data.Function (Fn2(), mkFn2)
17import Data.Maybe (Maybe(..), maybe) 18import Data.Maybe (maybe)
18import Data.Nullable (toMaybe) 19import Data.Nullable (toMaybe)
19import Data.String.Regex (Regex(), match, noFlags, regex) 20import Data.String.Regex (Regex(), match, noFlags, regex)
20 21
22import Node.Encoding (Encoding(UTF8))
23import Node.Process (stderr)
24import Node.Stream (writeString)
25
21import Unsafe.Coerce (unsafeCoerce) 26import Unsafe.Coerce (unsafeCoerce)
22 27
23import PursLoader.LoaderRef 28import PursLoader.LoaderRef
@@ -34,9 +39,11 @@ import PursLoader.Debug (debug)
34import PursLoader.Path (dirname, joinPath, relative) 39import PursLoader.Path (dirname, joinPath, relative)
35import PursLoader.Plugin as Plugin 40import PursLoader.Plugin as Plugin
36 41
37type Effects eff = (loader :: Loader | eff) 42type Effects eff = (console :: CONSOLE, err :: EXCEPTION | eff)
43
44type Effects_ eff = Effects (loader :: Loader | eff)
38 45
39loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit 46loader :: forall eff. LoaderRef -> String -> Eff (Effects_ eff) Unit
40loader ref source = do 47loader ref source = do
41 callback <- async ref 48 callback <- async ref
42 49
@@ -46,25 +53,32 @@ loader ref source = do
46 53
47 pluginContext.compile (compile callback) 54 pluginContext.compile (compile callback)
48 where 55 where
49 pluginContext :: Plugin.Context (Effects eff) 56 pluginContext :: Plugin.Context (Effects_ eff)
50 pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext 57 pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext
51 58
52 compile :: AsyncCallback eff -> Plugin.Compile (Effects eff) 59 compile :: AsyncCallback (Effects eff) -> Plugin.Compile (Effects_ eff)
53 compile callback error' graph = do 60 compile callback error' graph output = do
54 either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name 61 either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name
55 62
56 addDependency ref (resourcePath ref) 63 addDependency ref (resourcePath ref)
57 64
58 either (\err -> callback (toMaybe error' <|> Just err) "") id 65 void $ writeString stderr UTF8 output (pure unit)
66
67 maybe (pure unit) (\a -> void $ writeString stderr UTF8 (message a) (pure unit)) (toMaybe error')
68
69 either (const $ callback (pure fixedError) "") id
59 (handle <$> name <*> dependencies <*> exports) 70 (handle <$> name <*> dependencies <*> exports)
60 where 71 where
61 handle :: String -> Array String -> String -> Eff (Effects eff) Unit 72 fixedError :: Error
73 fixedError = error "PureScript compilation has failed."
74
75 handle :: String -> Array String -> String -> Eff (Effects_ eff) Unit
62 handle name' deps res = do 76 handle name' deps res = do
63 debug ("Adding PureScript dependencies for " ++ name') 77 debug ("Adding PureScript dependencies for " ++ name')
64 foreachE deps (addDependency ref) 78 foreachE deps (addDependency ref)
65 debug "Generated loader result" 79 debug "Generated loader result"
66 debug res 80 debug res
67 callback (toMaybe error') res 81 callback (const fixedError <$> toMaybe error') res
68 82
69 exports :: Either Error String 83 exports :: Either Error String
70 exports = 84 exports =
@@ -98,5 +112,5 @@ loader ref source = do
98 re :: Regex 112 re :: Regex
99 re = regex "(?:^|\\n)module\\s+([\\w\\.]+)" noFlags { ignoreCase = true } 113 re = regex "(?:^|\\n)module\\s+([\\w\\.]+)" noFlags { ignoreCase = true }
100 114
101loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) 115loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects_ eff) Unit)
102loaderFn = mkFn2 loader 116loaderFn = mkFn2 loader
diff --git a/src/PursLoader/Plugin.purs b/src/PursLoader/Plugin.purs
index c798c83..8bb53be 100644
--- a/src/PursLoader/Plugin.purs
+++ b/src/PursLoader/Plugin.purs
@@ -15,7 +15,7 @@ import Data.Either (Either(..))
15import Data.Function (Fn4(), runFn4) 15import Data.Function (Fn4(), runFn4)
16import Data.Nullable (Nullable()) 16import Data.Nullable (Nullable())
17 17
18type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit 18type Compile eff = Nullable Error -> DependencyGraph -> String -> Eff eff Unit
19 19
20type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } 20type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options }
21 21