cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit
```
-#### `query`
-
-``` purescript
-query :: LoaderRef -> String
-```
-
#### `clearDependencies`
``` purescript
## 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`
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
import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit)
-import Control.Apply ((*>))
import Control.Alt ((<|>))
import Control.Bind (join)
import Control.Monad.Eff (Eff(), foreachE)
, Loader()
, async
, cacheable
- , clearDependencies
, addDependency
, resourcePath
)
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)
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
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 =
exports.cacheable = cacheable;
-exports.query = query;
-
exports.clearDependencies = clearDependencies;
exports.resourcePath = resourcePath;
// 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);
module PursLoader.Plugin
- ( Result()
- , Compile()
+ ( Compile()
, Context()
, Options()
- , ImmutableMap()
, DependencyGraph()
- , get
, dependenciesOf
) where
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))