diff --git a/bin/src/Main.purs b/bin/src/Main.purs index 5cb1efb3b..e3e15d819 100644 --- a/bin/src/Main.purs +++ b/bin/src/Main.purs @@ -34,7 +34,7 @@ import Spago.Command.Fetch as Fetch import Spago.Command.Graph (GraphModulesArgs, GraphPackagesArgs) import Spago.Command.Graph as Graph import Spago.Command.Init as Init -import Spago.Command.Ls (LsDepsArgs, LsPackagesArgs) +import Spago.Command.Ls (LsPathsArgs, LsDepsArgs, LsPackagesArgs) import Spago.Command.Ls as Ls import Spago.Command.Publish as Publish import Spago.Command.Registry (RegistryInfoArgs, RegistrySearchArgs, RegistryPackageSetsArgs) @@ -178,6 +178,7 @@ data Command a | Fetch FetchArgs | Init InitArgs | Install InstallArgs + | LsPaths LsPathsArgs | LsDeps LsDepsArgs | LsPackages LsPackagesArgs | Publish PublishArgs @@ -230,6 +231,7 @@ argParser = ( O.hsubparser $ Foldable.fold [ commandParser "packages" (LsPackages <$> lsPackagesArgsParser) "List packages available in the local package set" , commandParser "deps" (LsDeps <$> lsDepsArgsParser) "List dependencies of the project" + , commandParser "paths" (LsPaths <$> lsPathsArgsParser) "List the paths used by Spago" ] ) (O.progDesc "List packages or dependencies") @@ -433,6 +435,11 @@ graphPackagesArgsParser = Optparse.fromRecord , topo: Flags.topo } +lsPathsArgsParser :: Parser LsPathsArgs +lsPathsArgsParser = Optparse.fromRecord + { json: Flags.json + } + lsPackagesArgsParser :: Parser LsPackagesArgs lsPackagesArgsParser = Optparse.fromRecord { json: Flags.json @@ -599,6 +606,8 @@ main = runSpago buildEnv (Build.run options) testEnv <- runSpago env (mkTestEnv args buildEnv) runSpago testEnv Test.run + LsPaths args -> do + runSpago { logOptions } $ Ls.listPaths args LsPackages args -> do let fetchArgs = { packages: mempty, selectedPackage: Nothing, ensureRanges: false, testDeps: false } { env: env@{ workspace }, fetchOpts } <- mkFetchEnv offline fetchArgs @@ -960,7 +969,7 @@ mkRegistryEnv offline = do -- Now that we are up to date with the Registry we init/refresh the database db <- liftEffect $ Db.connect - { database: Db.databasePath + { database: Paths.databasePath , logger: \str -> Reader.runReaderT (logDebug $ "DB: " <> str) { logOptions } } Registry.updatePackageSetsDb db diff --git a/src/Spago/Command/Ls.purs b/src/Spago/Command/Ls.purs index 029a9be78..3439b053f 100644 --- a/src/Spago/Command/Ls.purs +++ b/src/Spago/Command/Ls.purs @@ -1,10 +1,19 @@ -module Spago.Command.Ls (listPackages, listPackageSet, LsEnv(..), LsDepsArgs, LsPackagesArgs) where +module Spago.Command.Ls + ( listPaths + , listPackages + , listPackageSet + , LsEnv(..) + , LsPathsArgs + , LsDepsArgs + , LsPackagesArgs + ) where import Spago.Prelude import Data.Codec.Argonaut as CA +import Data.Codec.Argonaut.Common as CAC import Data.Codec.Argonaut.Record as CAR -import Data.Foldable (elem) +import Data.Foldable (elem, traverse_) import Data.Map (filterKeys) import Data.Map as Map import Data.Tuple.Nested (type (/\)) @@ -15,6 +24,7 @@ import Registry.Version as Version import Spago.Command.Fetch as Fetch import Spago.Config (Package(..), PackageSet(..), Workspace, WorkspacePackage) import Spago.Config as Config +import Spago.Paths as Paths import Type.Proxy (Proxy(..)) type LsPackagesArgs = @@ -32,6 +42,10 @@ type LsDepsOpts = , transitive :: Boolean } +type LsPathsArgs = + { json :: Boolean + } + type LsSetEnv = { dependencies :: Fetch.PackageTransitiveDeps , logOptions :: LogOptions @@ -45,6 +59,28 @@ type LsEnv = , selected :: WorkspacePackage } +listPaths :: LsPathsArgs -> Spago { logOptions :: LogOptions } Unit +listPaths { json } = do + logDebug "Running `listPaths`" + case json of + true -> + output $ OutputJson (CAC.map CA.string CA.string) $ Map.fromFoldable keyValuePairs + false -> + output $ OutputTable + { titles: [ "Name", "Path" ] + , rows: (\(Tuple k v) -> [ k, v ]) <$> keyValuePairs + } + where + keyValuePairs = + [ Tuple "Global cache path" Paths.globalCachePath + , Tuple "Global registry path" Paths.registryPath + , Tuple "Global registry index path" Paths.registryIndexPath + , Tuple "Global package sets path" Paths.packageSetsPath + , Tuple "Global database path" Paths.databasePath + , Tuple "Local cache path" Paths.localCachePath + , Tuple "Local cache packages path" Paths.localCachePackagesPath + ] + -- TODO: add LICENSE field listPackageSet :: LsPackagesArgs -> Spago LsSetEnv Unit diff --git a/src/Spago/Db.purs b/src/Spago/Db.purs index 9e51c4f2a..2c69e90e3 100644 --- a/src/Spago/Db.purs +++ b/src/Spago/Db.purs @@ -5,8 +5,6 @@ module Spago.Db , PackageSetEntry , PackageVersion , connect - , databasePath - , databaseVersion , selectPackageSets , selectLatestPackageSetByCompiler , insertPackageSet @@ -38,13 +36,6 @@ import Spago.Paths as Paths -------------------------------------------------------------------------------- -- API --- | We should bump this number every time we change the database schema in a breaking way -databaseVersion :: Int -databaseVersion = 1 - -databasePath :: FilePath -databasePath = Path.concat [ Paths.globalCachePath, "spago.v" <> show databaseVersion <> ".sqlite" ] - type ConnectOptions = { database :: FilePath , logger :: String -> Effect Unit @@ -93,6 +84,7 @@ selectPackageSetEntriesByPackage db packageName version = do -------------------------------------------------------------------------------- -- Table types and conversions +-- Note: bump `Paths.databaseVersion` every time we change the database schema in a breaking way data Db type PackageSetJs = diff --git a/src/Spago/Paths.purs b/src/Spago/Paths.purs index 38bbf0832..348e7efd6 100644 --- a/src/Spago/Paths.purs +++ b/src/Spago/Paths.purs @@ -41,11 +41,9 @@ registryIndexPath = Path.concat [ globalCachePath, "registry-index" ] packageSetsPath :: FilePath packageSetsPath = Path.concat [ registryPath, "package-sets" ] -localCachePersistedWarningsPath :: FilePath -localCachePersistedWarningsPath = Path.concat [ localCachePath, "persisted-warnings" ] +-- | We should bump this number every time we change the database schema in a breaking way +databaseVersion :: Int +databaseVersion = 1 -localCachesPersistedWarningsEntireWorkspace :: FilePath -localCachesPersistedWarningsEntireWorkspace = mkLocalCachesPersistentWarningsFile "entire-workspace" - -mkLocalCachesPersistentWarningsFile :: String -> FilePath -mkLocalCachesPersistentWarningsFile fileName = Path.concat [ localCachePersistedWarningsPath, fileName <> ".stash" ] +databasePath :: FilePath +databasePath = Path.concat [ globalCachePath, "spago.v" <> show databaseVersion <> ".sqlite" ]