From 845f3ec3c5b13a47d60b9ff2be14bf41fb5c4734 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 12 Mar 2016 14:33:55 -0500 Subject: Handling dependencies --- docs/PursLoader/LoaderRef.md | 6 ------ docs/PursLoader/Plugin.md | 20 +------------------- src/PursLoader/Loader.purs | 22 ++++------------------ src/PursLoader/LoaderRef.js | 2 -- src/PursLoader/Plugin.js | 6 ------ src/PursLoader/Plugin.purs | 22 ++-------------------- 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 cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit ``` -#### `query` - -``` purescript -query :: LoaderRef -> String -``` - #### `clearDependencies` ``` 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 @@ ## Module PursLoader.Plugin -#### `Result` - -``` purescript -type Result = { srcMap :: ImmutableMap String String, ffiMap :: ImmutableMap String String, graph :: DependencyGraph } -``` - #### `Compile` ``` purescript -type Compile eff = Nullable Error -> Result -> Eff eff Unit +type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit ``` #### `Context` @@ -24,24 +18,12 @@ type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options type Options = { bundle :: Boolean, output :: String, bundleOutput :: String } ``` -#### `get` - -``` purescript -get :: forall key value. ImmutableMap key value -> key -> Maybe value -``` - #### `dependenciesOf` ``` purescript dependenciesOf :: DependencyGraph -> String -> Either Error (Array String) ``` -#### `ImmutableMap` - -``` purescript -data ImmutableMap :: * -> * -> * -``` - #### `DependencyGraph` ``` 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 import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit) -import Control.Apply ((*>)) import Control.Alt ((<|>)) import Control.Bind (join) import Control.Monad.Eff (Eff(), foreachE) @@ -27,7 +26,6 @@ import PursLoader.LoaderRef , Loader() , async , cacheable - , clearDependencies , addDependency , resourcePath ) @@ -52,9 +50,7 @@ loader ref source = do pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext compile :: AsyncCallback eff -> Plugin.Compile (Effects eff) - compile callback error' { srcMap, ffiMap, graph } = do - clearDependencies ref - + compile callback error' graph = do either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name addDependency ref (resourcePath ref) @@ -64,9 +60,8 @@ loader ref source = do where handle :: String -> Array String -> String -> Eff (Effects eff) Unit handle name' deps res = do - debug ("Adding PureScript transitive dependencies for " ++ name') - addTransitive name' - foreachE deps addTransitive + debug ("Adding PureScript dependencies for " ++ name') + foreachE deps (addDependency ref) debug "Generated loader result" debug res callback (toMaybe error') res @@ -93,16 +88,7 @@ loader ref source = do resourceDir = dirname (resourcePath ref) dependencies :: Either Error (Array String) - dependencies = - if pluginContext.options.bundle - then name >>= Plugin.dependenciesOf graph - else pure [] - - addTransitive :: String -> Eff (Effects eff) Unit - addTransitive dep = addDep (Plugin.get srcMap dep) *> addDep (Plugin.get ffiMap dep) - where - addDep :: Maybe String -> Eff (Effects eff) Unit - addDep = maybe (pure unit) (addDependency ref) + dependencies = Plugin.dependenciesOf graph (resourcePath ref) name :: Either Error String 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; exports.cacheable = cacheable; -exports.query = query; - exports.clearDependencies = clearDependencies; 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 @@ // module PursLoader.Plugin -function getFn(nothing, just, map, key) { - var value = map.get(key); - return value === undefined ? nothing : just(value); -} -exports.getFn = getFn; - function dependenciesOfFn(left, right, graph, node) { try { 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 @@ module PursLoader.Plugin - ( Result() - , Compile() + ( Compile() , Context() , Options() - , ImmutableMap() , DependencyGraph() - , get , dependenciesOf ) where @@ -16,34 +13,19 @@ import Control.Monad.Eff.Exception (Error()) import Data.Either (Either(..)) import Data.Function (Fn4(), runFn4) -import Data.Maybe (Maybe(..)) import Data.Nullable (Nullable()) -type Result = { srcMap :: ImmutableMap String String, ffiMap :: ImmutableMap String String, graph :: DependencyGraph } - -type Compile eff = Nullable Error -> Result -> Eff eff Unit +type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } type Options = { bundle :: Boolean, output :: String, bundleOutput :: String } -get :: forall key value. ImmutableMap key value -> key -> Maybe value -get = runFn4 getFn Nothing Just - dependenciesOf :: DependencyGraph -> String -> Either Error (Array String) dependenciesOf = runFn4 dependenciesOfFn Left Right -foreign import data ImmutableMap :: * -> * -> * - foreign import data DependencyGraph :: * -foreign import getFn - :: forall key value. Fn4 (Maybe value) - (value -> Maybe value) - (ImmutableMap key value) - key - (Maybe value) - foreign import dependenciesOfFn :: Fn4 (Error -> Either Error (Array String)) (Array String -> Either Error (Array String)) -- cgit v1.2.3