aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/PursLoader/Loader.purs22
-rw-r--r--src/PursLoader/LoaderRef.js2
-rw-r--r--src/PursLoader/Plugin.js6
-rw-r--r--src/PursLoader/Plugin.purs22
4 files changed, 6 insertions, 46 deletions
diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs
index 0dfa20e..402e805 100644
--- a/src/PursLoader/Loader.purs
+++ b/src/PursLoader/Loader.purs
@@ -6,7 +6,6 @@ module PursLoader.Loader
6 6
7import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit) 7import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit)
8 8
9import Control.Apply ((*>))
10import Control.Alt ((<|>)) 9import Control.Alt ((<|>))
11import Control.Bind (join) 10import Control.Bind (join)
12import Control.Monad.Eff (Eff(), foreachE) 11import Control.Monad.Eff (Eff(), foreachE)
@@ -27,7 +26,6 @@ import PursLoader.LoaderRef
27 , Loader() 26 , Loader()
28 , async 27 , async
29 , cacheable 28 , cacheable
30 , clearDependencies
31 , addDependency 29 , addDependency
32 , resourcePath 30 , resourcePath
33 ) 31 )
@@ -52,9 +50,7 @@ loader ref source = do
52 pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext 50 pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext
53 51
54 compile :: AsyncCallback eff -> Plugin.Compile (Effects eff) 52 compile :: AsyncCallback eff -> Plugin.Compile (Effects eff)
55 compile callback error' { srcMap, ffiMap, graph } = do 53 compile callback error' graph = do
56 clearDependencies ref
57
58 either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name 54 either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name
59 55
60 addDependency ref (resourcePath ref) 56 addDependency ref (resourcePath ref)
@@ -64,9 +60,8 @@ loader ref source = do
64 where 60 where
65 handle :: String -> Array String -> String -> Eff (Effects eff) Unit 61 handle :: String -> Array String -> String -> Eff (Effects eff) Unit
66 handle name' deps res = do 62 handle name' deps res = do
67 debug ("Adding PureScript transitive dependencies for " ++ name') 63 debug ("Adding PureScript dependencies for " ++ name')
68 addTransitive name' 64 foreachE deps (addDependency ref)
69 foreachE deps addTransitive
70 debug "Generated loader result" 65 debug "Generated loader result"
71 debug res 66 debug res
72 callback (toMaybe error') res 67 callback (toMaybe error') res
@@ -93,16 +88,7 @@ loader ref source = do
93 resourceDir = dirname (resourcePath ref) 88 resourceDir = dirname (resourcePath ref)
94 89
95 dependencies :: Either Error (Array String) 90 dependencies :: Either Error (Array String)
96 dependencies = 91 dependencies = Plugin.dependenciesOf graph (resourcePath ref)
97 if pluginContext.options.bundle
98 then name >>= Plugin.dependenciesOf graph
99 else pure []
100
101 addTransitive :: String -> Eff (Effects eff) Unit
102 addTransitive dep = addDep (Plugin.get srcMap dep) *> addDep (Plugin.get ffiMap dep)
103 where
104 addDep :: Maybe String -> Eff (Effects eff) Unit
105 addDep = maybe (pure unit) (addDependency ref)
106 92
107 name :: Either Error String 93 name :: Either Error String
108 name = 94 name =
diff --git a/src/PursLoader/LoaderRef.js b/src/PursLoader/LoaderRef.js
index e92c72c..a5d8e1f 100644
--- a/src/PursLoader/LoaderRef.js
+++ b/src/PursLoader/LoaderRef.js
@@ -43,8 +43,6 @@ exports.asyncFn = asyncFn;
43 43
44exports.cacheable = cacheable; 44exports.cacheable = cacheable;
45 45
46exports.query = query;
47
48exports.clearDependencies = clearDependencies; 46exports.clearDependencies = clearDependencies;
49 47
50exports.resourcePath = resourcePath; 48exports.resourcePath = resourcePath;
diff --git a/src/PursLoader/Plugin.js b/src/PursLoader/Plugin.js
index 90feb33..ded6df5 100644
--- a/src/PursLoader/Plugin.js
+++ b/src/PursLoader/Plugin.js
@@ -2,12 +2,6 @@
2 2
3// module PursLoader.Plugin 3// module PursLoader.Plugin
4 4
5function getFn(nothing, just, map, key) {
6 var value = map.get(key);
7 return value === undefined ? nothing : just(value);
8}
9exports.getFn = getFn;
10
11function dependenciesOfFn(left, right, graph, node) { 5function dependenciesOfFn(left, right, graph, node) {
12 try { 6 try {
13 var dependencies = graph.dependenciesOf(node); 7 var dependencies = graph.dependenciesOf(node);
diff --git a/src/PursLoader/Plugin.purs b/src/PursLoader/Plugin.purs
index 520c786..c798c83 100644
--- a/src/PursLoader/Plugin.purs
+++ b/src/PursLoader/Plugin.purs
@@ -1,11 +1,8 @@
1module PursLoader.Plugin 1module PursLoader.Plugin
2 ( Result() 2 ( Compile()
3 , Compile()
4 , Context() 3 , Context()
5 , Options() 4 , Options()
6 , ImmutableMap()
7 , DependencyGraph() 5 , DependencyGraph()
8 , get
9 , dependenciesOf 6 , dependenciesOf
10 ) where 7 ) where
11 8
@@ -16,34 +13,19 @@ import Control.Monad.Eff.Exception (Error())
16 13
17import Data.Either (Either(..)) 14import Data.Either (Either(..))
18import Data.Function (Fn4(), runFn4) 15import Data.Function (Fn4(), runFn4)
19import Data.Maybe (Maybe(..))
20import Data.Nullable (Nullable()) 16import Data.Nullable (Nullable())
21 17
22type Result = { srcMap :: ImmutableMap String String, ffiMap :: ImmutableMap String String, graph :: DependencyGraph } 18type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit
23
24type Compile eff = Nullable Error -> Result -> Eff eff Unit
25 19
26type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } 20type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options }
27 21
28type Options = { bundle :: Boolean, output :: String, bundleOutput :: String } 22type Options = { bundle :: Boolean, output :: String, bundleOutput :: String }
29 23
30get :: forall key value. ImmutableMap key value -> key -> Maybe value
31get = runFn4 getFn Nothing Just
32
33dependenciesOf :: DependencyGraph -> String -> Either Error (Array String) 24dependenciesOf :: DependencyGraph -> String -> Either Error (Array String)
34dependenciesOf = runFn4 dependenciesOfFn Left Right 25dependenciesOf = runFn4 dependenciesOfFn Left Right
35 26
36foreign import data ImmutableMap :: * -> * -> *
37
38foreign import data DependencyGraph :: * 27foreign import data DependencyGraph :: *
39 28
40foreign import getFn
41 :: forall key value. Fn4 (Maybe value)
42 (value -> Maybe value)
43 (ImmutableMap key value)
44 key
45 (Maybe value)
46
47foreign import dependenciesOfFn 29foreign import dependenciesOfFn
48 :: Fn4 (Error -> Either Error (Array String)) 30 :: Fn4 (Error -> Either Error (Array String))
49 (Array String -> Either Error (Array String)) 31 (Array String -> Either Error (Array String))