aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2015-05-02 10:30:22 -0400
committereric <thul.eric@gmail.com>2015-05-02 10:30:22 -0400
commit0af1d8ec5f4926a6ae2c7fb03db6b44f99443e35 (patch)
tree9c39c031c0489a63ff63a899e702fe4449600770
parent16cd4615f9d7828f3119b771fbc64a3417cd6651 (diff)
parentd997476f011ae50036ffcabc03af2eaf85f33967 (diff)
downloadpurs-loader-0af1d8ec5f4926a6ae2c7fb03db6b44f99443e35.tar.gz
purs-loader-0af1d8ec5f4926a6ae2c7fb03db6b44f99443e35.tar.zst
purs-loader-0af1d8ec5f4926a6ae2c7fb03db6b44f99443e35.zip
Merge pull request #10 from ethul/topic/issue-9
Topic/issue 9
-rw-r--r--bower.json3
-rw-r--r--package.json2
-rw-r--r--src/Loader.purs19
3 files changed, 16 insertions, 8 deletions
diff --git a/bower.json b/bower.json
index dddddf9..2ee2486 100644
--- a/bower.json
+++ b/bower.json
@@ -11,6 +11,7 @@
11 "purescript-tuples": "~0.3.4", 11 "purescript-tuples": "~0.3.4",
12 "purescript-maps": "~0.3.3", 12 "purescript-maps": "~0.3.3",
13 "purescript-arrays": "~0.3.7", 13 "purescript-arrays": "~0.3.7",
14 "purescript-monad-eff": "~0.1.0" 14 "purescript-monad-eff": "~0.1.0",
15 "purescript-sets": "0.3.2"
15 } 16 }
16} 17}
diff --git a/package.json b/package.json
index 9ecfd17..1e823ae 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
22 "del": "^1.1.1", 22 "del": "^1.1.1",
23 "gulp": "^3.8.11", 23 "gulp": "^3.8.11",
24 "gulp-plumber": "^1.0.0", 24 "gulp-plumber": "^1.0.0",
25 "gulp-purescript": "^0.3.1", 25 "gulp-purescript": "^0.4.2",
26 "gulp-util": "^3.0.4", 26 "gulp-util": "^3.0.4",
27 "run-sequence": "^1.0.2", 27 "run-sequence": "^1.0.2",
28 "webpack": "^1.8.4" 28 "webpack": "^1.8.4"
diff --git a/src/Loader.purs b/src/Loader.purs
index 523aa7a..aae51c0 100644
--- a/src/Loader.purs
+++ b/src/Loader.purs
@@ -9,9 +9,11 @@ import Control.Monad.Eff (Eff())
9import Control.Monad.Eff.Class (liftEff) 9import Control.Monad.Eff.Class (liftEff)
10import Control.Monad.Eff.Exception (error) 10import Control.Monad.Eff.Exception (error)
11 11
12import Data.Array ((!!), catMaybes, concat, nub, null) 12import Data.Array ((!!), catMaybes, concat, filter, null)
13import Data.Foldable (foldl)
13import Data.Function (Fn2(), mkFn2) 14import Data.Function (Fn2(), mkFn2)
14import Data.Maybe (Maybe(..), fromMaybe, maybe) 15import Data.Maybe (Maybe(..), fromMaybe, maybe)
16import Data.Set (Set(), empty, insert, member, toList, unions)
15import Data.String (joinWith, split) 17import Data.String (joinWith, split)
16import Data.String.Regex (Regex(), match, noFlags, regex) 18import Data.String.Regex (Regex(), match, noFlags, regex)
17import Data.StrMap (StrMap(), fromList, lookup) 19import Data.StrMap (StrMap(), fromList, lookup)
@@ -60,11 +62,16 @@ mkGraph files = (fromList <<< catMaybes) <$> sequence (parse <$> files)
60 return $ (\a -> tuple2 a { file: file, imports: imports }) <$> key 62 return $ (\a -> tuple2 a { file: file, imports: imports }) <$> key
61 63
62mkDeps :: forall eff. String -> Graph -> [String] 64mkDeps :: forall eff. String -> Graph -> [String]
63mkDeps key graph = nub $ go [] key 65mkDeps key graph = toList $ go empty key
64 where go acc key = 66 where
65 maybe acc (\a -> if null a.imports 67 go :: Set String -> String -> Set String
66 then acc 68 go acc key =
67 else concat $ go (acc <> a.imports) <$> a.imports) (lookup key graph) 69 let node = fromMaybe {file: "", imports: []} (lookup key graph)
70 uniq = filter (not <<< flip member acc) node.imports
71 acc' = foldl (flip insert) acc node.imports
72 in if null uniq
73 then acc'
74 else unions $ go acc' <$> uniq
68 75
69addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit 76addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit
70addDeps ref graph deps = const unit <$> (sequence $ add <$> deps) 77addDeps ref graph deps = const unit <$> (sequence $ add <$> deps)