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 #1310

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b0187a7
Run Spago from a nested directory other than workspace root
fsoikin Dec 19, 2024
fbab1c3
The high spirits of questionable formatting are not to be trifled with
fsoikin Jan 19, 2025
ebba9da
When the slash is forward, every forest friend will notice
fsoikin Jan 20, 2025
d2dff38
Merge branch 'master' into nested-launch
f-f Jan 20, 2025
8bc1cf7
Merge branch 'master' into nested-launch
f-f Jan 23, 2025
2b79ca1
Merge branch 'master' into nested-launch
f-f Jan 31, 2025
171b93f
Do not attempt to load subpackages nested under malformed config
fsoikin Feb 3, 2025
2048499
Try to fix CI
fsoikin Feb 3, 2025
b467814
Debug MacOS test failure
fsoikin Feb 3, 2025
e15dcb5
Debug MacOS test failure
fsoikin Feb 3, 2025
6580f30
Debug MacOS test failure
fsoikin Feb 3, 2025
41fe063
Debug MacOS test failure
fsoikin Feb 3, 2025
124fc0f
Debug MacOS test failure
fsoikin Feb 3, 2025
a5f5bf0
Debug MacOS test failure
fsoikin Feb 3, 2025
443fdc4
Debug MacOS test failure
fsoikin Feb 3, 2025
5507c42
Debug MacOS test failure
fsoikin Feb 3, 2025
e3987ab
Debug MacOS test failure
fsoikin Feb 3, 2025
d7d0ecf
Debug MacOS test failure
fsoikin Feb 3, 2025
c0c918b
Debug MacOS test failure
fsoikin Feb 3, 2025
9f2b7f4
Debug MacOS test failure
fsoikin Feb 3, 2025
be6712e
Debug MacOS test failure
fsoikin Feb 3, 2025
38ff466
Debug MacOS test failure
fsoikin Feb 3, 2025
eb0df61
Remove debug cruft
fsoikin Feb 3, 2025
893d7c8
Remove more debug cruft
fsoikin Feb 3, 2025
2fb281b
Can't forget about Windows
fsoikin Feb 3, 2025
f6d9ec9
Review feedback: rename variables, add comment, add type signatures
fsoikin Feb 9, 2025
d1a15af
Autoformatter
fsoikin Feb 9, 2025
cc42d8e
Merge branch 'master' into nested-launch
fsoikin Feb 9, 2025
57a4768
Mention pruning reasoning
fsoikin Feb 9, 2025
67e96f1
Merge remote-tracking branch 'refs/remotes/origin/nested-launch' into…
fsoikin Feb 9, 2025
1bf9a7a
Merge branch 'master' into nested-launch
f-f Feb 14, 2025
b50b0f1
Merge branch 'master' into nested-launch
f-f Feb 14, 2025
52d8264
Merge branch 'master' into nested-launch
fsoikin Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Other improvements:
- When the `publish.location` field is missing, `spago publish` will attempt to
figure out the location from Git remotes and write it back to `spago.yaml`.
- Internally Spago uses stricter-typed file paths.
- Spago can now be launched from a directory nested within the workspace, not
just from workspace root.
- `spago install` warns the user when the installed versions of packages are outside
their specified dependency ranges.
- `spago publish` no longer tries to validate all workspace dependencies, but
Expand Down
53 changes: 31 additions & 22 deletions bin/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ main = do
\c -> Aff.launchAff_ case c of
Cmd'SpagoCmd (SpagoCmd globalArgs@{ offline, migrateConfig } command) -> do
logOptions <- mkLogOptions startingTime globalArgs
rootPath <- Path.mkRoot =<< Paths.cwd
runSpago { logOptions, rootPath } case command of
runSpago { logOptions } case command of
Sources args -> do
{ env } <- mkFetchEnv
{ packages: mempty
Expand All @@ -552,6 +551,7 @@ main = do
void $ runSpago env (Sources.run { json: args.json })
Init args@{ useSolver } -> do
-- Fetch the registry here so we can select the right package set later
rootPath <- Path.mkRoot =<< Paths.cwd
env <- mkRegistryEnv offline <#> Record.union { rootPath }
setVersion <- parseSetVersion args.setVersion
void $ runSpago env $ Init.run { mode: args.mode, setVersion, useSolver }
Expand Down Expand Up @@ -599,7 +599,8 @@ main = do
void $ runSpago publishEnv (Publish.publish {})

Repl args@{ selectedPackage } -> do
packages <- FS.exists (rootPath </> "spago.yaml") >>= case _ of
cwd <- Paths.cwd
packages <- FS.exists (cwd </> "spago.yaml") >>= case _ of
true -> do
-- if we have a config then we assume it's a workspace, and we can run a repl in the project
pure mempty -- TODO newPackages
Expand Down Expand Up @@ -661,13 +662,14 @@ main = do
testEnv <- runSpago env (mkTestEnv args buildEnv)
runSpago testEnv Test.run
LsPaths args -> do
runSpago { logOptions, rootPath } $ Ls.listPaths args
let fetchArgs = { packages: mempty, selectedPackage: Nothing, pure: false, ensureRanges: false, testDeps: false, isRepl: false, migrateConfig, offline }
{ env } <- mkFetchEnv fetchArgs
runSpago env $ Ls.listPaths args
LsPackages args@{ pure } -> do
let fetchArgs = { packages: mempty, selectedPackage: Nothing, pure, ensureRanges: false, testDeps: false, isRepl: false, migrateConfig, offline }
{ env: env@{ workspace }, fetchOpts } <- mkFetchEnv fetchArgs
{ env, fetchOpts } <- mkFetchEnv fetchArgs
dependencies <- runSpago env (Fetch.run fetchOpts)
let lsEnv = { workspace, dependencies, logOptions, rootPath }
runSpago lsEnv (Ls.listPackageSet args)
runSpago (Record.union env { dependencies }) (Ls.listPackageSet args)
LsDeps { selectedPackage, json, transitive, pure } -> do
let fetchArgs = { packages: mempty, selectedPackage, pure, ensureRanges: false, testDeps: false, isRepl: false, migrateConfig, offline }
{ env, fetchOpts } <- mkFetchEnv fetchArgs
Expand All @@ -690,13 +692,11 @@ main = do
GraphModules args -> do
{ env, fetchOpts } <- mkFetchEnv { packages: mempty, selectedPackage: Nothing, pure: false, ensureRanges: false, testDeps: false, isRepl: false, migrateConfig, offline }
dependencies <- runSpago env (Fetch.run fetchOpts)
purs <- Purs.getPurs
runSpago { dependencies, logOptions, rootPath, purs, workspace: env.workspace } (Graph.graphModules args)
runSpago (Record.union env { dependencies }) (Graph.graphModules args)
GraphPackages args -> do
{ env, fetchOpts } <- mkFetchEnv { packages: mempty, selectedPackage: Nothing, pure: false, ensureRanges: false, testDeps: false, isRepl: false, migrateConfig, offline }
dependencies <- runSpago env (Fetch.run fetchOpts)
purs <- Purs.getPurs
runSpago { dependencies, logOptions, rootPath, purs, workspace: env.workspace } (Graph.graphPackages args)
runSpago (Record.union env { dependencies }) (Graph.graphPackages args)

Cmd'VersionCmd v -> when v do
output (OutputLines [ BuildInfo.packages."spago-bin" ])
Expand Down Expand Up @@ -951,7 +951,14 @@ mkReplEnv replArgs dependencies supportPackage = do
, selected
}

