diff options
Diffstat (limited to 'src/PursLoader')
-rw-r--r-- | src/PursLoader/Loader.purs | 22 | ||||
-rw-r--r-- | src/PursLoader/LoaderRef.js | 2 | ||||
-rw-r--r-- | src/PursLoader/Plugin.js | 6 | ||||
-rw-r--r-- | src/PursLoader/Plugin.purs | 22 |
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 | ||
7 | import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit) | 7 | import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit) |
8 | 8 | ||
9 | import Control.Apply ((*>)) | ||
10 | import Control.Alt ((<|>)) | 9 | import Control.Alt ((<|>)) |
11 | import Control.Bind (join) | 10 | import Control.Bind (join) |
12 | import Control.Monad.Eff (Eff(), foreachE) | 11 | import 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 | ||
44 | exports.cacheable = cacheable; | 44 | exports.cacheable = cacheable; |
45 | 45 | ||
46 | exports.query = query; | ||
47 | |||
48 | exports.clearDependencies = clearDependencies; | 46 | exports.clearDependencies = clearDependencies; |
49 | 47 | ||
50 | exports.resourcePath = resourcePath; | 48 | exports.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 | ||
5 | function getFn(nothing, just, map, key) { | ||
6 | var value = map.get(key); | ||
7 | return value === undefined ? nothing : just(value); | ||
8 | } | ||
9 | exports.getFn = getFn; | ||
10 | |||
11 | function dependenciesOfFn(left, right, graph, node) { | 5 | function 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 @@ | |||
1 | module PursLoader.Plugin | 1 | module 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 | ||
17 | import Data.Either (Either(..)) | 14 | import Data.Either (Either(..)) |
18 | import Data.Function (Fn4(), runFn4) | 15 | import Data.Function (Fn4(), runFn4) |
19 | import Data.Maybe (Maybe(..)) | ||
20 | import Data.Nullable (Nullable()) | 16 | import Data.Nullable (Nullable()) |
21 | 17 | ||
22 | type Result = { srcMap :: ImmutableMap String String, ffiMap :: ImmutableMap String String, graph :: DependencyGraph } | 18 | type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit |
23 | |||
24 | type Compile eff = Nullable Error -> Result -> Eff eff Unit | ||
25 | 19 | ||
26 | type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } | 20 | type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } |
27 | 21 | ||
28 | type Options = { bundle :: Boolean, output :: String, bundleOutput :: String } | 22 | type Options = { bundle :: Boolean, output :: String, bundleOutput :: String } |
29 | 23 | ||
30 | get :: forall key value. ImmutableMap key value -> key -> Maybe value | ||
31 | get = runFn4 getFn Nothing Just | ||
32 | |||
33 | dependenciesOf :: DependencyGraph -> String -> Either Error (Array String) | 24 | dependenciesOf :: DependencyGraph -> String -> Either Error (Array String) |
34 | dependenciesOf = runFn4 dependenciesOfFn Left Right | 25 | dependenciesOf = runFn4 dependenciesOfFn Left Right |
35 | 26 | ||
36 | foreign import data ImmutableMap :: * -> * -> * | ||
37 | |||
38 | foreign import data DependencyGraph :: * | 27 | foreign import data DependencyGraph :: * |
39 | 28 | ||
40 | foreign import getFn | ||
41 | :: forall key value. Fn4 (Maybe value) | ||
42 | (value -> Maybe value) | ||
43 | (ImmutableMap key value) | ||
44 | key | ||
45 | (Maybe value) | ||
46 | |||
47 | foreign import dependenciesOfFn | 29 | foreign 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)) |