@@ -38,6 +38,7 @@ import Data.Enum as Enum
3838import Data.Graph as Graph
3939import Data.HTTP.Method as Method
4040import Data.Int as Int
41+ import Data.List (List (..), (:))
4142import Data.Map as Map
4243import Data.Nullable (Nullable )
4344import Data.Nullable as Nullable
@@ -47,6 +48,7 @@ import Data.Set.NonEmpty (NonEmptySet)
4748import Data.Set.NonEmpty as NonEmptySet
4849import Data.String (CodePoint , Pattern (..))
4950import Data.String as String
51+ import Data.Traversable (sequence )
5052import Dodo as Log
5153import Effect.Aff as Aff
5254import Effect.Uncurried (EffectFn2 , EffectFn3 , runEffectFn2 , runEffectFn3 )
@@ -164,6 +166,17 @@ type ReadWorkspaceOptions =
164166 , migrateConfig :: Boolean
165167 }
166168
169+ type PrelimWorkspace =
170+ { backend :: Maybe Core.BackendConfig
171+ , buildOpts :: Maybe
172+ { censorLibraryWarnings :: Maybe Core.CensorBuildWarnings
173+ , output :: Maybe String
174+ , statVerbosity :: Maybe Core.StatVerbosity
175+ }
176+ , extraPackages :: Maybe (Map PackageName Core.ExtraPackage )
177+ , packageSet :: Maybe Core.SetAddress
178+ }
179+
167180-- | Reads all the configurations in the tree and builds up the Map of local
168181-- | packages to be integrated in the package set
169182readWorkspace :: ReadWorkspaceOptions -> Spago (Registry.RegistryEnv _ ) Workspace
@@ -180,6 +193,36 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
180193 false , true -> logWarn $ " Your " <> path <> " is using an outdated format. Run Spago with the --migrate flag to update it to the latest version."
181194 _, false -> pure unit
182195
196+ logInfo " Gathering all the spago configs higher in the tree..."
197+ let
198+ higherPaths :: List FilePath
199+ higherPaths = Array .toUnfoldable $ Paths .toGitSearchPath Paths .cwd
200+
201+ checkForWorkspace :: forall a . FilePath
202+ -> Spago (LogEnv a ) (Maybe PrelimWorkspace )
203+ checkForWorkspace config = do
204+ result <- readConfig config
205+ case result of
206+ Left _ -> pure Nothing
207+ Right { yaml: { workspace: Nothing } } -> pure Nothing
208+ Right { yaml: { workspace: Just ws } } -> pure (Just ws)
209+
210+ searchHigherPaths :: forall a . List FilePath -> Spago (LogEnv a ) (Maybe PrelimWorkspace )
211+ searchHigherPaths Nil = pure Nothing
212+ searchHigherPaths (path : otherPaths) = do
213+ mYaml :: Maybe String <- map Array .head $ liftAff $ Glob .gitignoringGlob path [ " ./spago.yaml" ]
214+ case mYaml of
215+ Nothing -> searchHigherPaths otherPaths
216+ Just foundSpagoYaml -> do
217+ mWorkspace :: Maybe PrelimWorkspace <- checkForWorkspace foundSpagoYaml
218+ case mWorkspace of
219+ Nothing -> searchHigherPaths otherPaths
220+ workspace -> pure workspace
221+
222+ mHigherConfigPath <- searchHigherPaths higherPaths
223+ for_ mHigherConfigPath $ \higherConfigPath -> do
224+ logDebug $ [ toDoc " Found workspace at higher path:" ]
225+
183226 -- First try to read the config in the root. It _has_ to contain a workspace
184227 -- configuration, or we fail early.
185228 { workspace, package: maybePackage, workspaceDoc } <- readConfig " spago.yaml" >>= case _ of
@@ -199,10 +242,10 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
199242 doMigrateConfig " spago.yaml" config
200243 pure { workspace, package, workspaceDoc: doc }
201244
202- logDebug " Gathering all the spago configs in the tree..."
203- otherConfigPaths <- liftAff $ Glob .gitignoringGlob Paths .cwd [ " **/spago.yaml" ]
204- unless (Array .null otherConfigPaths ) do
205- logDebug $ [ toDoc " Found packages at these paths:" , Log .indent $ Log .lines (map toDoc otherConfigPaths ) ]
245+ logDebug " Gathering all the spago configs lower in the tree..."
246+ otherLowerConfigPaths <- liftAff $ Glob .gitignoringGlob Paths .cwd [ " **/spago.yaml" ]
247+ unless (Array .null otherLowerConfigPaths ) do
248+ logDebug $ [ toDoc " Found packages at these lower paths:" , Log .indent $ Log .lines (map toDoc otherLowerConfigPaths ) ]
206249
207250 -- We read all of them in, and only read the package section, if any.
208251 let
@@ -220,7 +263,7 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
220263 Right config -> do
221264 Right { config, hasTests, configPath: path, packagePath: Path .dirname path }
222265
223- { right: otherPackages, left: failedPackages } <- partitionMap identity <$> traverse readWorkspaceConfig otherConfigPaths
266+ { right: otherPackages, left: failedPackages } <- partitionMap identity <$> traverse readWorkspaceConfig otherLowerConfigPaths
224267 unless (Array .null failedPackages) do
225268 logWarn $ [ toDoc " Failed to read some configs:" ] <> failedPackages
226269
0 commit comments