mkFetchEnv :: forall a b. { offline :: OnlineStatus, migrateConfig :: Boolean, isRepl :: Boolean | FetchArgsRow b } -> Spago (SpagoBaseEnv a) { env :: Fetch.FetchEnv (), fetchOpts :: Fetch.FetchOpts }
mkFetchEnv
:: ∀ a b
. { offline :: OnlineStatus
, migrateConfig :: Boolean
, isRepl :: Boolean
| FetchArgsRow b
}
-> Spago { logOptions :: LogOptions | a } { env :: Fetch.FetchEnv (), fetchOpts :: Fetch.FetchOpts }
mkFetchEnv args@{ migrateConfig, offline } = do
let
parsePackageName p =
Expand All @@ -966,24 +973,26 @@ mkFetchEnv args@{ migrateConfig, offline } = do
Left _err -> die $ "Failed to parse selected package name, was: " <> show args.selectedPackage

env <- mkRegistryEnv offline
{ rootPath } <- ask
workspace <-
runSpago (Record.union env { rootPath })
(Config.readWorkspace { maybeSelectedPackage, pureBuild: args.pure, migrateConfig })
cwd <- Paths.cwd
{ workspace, rootPath } <-
runSpago env
(Config.discoverWorkspace { maybeSelectedPackage, pureBuild: args.pure, migrateConfig } cwd)

