git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove Docs.Bookmarks

We don't actually need the full Bookmarks to be able to generate links between packages properly, and in fact all that Pursuit uses the pkgBookmarks field for now is to work out which package it needs to link to, given a module name. That is, all it needs is a Map ModuleName PackageName. So we can simplify and speed up the JSON generation by replacing the pkgBookmarks with such a Map. This gets us one step closer to being able to get rid of Language.PureScript.AST.Exported, refs #2130.

commit5263800052fbfc7c9136a4686757a17112198b01 authorHarry Garrood <harry@garrood.me> dateSun 8 Jan 2017, 20:17 (10 years ago) parent52ee527
9 files changed+178−194
psc-docs/Main.hs+2−2 purescript.cabal+1−1 src/Language/PureScript/Docs.hs+1−1 src/Language/PureScript/Docs/Convert.hs+40−28 src/Language/PureScript/Docs/Convert/Single.hs−13 src/Language/PureScript/Docs/ParseAndBookmark.hs−93 src/Language/PureScript/Docs/ParseInPackage.hs+73 src/Language/PureScript/Docs/Types.hs+47−29 src/Language/PureScript/Publish.hs+14−27
psc-docs/Main.hs+2−2
@@ -60,8 +60,8 @@ docgen (PSCDocsOptions fmt inputGlob output) = do
6060 Etags -> dumpTags input dumpEtags
6161 Ctags -> dumpTags input dumpCtags
6262 Markdown -> do
63− ms <- runExceptT (D.parseAndBookmark input []
64− >>= (fst >>> D.convertModulesInPackage))
63+ ms <- runExceptT (D.parseFilesInPackages input []
64+ >>= uncurry D.convertModulesInPackage)
6565 >>= successOrExit
6666
6767 case output of
purescript.cabal+1−1
@@ -268,7 +268,7 @@ library
268268 Language.PureScript.Docs.RenderedCode.Types
269269 Language.PureScript.Docs.RenderedCode.Render
270270 Language.PureScript.Docs.AsMarkdown
271− Language.PureScript.Docs.ParseAndBookmark
271+ Language.PureScript.Docs.ParseInPackage
272272 Language.PureScript.Docs.Utils.MonoidExtras
273273
274274 Language.PureScript.Publish
src/Language/PureScript/Docs.hs+1−1
@@ -8,7 +8,7 @@ module Language.PureScript.Docs (
88
99import Language.PureScript.Docs.Convert as Docs
1010import Language.PureScript.Docs.Prim as Docs
11−import Language.PureScript.Docs.ParseAndBookmark as Docs
11+import Language.PureScript.Docs.ParseInPackage as Docs
1212import Language.PureScript.Docs.Render as Docs
1313import Language.PureScript.Docs.RenderedCode.Render as Docs
1414import Language.PureScript.Docs.RenderedCode.Types as Docs
src/Language/PureScript/Docs/Convert.hs+40−28
@@ -3,28 +3,27 @@
33
44module Language.PureScript.Docs.Convert
55 ( convertModules
6+ , convertModulesWithEnv
67 , convertModulesInPackage
7− , collectBookmarks
8+ , convertModulesInPackageWithEnv
89 ) where
910
10−import Prelude.Compat
11+import Prelude (id, String)
12+import Protolude hiding (check)
1113
12−import Control.Arrow ((&&&), second)
14+import Control.Arrow ((&&&))
1315import Control.Category ((>>>))
14−import Control.Monad
15−import Control.Monad.Error.Class (MonadError)
16−import Control.Monad.State (runStateT)
1716import Control.Monad.Writer.Strict (runWriterT)
18−import Data.List (find)
1917import qualified Data.Map as Map
20−import Data.Text (Text)
2118
2219import Language.PureScript.Docs.Convert.ReExports (updateReExports)
23−import Language.PureScript.Docs.Convert.Single (convertSingleModule, collectBookmarks)
20+import Language.PureScript.Docs.Convert.Single (convertSingleModule)
2421import Language.PureScript.Docs.Types
2522import qualified Language.PureScript as P
2623import qualified Language.PureScript.Constants as C
2724
25+import Web.Bower.PackageMeta (PackageName)
26+
2827import Text.Parsec (eof)
2928
3029-- |
@@ -34,32 +33,36 @@ import Text.Parsec (eof)
3433--
3534convertModulesInPackage ::
3635 (MonadError P.MultipleErrors m) =>
37− [InPackage P.Module] ->
36+ [P.Module] ->
37+ Map P.ModuleName PackageName ->
3838 m [Module]
39−convertModulesInPackage modules =
39+convertModulesInPackage modules modulesDeps =
40+ fmap fst (convertModulesInPackageWithEnv modules modulesDeps)
41+
42+convertModulesInPackageWithEnv ::
43+ (MonadError P.MultipleErrors m) =>
44+ [P.Module] ->
45+ Map P.ModuleName PackageName ->
46+ m ([Module], P.Env)
47+convertModulesInPackageWithEnv modules modulesDeps =
4048 go modules
4149 where
42− localNames =
43− map P.getModuleName (takeLocals modules)
4450 go =
45− map ignorePackage
46− >>> convertModules withPackage
47− >>> fmap (filter ((`elem` localNames) . modName))
51+ convertModulesWithEnv withPackage
52+ >>> fmap (first (filter (isLocal . modName)))
4853
4954 withPackage :: P.ModuleName -> InPackage P.ModuleName
5055 withPackage mn =
51− case find ((== mn) . P.getModuleName . ignorePackage) modules of
52− Just m ->
53− fmap P.getModuleName m
54− Nothing ->
55− P.internalError $ "withPackage: missing module:" ++
56− show (P.runModuleName mn)
56+ case Map.lookup mn modulesDeps of
57+ Just pkgName -> FromDep pkgName mn
58+ Nothing -> Local mn
59+
60+ isLocal :: P.ModuleName -> Bool
61+ isLocal = not . flip Map.member modulesDeps
5762
5863-- |
5964-- Convert a group of modules to the intermediate format, designed for
60−-- producing documentation from. It is also necessary to pass an Env containing
61−-- imports/exports information about the list of modules, which is needed for
62−-- documenting re-exports.
65+-- producing documentation from.
6366--
6467-- Note that the whole module dependency graph must be included in the list; if
6568-- some modules import things from other modules, then those modules must also
@@ -75,6 +78,14 @@ convertModules ::
7578 [P.Module] ->
7679 m [Module]
7780convertModules withPackage =
81+ fmap fst . convertModulesWithEnv withPackage
82+
83+convertModulesWithEnv ::
84+ (MonadError P.MultipleErrors m) =>
85+ (P.ModuleName -> InPackage P.ModuleName) ->
86+ [P.Module] ->
87+ m ([Module], P.Env)
88+convertModulesWithEnv withPackage =
7889 P.sortModules
7990 >>> fmap (fst >>> map importPrim)
8091 >=> convertSorted withPackage
@@ -83,13 +94,14 @@ importPrim :: P.Module -> P.Module
8394importPrim = P.addDefaultImport (P.ModuleName [P.ProperName C.prim])
8495
8596-- |
86−-- Convert a sorted list of modules.
97+-- Convert a sorted list of modules, returning both the list of converted
98+-- modules and the Env produced during desugaring.
8799--
88100convertSorted ::
89101 (MonadError P.MultipleErrors m) =>
90102 (P.ModuleName -> InPackage P.ModuleName) ->
91103 [P.Module] ->
92− m [Module]
104+ m ([Module], P.Env)
93105convertSorted withPackage modules = do
94106 (env, convertedModules) <- second (map convertSingleModule) <$> partiallyDesugar modules
95107
@@ -97,7 +109,7 @@ convertSorted withPackage modules = do
97109 let moduleMap = Map.fromList (map (modName &&& id) modulesWithTypes)
98110
99111 let traversalOrder = map P.getModuleName modules
100− pure (Map.elems (updateReExports env traversalOrder withPackage moduleMap))
112+ pure (Map.elems (updateReExports env traversalOrder withPackage moduleMap), env)
101113
102114-- |
103115-- If any exported value declarations have either wildcard type signatures, or
src/Language/PureScript/Docs/Convert/Single.hs−13
@@ -1,6 +1,5 @@
11module Language.PureScript.Docs.Convert.Single
22 ( convertSingleModule
3− , collectBookmarks
43 ) where
54
65import Protolude
@@ -184,15 +183,3 @@ convertComments cs = do
184183
185184 dropPrefix prefix str =
186185 fromMaybe str (T.stripPrefix prefix str)
187−
188−-- | Go through a PureScript module and extract a list of Bookmarks; references
189−-- to data types or values, to be used as a kind of index. These are used for
190−-- generating links in the HTML documentation, for example.
191−collectBookmarks :: InPackage P.Module -> [Bookmark]
192−collectBookmarks (Local m) = map Local (collectBookmarks' m)
193−collectBookmarks (FromDep pkg m) = map (FromDep pkg) (collectBookmarks' m)
194−
195−collectBookmarks' :: P.Module -> [(P.ModuleName, Text)]
196−collectBookmarks' m =
197− map (P.getModuleName m, )
198− (mapMaybe getDeclarationTitle (P.exportedDeclarations m))
src/Language/PureScript/Docs/ParseAndBookmark.hsdeleted−93
@@ -1,93 +0,0 @@
1−module Language.PureScript.Docs.ParseAndBookmark
2− ( parseAndBookmark
3− ) where
4−
5−import Protolude
6−import Prelude (id)
7−
8−import qualified Data.Map as M
9−
10−import Language.PureScript.Docs.Convert (collectBookmarks)
11−import Language.PureScript.Docs.Types
12−import qualified Language.PureScript as P
13−import System.IO.UTF8 (readUTF8FileT)
14−import Web.Bower.PackageMeta (PackageName)
15−
16−-- |
17−-- Given:
18−--
19−-- * A list of local source files
20−-- * A list of source files from external dependencies, together with their
21−-- package names
22−--
23−-- This function does the following:
24−--
25−-- * Parse all of the input and dependency source files
26−-- * Associate each dependency module with its package name, thereby
27−-- distinguishing these from local modules
28−-- * Collect a list of bookmarks from the whole set of source files
29−-- * Return the parsed modules and the bookmarks
30−parseAndBookmark ::
31− (MonadError P.MultipleErrors m, MonadIO m) =>
32− [FilePath]
33− -> [(PackageName, FilePath)]
34− -> m ([InPackage P.Module], [Bookmark])
35−parseAndBookmark inputFiles depsFiles = do
36− inputFiles' <- traverse (parseAs Local) inputFiles
37− depsFiles' <- traverse (\(pkgName, f) -> parseAs (FromDep pkgName) f) depsFiles
38−
39− addBookmarks <$> parseFiles (inputFiles' ++ depsFiles')
40−
41−parseFiles ::
42− (MonadError P.MultipleErrors m) =>
43− [(FileInfo, Text)]
44− -> m [(FileInfo, P.Module)]
45−parseFiles =
46− throwLeft . P.parseModulesFromFiles fileInfoToString
47−
48−addBookmarks ::
49− [(FileInfo, P.Module)]
50− -> ([InPackage P.Module], [Bookmark])
51−addBookmarks msInfo =
52− let
53− msDeps = getDepsModuleNames (map (\(fp, m) -> (,m) <$> fp) msInfo)
54− msPackages = map (addPackage msDeps . snd) msInfo
55− bookmarks = concatMap collectBookmarks msPackages
56− in
57− (msPackages, bookmarks)
58−
59−throwLeft :: (MonadError l m) => Either l r -> m r
60−throwLeft = either throwError return
61−
62−-- | Specifies whether a PureScript source file is considered as:
63−--
64−-- 1) with the `Local` constructor, a target source file, i.e., we want to see
65−-- its modules in the output
66−-- 2) with the `FromDep` constructor, a dependencies source file, i.e. we do
67−-- not want its modules in the output; it is there to enable desugaring, and
68−-- to ensure that links between modules are constructed correctly.
69−type FileInfo = InPackage FilePath
70−
71−fileInfoToString :: FileInfo -> FilePath
72−fileInfoToString (Local fn) = fn
73−fileInfoToString (FromDep _ fn) = fn
74−
75−parseFile :: FilePath -> IO (FilePath, Text)
76−parseFile input' = (,) input' <$> readUTF8FileT input'
77−
78−parseAs :: (MonadIO m) => (FilePath -> a) -> FilePath -> m (a, Text)
79−parseAs g = fmap (first g) . liftIO . parseFile
80−
81−getDepsModuleNames :: [InPackage (FilePath, P.Module)] -> M.Map P.ModuleName PackageName
82−getDepsModuleNames = foldl' go M.empty
83− where
84− go deps p = deps # case p of
85− Local _ -> id
86− FromDep pkgName (_, m) -> M.insert (P.getModuleName m) pkgName
87− (#) = flip ($)
88−
89−addPackage :: M.Map P.ModuleName PackageName -> P.Module -> InPackage P.Module
90−addPackage depsModules m =
91− case M.lookup (P.getModuleName m) depsModules of
92− Just pkgName -> FromDep pkgName m
93− Nothing -> Local m
src/Language/PureScript/Docs/ParseInPackage.hsnew file+73
@@ -0,0 +1,73 @@
1+module Language.PureScript.Docs.ParseInPackage
2+ ( parseFilesInPackages
3+ ) where
4+
5+import Protolude
6+
7+import qualified Data.Map as M
8+
9+import Language.PureScript.Docs.Types
10+import qualified Language.PureScript as P
11+import System.IO.UTF8 (readUTF8FileT)
12+import Web.Bower.PackageMeta (PackageName)
13+
14+-- |
15+-- Given:
16+--
17+-- * A list of local source files
18+-- * A list of source files from external dependencies, together with their
19+-- package names
20+--
21+-- This function does the following:
22+--
23+-- * Parse all of the input and dependency source files
24+-- * Associate each dependency module with its package name, thereby
25+-- distinguishing these from local modules
26+-- * Return the parsed modules and a Map mapping module names to package
27+-- names for modules which come from dependencies. If a module does not
28+-- exist in the map, it can safely be assumed to be local.
29+parseFilesInPackages ::
30+ (MonadError P.MultipleErrors m, MonadIO m) =>
31+ [FilePath]
32+ -> [(PackageName, FilePath)]
33+ -> m ([P.Module], Map P.ModuleName PackageName)
34+parseFilesInPackages inputFiles depsFiles = do
35+ inputFiles' <- traverse (readFileAs . Local) inputFiles
36+ depsFiles' <- traverse (readFileAs . uncurry FromDep) depsFiles
37+
38+ modules <- parse (inputFiles' ++ depsFiles')
39+
40+ let mnMap = M.fromList (mapMaybe (\(inpkg, m) -> (P.getModuleName m,) <$> inPkgToMaybe inpkg) modules)
41+
42+ pure (map snd modules, mnMap)
43+
44+ where
45+ parse ::
46+ (MonadError P.MultipleErrors m) =>
47+ [(FileInfo, Text)]
48+ -> m [(FileInfo, P.Module)]
49+ parse =
50+ throwLeft . P.parseModulesFromFiles fileInfoToString
51+
52+ inPkgToMaybe = \case
53+ Local _ -> Nothing
54+ FromDep pkgName _ -> Just pkgName
55+
56+throwLeft :: (MonadError l m) => Either l r -> m r
57+throwLeft = either throwError return
58+
59+-- | Specifies whether a PureScript source file is considered as:
60+--
61+-- 1) with the `Local` constructor, a target source file, i.e., we want to see
62+-- its modules in the output
63+-- 2) with the `FromDep` constructor, a dependencies source file, i.e. we do
64+-- not want its modules in the output; it is there to enable desugaring, and
65+-- to ensure that links between modules are constructed correctly.
66+type FileInfo = InPackage FilePath
67+
68+fileInfoToString :: FileInfo -> FilePath
69+fileInfoToString (Local fn) = fn
70+fileInfoToString (FromDep _ fn) = fn
71+
72+readFileAs :: (MonadIO m) => FileInfo -> m (FileInfo, Text)
73+readFileAs fi = liftIO . fmap ((fi,)) $ readUTF8FileT (ignorePackage fi)
src/Language/PureScript/Docs/Types.hs+47−29
@@ -4,19 +4,14 @@ module Language.PureScript.Docs.Types
44 )
55 where
66
7−import Prelude.Compat
7+import Protolude hiding (to, from)
8+import Prelude (String, unlines)
89
9−import Control.Arrow (first, (***))
10−import Control.Monad (when)
11−import Control.Monad.Error.Class (catchError)
10+import Control.Arrow ((***))
1211
1312import Data.Aeson ((.=))
1413import Data.Aeson.BetterErrors
15−import Data.ByteString.Lazy (ByteString)
16−import Data.Either (isLeft, isRight)
17−import Data.Maybe (mapMaybe, fromMaybe, maybeToList)
18−import Data.Monoid ((<>))
19−import Data.Text (Text)
14+import qualified Data.Map as Map
2015import Data.Time.Clock (UTCTime)
2116import qualified Data.Time.Format as TimeFormat
2217import Data.Version
@@ -47,7 +42,7 @@ data Package a = Package
4742 -- field. It should eventually be changed to just UTCTime.
4843 , pkgTagTime :: Maybe UTCTime
4944 , pkgModules :: [Module]
50− , pkgBookmarks :: [Bookmark]
45+ , pkgModuleMap :: Map P.ModuleName PackageName
5146 , pkgResolvedDependencies :: [(PackageName, Version)]
5247 , pkgGithub :: (GithubUser, GithubRepo)
5348 , pkgUploader :: a
@@ -70,7 +65,7 @@ verifyPackage verifiedUser Package{..} =
7065 pkgVersionTag
7166 pkgTagTime
7267 pkgModules
73− pkgBookmarks
68+ pkgModuleMap
7469 pkgResolvedDependencies
7570 pkgGithub
7671 verifiedUser
@@ -308,8 +303,6 @@ data PackageError
308303 | InvalidTime
309304 deriving (Show, Eq, Ord)
310305
311−type Bookmark = InPackage (P.ModuleName, Text)
312−
313306data InPackage a
314307 = Local a
315308 | FromDep PackageName a
@@ -333,10 +326,10 @@ ignorePackage (FromDep _ x) = x
333326----------------------
334327-- Parsing
335328
336−parseUploadedPackage :: Version -> ByteString -> Either (ParseError PackageError) UploadedPackage
329+parseUploadedPackage :: Version -> LByteString -> Either (ParseError PackageError) UploadedPackage
337330parseUploadedPackage minVersion = parse $ asUploadedPackage minVersion
338331
339−parseVerifiedPackage :: Version -> ByteString -> Either (ParseError PackageError) VerifiedPackage
332+parseVerifiedPackage :: Version -> LByteString -> Either (ParseError PackageError) VerifiedPackage
340333parseVerifiedPackage minVersion = parse $ asVerifiedPackage minVersion
341334
342335asPackage :: Version -> (forall e. Parse e a) -> Parse PackageError (Package a)
@@ -353,11 +346,15 @@ asPackage minimumVersion uploader = do
353346 <*> key "versionTag" asText
354347 <*> keyMay "tagTime" (withString parseTimeEither)
355348 <*> key "modules" (eachInArray asModule)
356− <*> key "bookmarks" asBookmarks .! ErrorInPackageMeta
349+ <*> moduleMap
357350 <*> key "resolvedDependencies" asResolvedDependencies
358351 <*> key "github" asGithub
359352 <*> key "uploader" uploader
360353 <*> pure compilerVersion
354+ where
355+ moduleMap =
356+ key "moduleMap" asModuleMap
357+ `pOr` (key "bookmarks" bookmarksAsModuleMap .! ErrorInPackageMeta)
361358
362359parseTimeEither :: String -> Either PackageError UTCTime
363360parseTimeEither =
@@ -444,9 +441,10 @@ asReExport =
444441 asReExportModuleName :: Parse PackageError (InPackage P.ModuleName)
445442 asReExportModuleName =
446443 asInPackage fromAesonParser .! ErrorInPackageMeta
447− <|> fmap Local fromAesonParser
444+ `pOr` fmap Local fromAesonParser
448445
449− (<|>) p q = catchError p (const q)
446+pOr :: Parse e a -> Parse e a -> Parse e a
447+p `pOr` q = catchError p (const q)
450448
451449asInPackage :: Parse BowerError a -> Parse BowerError (InPackage a)
452450asInPackage inner =
@@ -559,20 +557,38 @@ asQualifiedProperName = fromAesonParser
559557asQualifiedIdent :: Parse e (P.Qualified P.Ident)
560558asQualifiedIdent = fromAesonParser
561559
562−asBookmarks :: Parse BowerError [Bookmark]
563−asBookmarks = eachInArray asBookmark
560+asModuleMap :: Parse PackageError (Map P.ModuleName PackageName)
561+asModuleMap =
562+ Map.fromList <$>
563+ eachInObjectWithKey (Right . P.moduleNameFromString)
564+ (withText parsePackageName')
565+
566+-- This is here to preserve backwards compatibility with compilers which used
567+-- to generate a 'bookmarks' field in the JSON (i.e. up to 0.10.5). We should
568+-- remove this after the next breaking change to the JSON.
569+bookmarksAsModuleMap :: Parse BowerError (Map P.ModuleName PackageName)
570+bookmarksAsModuleMap =
571+ convert <$>
572+ eachInArray (asInPackage (nth 0 (P.moduleNameFromString <$> asText)))
573+
574+ where
575+ convert :: [InPackage P.ModuleName] -> Map P.ModuleName PackageName
576+ convert = Map.fromList . mapMaybe toTuple
564577
565−asBookmark :: Parse BowerError Bookmark
566−asBookmark =
567− asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
568− <*> nth 1 asText)
578+ toTuple (Local _) = Nothing
579+ toTuple (FromDep pkgName mn) = Just (mn, pkgName)
569580
570581asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
571582asResolvedDependencies =
572− eachInObjectWithKey (mapLeft ErrorInPackageMeta . parsePackageName) asVersion
573− where
574− mapLeft f (Left x) = Left (f x)
575− mapLeft _ (Right x) = Right x
583+ eachInObjectWithKey parsePackageName' asVersion
584+
585+parsePackageName' :: Text -> Either PackageError PackageName
586+parsePackageName' =
587+ mapLeft ErrorInPackageMeta . parsePackageName
588+
589+mapLeft :: (a -> a') -> Either a b -> Either a' b
590+mapLeft f (Left x) = Left (f x)
591+mapLeft _ (Right x) = Right x
576592
577593asGithub :: Parse e (GithubUser, GithubRepo)
578594asGithub = (,) <$> nth 0 (GithubUser <$> asText)
@@ -593,7 +609,9 @@ instance A.ToJSON a => A.ToJSON (Package a) where
593609 , "version" .= showVersion pkgVersion
594610 , "versionTag" .= pkgVersionTag
595611 , "modules" .= pkgModules
596− , "bookmarks" .= map (fmap (first P.runModuleName)) pkgBookmarks
612+ , "moduleMap" .= assocListToJSON P.runModuleName
613+ runPackageName
614+ (Map.toList pkgModuleMap)
597615 , "resolvedDependencies" .= assocListToJSON runPackageName
598616 (T.pack . showVersion)
599617 pkgResolvedDependencies
src/Language/PureScript/Publish.hs+14−27
@@ -16,30 +16,23 @@ module Language.PureScript.Publish
1616 , checkCleanWorkingTree
1717 , getVersionFromGitTag
1818 , getBowerRepositoryInfo
19− , getModulesAndBookmarks
19+ , getModules
2020 , getResolvedDependencies
2121 ) where
2222
23−import Prelude ()
24−import Prelude.Compat hiding (userError)
23+import Protolude hiding (stdin)
2524
26−import Control.Arrow ((***), first)
25+import Control.Arrow ((***))
2726import Control.Category ((>>>))
28−import Control.Exception (catch, try)
29−import Control.Monad.Error.Class (MonadError(..))
30−import Control.Monad.Trans.Except
3127import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
32−import Control.Monad.Writer.Strict
28+import Control.Monad.Writer.Strict (MonadWriter, WriterT, runWriterT, tell)
3329
3430import Data.Aeson.BetterErrors
3531import Data.Char (isSpace)
36−import Data.Foldable (traverse_)
37−import Data.Function (on)
32+import Data.String (String, lines)
3833import Data.List (stripPrefix, (\\), nubBy)
3934import Data.List.NonEmpty (NonEmpty(..))
4035import Data.List.Split (splitOn)
41−import Data.Maybe
42−import Data.Text (Text)
4336import qualified Data.Text as T
4437import qualified Data.Text.Lazy as TL
4538import qualified Data.Text.Lazy.Encoding as TL
@@ -47,10 +40,7 @@ import Data.Time.Clock (UTCTime)
4740import Data.Version
4841import qualified Data.SPDX as SPDX
4942
50−import Safe (headMay)
51−
5243import System.Directory (doesFileExist, findExecutable)
53−import System.Exit (exitFailure)
5444import System.FilePath (pathSeparator)
5545import System.Process (readProcess)
5646import qualified System.FilePath.Glob as Glob
@@ -61,7 +51,7 @@ import qualified Web.Bower.PackageMeta as Bower
6151
6252import Language.PureScript.Publish.ErrorsWarnings
6353import Language.PureScript.Publish.Utils
64−import qualified Language.PureScript as P (version)
54+import qualified Language.PureScript as P (version, ModuleName)
6555import qualified Language.PureScript.Docs as D
6656
6757data PublishOptions = PublishOptions
@@ -129,9 +119,6 @@ otherError = throwError . OtherError
129119catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
130120catchLeft a f = either f pure a
131121
132−unlessM :: Monad m => m Bool -> m () -> m ()
133−unlessM cond act = cond >>= flip unless act
134−
135122preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
136123preparePackage' opts = do
137124 unlessM (liftIO (doesFileExist "bower.json")) (userError BowerJSONNotFound)
@@ -144,7 +131,7 @@ preparePackage' opts = do
144131 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
145132 pkgTagTime <- Just <$> publishGetTagTime opts pkgVersionTag
146133 pkgGithub <- getBowerRepositoryInfo pkgMeta
147− (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
134+ (pkgModules, pkgModuleMap) <- getModules
148135
149136 let declaredDeps = map fst (bowerDependencies pkgMeta ++
150137 bowerDevDependencies pkgMeta)
@@ -155,18 +142,18 @@ preparePackage' opts = do
155142
156143 return D.Package{..}
157144
158−getModulesAndBookmarks :: PrepareM ([D.Bookmark], [D.Module])
159−getModulesAndBookmarks = do
145+getModules :: PrepareM ([D.Module], Map P.ModuleName PackageName)
146+getModules = do
160147 (inputFiles, depsFiles) <- liftIO getInputAndDepsFiles
161− (modules', bookmarks) <- parseAndBookmark inputFiles depsFiles
148+ (modules', moduleMap) <- parseFilesInPackages inputFiles depsFiles
162149
163− case runExcept (D.convertModulesInPackage modules') of
164− Right modules -> return (bookmarks, modules)
150+ case runExcept (D.convertModulesInPackage modules' moduleMap) of
151+ Right modules -> return (modules, moduleMap)
165152 Left err -> userError (CompileError err)
166153
167154 where
168− parseAndBookmark inputFiles depsFiles = do
169− r <- liftIO . runExceptT $ D.parseAndBookmark inputFiles depsFiles
155+ parseFilesInPackages inputFiles depsFiles = do
156+ r <- liftIO . runExceptT $ D.parseFilesInPackages inputFiles depsFiles
170157 case r of
171158 Right r' ->
172159 return r'