Skip to content

Commit c69cd06

Browse files
committed
successfully finds and uses workspace in parent directory
1 parent 00d3951 commit c69cd06

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/Spago/Config.purs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Data.Enum as Enum
3838
import Data.Graph as Graph
3939
import Data.HTTP.Method as Method
4040
import Data.Int as Int
41-
import Data.List (List(..), (:))
41+
import Data.List (List(..))
4242
import Data.Map as Map
4343
import Data.Nullable (Nullable)
4444
import Data.Nullable as Nullable
@@ -48,7 +48,6 @@ import Data.Set.NonEmpty (NonEmptySet)
4848
import Data.Set.NonEmpty as NonEmptySet
4949
import Data.String (CodePoint, Pattern(..))
5050
import Data.String as String
51-
import Data.Traversable (sequence)
5251
import Dodo as Log
5352
import Effect.Aff as Aff
5453
import 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 }

src/Spago/Paths.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ toLocalCachePackagesPath rootDir = Path.concat [ toLocalCachePath rootDir, "p" ]
4242

4343
-- search maximum 4 levels up the tree to find the Git project, if it exists
4444
toGitSearchPath :: FilePath -> Array FilePath
45-
toGitSearchPath rootDir = reverse $ makeSearchPaths rootDir 2 where
45+
toGitSearchPath rootDir = reverse $ makeSearchPaths rootDir 4 where
4646
makeSearchPath :: FilePath -> Int -> FilePath
4747
makeSearchPath wd i = joinWith "" $ cons wd $ cons "/" $ replicate i "../"
4848

4949
makeSearchPaths :: FilePath -> Int -> Array FilePath
50-
makeSearchPaths wd 0 = pure wd
50+
makeSearchPaths wd 0 = pure (wd <> "/")
5151
makeSearchPaths wd i | i > 0 = cons (makeSearchPath wd i) (makeSearchPaths wd (i - 1))
5252
makeSearchPaths _ _ = mempty
5353

0 commit comments

Comments
 (0)