FS.mkdirp $ rootPath </> Paths.localCachePath
FS.mkdirp $ rootPath </> Paths.localCachePackagesPath
logDebug $ "Workspace root path: " <> Path.quote rootPath
logDebug $ "Local cache: " <> Paths.localCachePath

let fetchOpts = { packages: packageNames, ensureRanges: args.ensureRanges, isTest: args.testDeps, isRepl: args.isRepl }
pure { fetchOpts, env: Record.union { workspace, rootPath } env }

mkRegistryEnv :: forall a. OnlineStatus -> Spago (SpagoBaseEnv a) (Registry.RegistryEnv ())
mkRegistryEnv offline = do
{ logOptions, rootPath } <- ask
{ logOptions } <- ask

-- Take care of the caches
FS.mkdirp Paths.globalCachePath
FS.mkdirp $ rootPath </> Paths.localCachePath
FS.mkdirp $ rootPath </> Paths.localCachePackagesPath
logDebug $ "Workspace root path: " <> Path.quote rootPath
logDebug $ "Global cache: " <> Path.quote Paths.globalCachePath
logDebug $ "Local cache: " <> Paths.localCachePath

-- Make sure we have git and purs
git <- Git.getGit
Expand All @@ -1004,7 +1013,7 @@ mkRegistryEnv offline = do
, db
}

mkLsEnv :: forall a. Fetch.PackageTransitiveDeps -> Spago (Fetch.FetchEnv a) Ls.LsEnv
mkLsEnv :: a. Fetch.PackageTransitiveDeps -> Spago (Fetch.FetchEnv a) (Ls.LsEnv ())
mkLsEnv dependencies = do
{ logOptions, workspace, rootPath } <- ask
selected <- case workspace.selected of
Expand Down
14 changes: 3 additions & 11 deletions core/src/Log.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Spago.Log
, rightOrDie
, rightOrDie_
, rightOrDieWith
, rightOrDieWith'
, toDoc
) where

Expand Down Expand Up @@ -185,25 +184,18 @@ justOrDieWith' value msg = case value of
die' msg

rightOrDie :: ∀ b m err x. MonadEffect m => MonadAsk (LogEnv b) m => Loggable err => Either err x -> m x
rightOrDie value = rightOrDieWith value identity
rightOrDie = rightOrDieWith identity

rightOrDie_ :: ∀ b m err x. MonadEffect m => MonadAsk (LogEnv b) m => Loggable err => Either err x -> m Unit
rightOrDie_ = void <<< rightOrDie

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
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
Right a ->
pure a
Left err ->
die' $ toMsg err

