@@ -192,7 +192,6 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
192192 false , true -> logWarn $ " Your " <> path <> " is using an outdated format. Run Spago with the --migrate flag to update it to the latest version."
193193 _, false -> pure unit
194194
195- logInfo " Gathering all the spago configs higher in the tree..."
196195 let
197196 higherPaths :: List FilePath
198197 higherPaths = Array .toUnfoldable $ Paths .toGitSearchPath Paths .cwd
@@ -210,23 +209,31 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
210209 searchHigherPaths :: forall a . List FilePath -> Spago (LogEnv a ) (Maybe (Tuple FilePath PrelimWorkspace ))
211210 searchHigherPaths Nil = pure Nothing
212211 searchHigherPaths (path : otherPaths) = do
213- -- TODO stop searching if .git is found, this is the root
214- logInfo $ " Searching " <> path
212+ mGitRoot :: Maybe String <- map Array .head $ liftAff $ Glob .gitignoringGlob path [ " ./.git" ]
215213 mYaml :: Maybe String <- map (map (\yml -> path <> yml)) $ map Array .head $ liftAff $ Glob .gitignoringGlob path [ " ./spago.yaml" ]
216214 case mYaml of
217- Nothing -> searchHigherPaths otherPaths
215+ Nothing -> case mGitRoot of
216+ Nothing -> searchHigherPaths otherPaths
217+ Just gitRoot -> do
218+ -- directory containing .git assumed to be the root of the project;
219+ -- do not search up the file tree further than this
220+ logInfo $ " No Spago workspace found in any directory up to root of project: " <> gitRoot
221+ pure Nothing
218222 Just foundSpagoYaml -> do
219223 mWorkspace :: Maybe PrelimWorkspace <- checkForWorkspace foundSpagoYaml
220224 case mWorkspace of
221- Nothing -> searchHigherPaths otherPaths
225+ Nothing -> case mGitRoot of
226+ Nothing -> searchHigherPaths otherPaths
227+ Just gitRoot -> do
228+ -- directory containing .git assumed to be the root of the project;
229+ -- do not search up the file tree further than this
230+ logInfo $ " No Spago workspace found in any directory up to root of project: " <> gitRoot
231+ pure Nothing
222232 Just ws -> pure (pure (Tuple foundSpagoYaml ws))
223233
224- mHigherWorkspace <- searchHigherPaths higherPaths
225- for_ mHigherWorkspace $ \(Tuple filepath _) ->
226- logInfo $ " Found workspace definition in " <> filepath
227-
228- -- First try to read the config in the root. It _has_ to contain a workspace
229- -- configuration, or we fail early.
234+ -- First try to read the config in the root.
235+ -- Else, look for a workspace in parent directories.
236+ -- Else fail.
230237 { workspace, package: maybePackage, workspaceDoc } <- readConfig " spago.yaml" >>= case _ of
231238 Left errLines ->
232239 die
@@ -236,16 +243,22 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
236243 , Log .break
237244 , toDoc " The configuration file help can be found here https://github.com/purescript/spago#the-configuration-file"
238245 ]
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 }
246+ Right config@{ yaml: { workspace: Nothing , package }, doc } -> do
247+ logInfo " Looking for Spago workspace configuration higher in the filesystem, up to project root (.git)..."
248+ mHigherWorkspace <- searchHigherPaths higherPaths
249+ case mHigherWorkspace of
250+ Nothing ->
251+ die
252+ [ " No workspace definition found in this directory"
253+ , " or in any directory up to root of project."
254+ , " Root determined by '.git' file."
255+ , " See the relevant documentation here: https://github.com/purescript/spago#the-workspace"
256+ ]
257+ Just (Tuple higherWorkspacePath higherWorkspace) -> do
258+ logInfo $ " Found workspace definition in " <> higherWorkspacePath
259+ -- TODO migrate workspace at higher directory?
260+ doMigrateConfig " spago.yaml" config
261+ pure { workspace: higherWorkspace, package, workspaceDoc: doc }
249262 Right config@{ yaml: { workspace: Just workspace, package }, doc } -> do
250263 doMigrateConfig " spago.yaml" config
251264 pure { workspace, package, workspaceDoc: doc }
0 commit comments