@@ -38,7 +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 (..), (:) )
41+ import Data.List (List (..))
4242import Data.Map as Map
4343import Data.Nullable (Nullable )
4444import Data.Nullable as Nullable
@@ -48,7 +48,6 @@ import Data.Set.NonEmpty (NonEmptySet)
4848import Data.Set.NonEmpty as NonEmptySet
4949import Data.String (CodePoint , Pattern (..))
5050import Data.String as String
51- import Data.Traversable (sequence )
5251import Dodo as Log
5352import Effect.Aff as Aff
5453import Effect.Uncurried (EffectFn2 , EffectFn3 , runEffectFn2 , runEffectFn3 )
@@ -201,27 +200,30 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
201200 checkForWorkspace :: forall a . FilePath
202201 -> Spago (LogEnv a ) (Maybe PrelimWorkspace )
203202 checkForWorkspace config = do
204- result <- readConfig config
203+ logInfo $ " Checking for workspace: " <> config
204+ result <- map (map (\y -> y.yaml)) $ readConfig config
205205 case result of
206206 Left _ -> pure Nothing
207- Right { yaml: { workspace: Nothing } } -> pure Nothing
208- Right { yaml: { workspace: Just ws } } -> pure (Just ws)
207+ Right { workspace: Nothing } -> pure Nothing
208+ Right { workspace: Just ws } -> pure (Just ws)
209209
210- searchHigherPaths :: forall a . List FilePath -> Spago (LogEnv a ) (Maybe PrelimWorkspace )
210+ searchHigherPaths :: forall a . List FilePath -> Spago (LogEnv a ) (Maybe ( Tuple FilePath PrelimWorkspace ) )
211211 searchHigherPaths Nil = pure Nothing
212212 searchHigherPaths (path : otherPaths) = do
213- mYaml :: Maybe String <- map Array .head $ liftAff $ Glob .gitignoringGlob path [ " ./spago.yaml" ]
213+ -- TODO stop searching if .git is found, this is the root
214+ logInfo $ " Searching " <> path
215+ mYaml :: Maybe String <- map (map (\yml -> path <> yml)) $ map Array .head $ liftAff $ Glob .gitignoringGlob path [ " ./spago.yaml" ]
214216 case mYaml of
215217 Nothing -> searchHigherPaths otherPaths
216218 Just foundSpagoYaml -> do
217219 mWorkspace :: Maybe PrelimWorkspace <- checkForWorkspace foundSpagoYaml
218220 case mWorkspace of
219221 Nothing -> searchHigherPaths otherPaths
220- workspace -> pure workspace
222+ Just ws -> pure (pure ( Tuple foundSpagoYaml ws))
221223
222- mHigherConfigPath <- searchHigherPaths higherPaths
223- for_ mHigherConfigPath $ \higherConfigPath -> do
224- logDebug $ [ toDoc " Found workspace at higher path: " ]
224+ mHigherWorkspace <- searchHigherPaths higherPaths
225+ for_ mHigherWorkspace $ \( Tuple filepath _) ->
226+ logInfo $ " Found workspace definition in " <> filepath
225227
226228 -- First try to read the config in the root. It _has_ to contain a workspace
227229 -- configuration, or we fail early.
@@ -234,10 +236,16 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
234236 , Log .break
235237 , toDoc " The configuration file help can be found here https://github.com/purescript/spago#the-configuration-file"
236238 ]
237- Right { yaml: { workspace: Nothing } } -> die
238- [ " Your spago.yaml doesn't contain a workspace section."
239- , " See the relevant documentation here: https://github.com/purescript/spago#the-workspace"
240- ]
239+ Right config@{ yaml: { workspace: Nothing , package }, doc } -> case mHigherWorkspace of
240+ Nothing ->
241+ die
242+ [ " No workspace definition found in this spago.yaml or any spago.yaml in parent directory."
243+ , " See the relevant documentation here: https://github.com/purescript/spago#the-workspace"
244+ ]
245+ Just (Tuple _ higherWorkspace) -> do
246+ -- TODO migrate workspace at higher directory?
247+ doMigrateConfig " spago.yaml" config
248+ pure { workspace: higherWorkspace, package, workspaceDoc: doc }
241249 Right config@{ yaml: { workspace: Just workspace, package }, doc } -> do
242250 doMigrateConfig " spago.yaml" config
243251 pure { workspace, package, workspaceDoc: doc }
0 commit comments