data OutputFormat a
= OutputJson (CJ.Codec a) a
| OutputYaml (CJ.Codec a) a
Expand Down
3 changes: 2 additions & 1 deletion core/src/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Data.DateTime.Instant (Instant) as Extra
import Data.Either (Either(..), isLeft, isRight, either, hush) as Extra
import Data.Filterable (partition, partitionMap) as Extra
import Data.Foldable (foldMap, for_, foldl, and, or) as Extra
import Data.FoldableWithIndex (forWithIndex_) as Extra
import Data.Function (on) as Extra
import Data.Generic.Rep (class Generic) as Extra
import Data.Identity (Identity(..)) as Extra
Expand All @@ -47,7 +48,7 @@ import Partial.Unsafe (unsafeCrashWith)
import Registry.ManifestIndex (ManifestIndex) as Extra
import Registry.Types (PackageName, Version, Range, Location, License, Manifest(..), Metadata(..), Sha256) as Extra
import Spago.Json (printJson, parseJson) as Extra
import Spago.Log (logDebug, logError, logInfo, Docc, logSuccess, logWarn, die, die', justOrDieWith, justOrDieWith', rightOrDie, rightOrDie_, rightOrDieWith, rightOrDieWith', toDoc, indent, indent2, output, LogEnv, LogOptions, OutputFormat(..)) as Extra
import Spago.Log (logDebug, logError, logInfo, Docc, logSuccess, logWarn, die, die', justOrDieWith, justOrDieWith', rightOrDie, rightOrDie_, rightOrDieWith, toDoc, indent, indent2, output, LogEnv, LogOptions, OutputFormat(..)) as Extra
import Spago.Path (RawFilePath, GlobalPath, LocalPath, RootPath, class AppendPath, appendPath, (</>)) as Extra
import Spago.Yaml (YamlDoc, printYaml, parseYaml) as Extra

Expand Down
11 changes: 11 additions & 0 deletions spago.lock
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@
},
"test": {
"dependencies": [
"debug",
"exceptions",
"quickcheck",
"spec",
Expand All @@ -741,6 +742,7 @@
"contravariant",
"control",
"datetime",
"debug",
"distributive",
"effect",
"either",
Expand Down Expand Up @@ -2157,6 +2159,15 @@
"tuples"
]
},
"debug": {
"type": "registry",
"version": "6.0.2",
"integrity": "sha256-vmkYFuXYuELBzeauvgHG6E6Kf/Hp1dAnxwE9ByHfwSg=",
"dependencies": [
"functions",
"prelude"
]
},
"distributive": {
"type": "registry",
"version": "6.0.0",
Expand Down
12 changes: 7 additions & 5 deletions src/Spago/Command/Ls.purs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,24 @@ type LsPathsArgs =
{ json :: Boolean
}

type LsSetEnv =
type LsSetEnv r =
{ dependencies :: Fetch.PackageTransitiveDeps
, logOptions :: LogOptions
, workspace :: Workspace
, rootPath :: RootPath
| r
}

type LsEnv =
type LsEnv r =
{ dependencies :: Fetch.PackageTransitiveDeps
, logOptions :: LogOptions
, workspace :: Workspace
, selected :: WorkspacePackage
, rootPath :: RootPath
| r
}

listPaths :: LsPathsArgs -> Spago { logOptions :: LogOptions, rootPath :: RootPath } Unit
listPaths :: ∀ r. LsPathsArgs -> Spago { logOptions :: LogOptions, rootPath :: RootPath | r } Unit
listPaths { json } = do
logDebug "Running `listPaths`"
{ rootPath } <- ask
Expand All @@ -90,7 +92,7 @@ listPaths { json } = do

-- TODO: add LICENSE field

listPackageSet :: LsPackagesArgs -> Spago LsSetEnv Unit
listPackageSet :: ∀ r. LsPackagesArgs -> Spago (LsSetEnv r) Unit
listPackageSet { json } = do
logDebug "Running `listPackageSet`"
{ workspace, rootPath } <- ask
Expand All @@ -102,7 +104,7 @@ listPackageSet { json } = do
true -> formatPackagesJson rootPath packages
false -> formatPackagesTable packages

listPackages :: LsDepsOpts -> Spago LsEnv Unit
listPackages :: ∀ r. LsDepsOpts -> Spago (LsEnv r) Unit
listPackages { transitive, json } = do
logDebug "Running `listPackages`"
{ dependencies, selected, rootPath } <- ask
Expand Down
Loading
Loading