Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Spago from a nested directory other than workspace root #1

Open
wants to merge 1 commit into
base: file-paths
Choose a base branch
from

Conversation

fsoikin
Copy link
Owner

@fsoikin fsoikin commented Dec 19, 2024

NOTE: this PR is built on top of purescript#1296, so for now it's targeted at my own fork. Once purescript#1296 is merged, I will open a proper PR to the original repo.

@f-f

Description of the change

Fixes purescript#1237
Allowing Spago to be launched from a directory nested within the workspace.

  • When launched, Spago will walk directories up until it finds a spago.yaml containing a workspace.
  • As it goes, it remembers config docs it finds and loads along the way.
    • We have to load them anyway in order to see if they contain a workspace. So we remember them in order to avoid loading them twice.
  • After finding the root, it then globs for spago.yaml files back down the tree and loads those that it hasn't loaded while walking up.
  • As it walks up the tree, it also gathers and remembers any spago.yml (wrong extension) files.
  • If it goes all the way up to the file system root, it prints an error saying no config found and lists all the yml files found along the way, if any, suggesting that they may have the wrong extension.

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • [ ] Added some example of the new feature to the README
  • Added a test for the contribution (if applicable)

Comment on lines +967 to +970
FS.mkdirp $ rootPath </> Paths.localCachePath
FS.mkdirp $ rootPath </> Paths.localCachePackagesPath
logDebug $ "Workspace root path: " <> Path.quote rootPath
logDebug $ "Local cache: " <> Paths.localCachePath
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only semi-related to the change. I found that, before this change, Spago would always create a ./.spago directory as soon as it's launched, even if it's only asked to registry search. I moved this from mkRegistryEnv to mkFetchEnv, which seems to be logically always "in a workspace".

rightOrDieWith :: ∀ a b m err x. MonadEffect m => MonadAsk (LogEnv b) m => Loggable a => Either err x -> (err -> a) -> m x
rightOrDieWith value toMsg = case value of
rightOrDieWith :: ∀ a b m err x. MonadEffect m => MonadAsk (LogEnv b) m => Loggable a => (err -> a) -> Either err x -> m x
rightOrDieWith toMsg value = case value of
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function wasn't actually used anywhere (until now), so I swapped the parameters to allow it to be called with postfix application like foo >>= rightOrDieWith \err -> die $ "Error: " <> err

Right a ->
pure a
Left err ->
die $ toMsg err

rightOrDieWith' :: ∀ a b m err x. MonadEffect m => MonadAsk (LogEnv b) m => Loggable a => Either err x -> (err -> Array a) -> m x
rightOrDieWith' value toMsg = case value of
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also not used anywhere, and also is redundant, since there is an instance Loggable a => Loggable (Array a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant