Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Spago/Command/Fetch.purs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ getGitPackageInLocalCache name package = do
getPackageDependencies :: forall a. PackageName -> Package -> Spago (FetchEnv a) (Maybe (ByEnv (Map PackageName Range)))
getPackageDependencies packageName package = case package of
RegistryVersion v -> do
-- Check if registry-index exists when offline
whenM (asks _.offline <#> eq Offline) do
unlessM (FS.exists Paths.registryIndexPath) do
die
[ "You are offline and the Registry Index is not cached locally."
, "Cannot look up dependencies for " <> PackageName.print packageName <> "@" <> Version.print v
, "Please connect to the internet and run 'spago install' first."
]
maybeManifest <- Registry.getManifestFromIndex packageName v
pure $ maybeManifest <#> \(Manifest m) -> { core: m.dependencies, test: Map.empty }
GitPackage p -> do
Expand Down
12 changes: 9 additions & 3 deletions src/Spago/Git.purs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ checkout { repo, ref } = Except.runExceptT $ void $ runGit [ "checkout", ref ] (

fetch :: ∀ a path. Path.IsPath path => { repo :: path, remote :: String } -> Spago (GitEnv a) (Either String Unit)
fetch { repo, remote } = do
remoteUrl <- runGit [ "remote", "get-url", remote ] (Just $ Path.toGlobal repo) # Except.runExceptT >>= rightOrDie
logInfo $ "Fetching from " <> remoteUrl
Except.runExceptT $ runGit_ [ "fetch", remote, "--tags" ] (Just $ Path.toGlobal repo)
{ offline } <- ask
case offline of
Offline -> do
logDebug $ "Skipping fetch from remote '" <> remote <> "' because we are offline"
pure $ Left "Cannot fetch from remote while offline."
_ -> do
remoteUrl <- runGit [ "remote", "get-url", remote ] (Just $ Path.toGlobal repo) # Except.runExceptT >>= rightOrDie
logInfo $ "Fetching from " <> remoteUrl
Except.runExceptT $ runGit_ [ "fetch", remote, "--tags" ] (Just $ Path.toGlobal repo)

getRefType :: ∀ a path. Path.IsPath path => { repo :: path, ref :: String } -> Spago (GitEnv a) (Either String String)
getRefType { repo, ref } = Except.runExceptT $ runGit [ "cat-file", "-t", ref ] (Just $ Path.toGlobal repo)
Expand Down
31 changes: 24 additions & 7 deletions src/Spago/Registry.purs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ getRegistryFns registryBox registryLock = do

-- Now that we are up to date with the Registry we init/refresh the database
updatePackageSetsDb db

-- Check if registry directories exist when offline - the build should have already failed by now, but just in case..
case offline of
Offline -> do
unlessM (FS.exists Paths.registryPath) $
die "You are offline and the Registry is not cached locally. Please connect to the internet and run 'spago install' to cache the registry."
unlessM (FS.exists Paths.registryIndexPath) $
die "You are offline and the Registry Index is not cached locally. Please connect to the internet and run 'spago install' to cache the registry index."
_ -> pure unit

pure fetchingFreshRegistry

-- | Update the database with the latest package sets
Expand All @@ -211,12 +221,19 @@ getRegistryFns registryBox registryLock = do
-- | List all the package sets versions available in the Registry repo
getAvailablePackageSets :: ∀ a. Spago (LogEnv a) (Array Version)
getAvailablePackageSets = do
{ success: setVersions, fail: parseFailures } <- map (partitionEithers <<< map parseSetVersion) $ FS.ls Paths.packageSetsPath

unless (Array.null parseFailures) do
logDebug $ [ toDoc "Failed to parse some package-sets versions:" ] <> map (indent <<< toDoc <<< show) parseFailures

pure setVersions
packageSetsExists <- FS.exists Paths.packageSetsPath
if packageSetsExists then do
{ success: setVersions, fail: parseFailures } <- map (partitionEithers <<< map parseSetVersion) $ FS.ls Paths.packageSetsPath

unless (Array.null parseFailures) do
logDebug $ [ toDoc "Failed to parse some package-sets versions:" ] <> map (indent <<< toDoc <<< show) parseFailures

pure setVersions
else do
die
[ "Package sets directory does not exist at " <> Path.quote Paths.packageSetsPath
, "Please connect to the internet and run 'spago install' to populate the registry cache."
]
where
parseSetVersion str = Version.parse case String.stripSuffix (Pattern ".json") str of
Nothing -> str
Expand Down Expand Up @@ -286,7 +303,7 @@ getManifestFromIndexImpl db name version = do
manifests <- map (map (\m@(Manifest m') -> Tuple m'.version m)) case maybeManifests of
Right ms -> pure $ NonEmptyArray.toUnfoldable ms
Left err -> do
logWarn $ "Could not read package manifests from index, proceeding anyways. Error: " <> err
logWarn $ "Could not read package manifests for '" <> PackageName.print name <> "' from index. Error: " <> err
pure []
let versions = Map.fromFoldable manifests
-- and memoize it
Expand Down
Loading