aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/PursLoader/LoaderRef.md6
-rw-r--r--docs/PursLoader/Plugin.md20
-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
6 files changed, 7 insertions, 71 deletions
diff --git a/docs/PursLoader/LoaderRef.md b/docs/PursLoader/LoaderRef.md
index 60341f7..917db3a 100644
--- a/docs/PursLoader/LoaderRef.md
+++ b/docs/PursLoader/LoaderRef.md
@@ -30,12 +30,6 @@ async :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> S
30cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit 30cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit
31``` 31```
32 32
33#### `query`
34
35``` purescript
36query :: LoaderRef -> String
37```
38
39#### `clearDependencies` 33#### `clearDependencies`
40 34
41``` purescript 35``` purescript
diff --git a/docs/PursLoader/Plugin.md b/docs/PursLoader/Plugin.md
index 26e3f26..7a524da 100644
--- a/docs/PursLoader/Plugin.md
+++ b/docs/PursLoader/Plugin.md
@@ -1,15 +1,9 @@
1## Module PursLoader.Plugin 1## Module PursLoader.Plugin
2 2
3#### `Result`
4
5``` purescript
6type Result = { srcMap :: ImmutableMap String String, ffiMap :: ImmutableMap String String, graph :: DependencyGraph }
7```
8
9#### `Compile` 3#### `Compile`
10 4
11``` purescript 5``` purescript
12type Compile eff = Nullable Error -> Result -> Eff eff Unit 6type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit
13``` 7```
14 8
15#### `Context` 9#### `Context`
@@ -24,24 +18,12 @@ type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options
24type Options = { bundle :: Boolean, output :: String, bundleOutput :: String } 18type Options = { bundle :: Boolean, output :: String, bundleOutput :: String }
25``` 19```
26 20
27#### `get`
28
29``` purescript
30get :: forall key value. ImmutableMap key value -> key -> Maybe value
31```
32
33#### `dependenciesOf` 21#### `dependenciesOf`
34 22
35``` purescript 23``` purescript
36dependenciesOf :: DependencyGraph -> String -> Either Error (Array String) 24dependenciesOf :: DependencyGraph -> String -> Either Error (Array String)
37``` 25```
38 26
39#### `ImmutableMap`
40
41``` purescript
42data ImmutableMap :: * -> * -> *
43```
44
45#### `DependencyGraph` 27#### `DependencyGraph`
46 28
47``` purescript 29``` purescript
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))