Skip to content

Commit

Permalink
look for workspace in parent directories only after not found in work…
Browse files Browse the repository at this point in the history
…ing directory
  • Loading branch information
peterbecich committed Jul 21, 2024
1 parent c69cd06 commit 7400380
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
33 changes: 16 additions & 17 deletions src/Spago/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
searchHigherPaths Nil = pure Nothing
searchHigherPaths (path : otherPaths) = do
-- TODO stop searching if .git is found, this is the root
logInfo $ "Searching " <> path
mYaml :: Maybe String <- map (map (\yml -> path <> yml)) $ map Array.head $ liftAff $ Glob.gitignoringGlob path [ "./spago.yaml" ]
case mYaml of
Nothing -> searchHigherPaths otherPaths
Expand All @@ -221,12 +220,9 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
Nothing -> searchHigherPaths otherPaths
Just ws -> pure (pure (Tuple foundSpagoYaml ws))

mHigherWorkspace <- searchHigherPaths higherPaths
for_ mHigherWorkspace $ \(Tuple filepath _) ->
logInfo $ "Found workspace definition in " <> filepath

-- First try to read the config in the root. It _has_ to contain a workspace
-- configuration, or we fail early.
-- First try to read the config in the root.
-- Else, look for a workspace in parent directories.
-- Else fail.
{ workspace, package: maybePackage, workspaceDoc } <- readConfig "spago.yaml" >>= case _ of
Left errLines ->
die
Expand All @@ -236,16 +232,19 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
, Log.break
, toDoc "The configuration file help can be found here https://github.com/purescript/spago#the-configuration-file"
]
Right config@{ yaml: { workspace: Nothing, package }, doc } -> case mHigherWorkspace of
Nothing ->
die
[ "No workspace definition found in this spago.yaml or any spago.yaml in parent directory."
, "See the relevant documentation here: https://github.com/purescript/spago#the-workspace"
]
Just (Tuple _ higherWorkspace) -> do
-- TODO migrate workspace at higher directory?
doMigrateConfig "spago.yaml" config
pure { workspace: higherWorkspace, package, workspaceDoc: doc }
Right config@{ yaml: { workspace: Nothing, package }, doc } -> do
mHigherWorkspace <- searchHigherPaths higherPaths
case mHigherWorkspace of
Nothing ->
die
[ "No workspace definition found in this spago.yaml or any spago.yaml in parent directory."
, "See the relevant documentation here: https://github.com/purescript/spago#the-workspace"
]
Just (Tuple higherWorkspacePath higherWorkspace) -> do
logInfo $ "Found workspace definition in " <> higherWorkspacePath
-- TODO migrate workspace at higher directory?
doMigrateConfig "spago.yaml" config
pure { workspace: higherWorkspace, package, workspaceDoc: doc }
Right config@{ yaml: { workspace: Just workspace, package }, doc } -> do
doMigrateConfig "spago.yaml" config
pure { workspace, package, workspaceDoc: doc }
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/Paths.purs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ toGitSearchPath rootDir = reverse $ makeSearchPaths rootDir 4 where
makeSearchPath wd i = joinWith "" $ cons wd $ cons "/" $ replicate i "../"

makeSearchPaths :: FilePath -> Int -> Array FilePath
makeSearchPaths wd 0 = pure (wd <> "/")
makeSearchPaths wd 0 = mempty
makeSearchPaths wd i | i > 0 = cons (makeSearchPath wd i) (makeSearchPaths wd (i - 1))
makeSearchPaths _ _ = mempty

Expand Down
5 changes: 2 additions & 3 deletions test/Spago/Paths.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import Spago.Paths (toGitSearchPath)
spec :: Spec Unit
spec = Spec.around withTempDir do
Spec.describe "paths" do
Spec.it "generate four paths to parent directories of working directory, plus working directory" \ _ -> do
Spec.it "generate four paths to parent directories of working directory" \ _ -> do
toGitSearchPath "~/a/b/c/d/e" `Assert.shouldEqual`
[ "~/a/b/c/d/e"
, "~/a/b/c/d/e/../"
[ "~/a/b/c/d/e/../"
, "~/a/b/c/d/e/../../"
, "~/a/b/c/d/e/../../../"
, "~/a/b/c/d/e/../../../../"
Expand Down

0 comments on commit 7400380

Please sign in to comment.