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

Support lockfiles, take 2 #1138

Merged
merged 9 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 7 additions & 0 deletions bin/src/Flags.purs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ transitive =
<> O.help "Include transitive dependencies"
)

pure :: Parser Boolean
pure =
O.switch
( O.long "pure"
<> O.help "Use the package information from the current lockfile, even if it is out of date"
)

pedanticPackages :: Parser Boolean
pedanticPackages =
O.switch
Expand Down
82 changes: 52 additions & 30 deletions bin/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Spago.Bin.Flags as Flags
import Spago.Command.Build as Build
import Spago.Command.Bundle as Bundle
import Spago.Command.Docs as Docs
import Spago.Command.Uninstall as Uninstall
import Spago.Command.Fetch as Fetch
import Spago.Command.Graph (GraphModulesArgs, GraphPackagesArgs)
import Spago.Command.Graph as Graph
Expand All @@ -45,6 +44,7 @@ import Spago.Command.Repl as Repl
import Spago.Command.Run as Run
import Spago.Command.Sources as Sources
import Spago.Command.Test as Test
import Spago.Command.Uninstall as Uninstall
import Spago.Command.Upgrade as Upgrade
import Spago.Config (BundleConfig, BundlePlatform(..), BundleType(..), PackageMap, RunConfig, TestConfig)
import Spago.Config as Config
Expand All @@ -60,6 +60,7 @@ import Spago.Paths as Paths
import Spago.Purs as Purs
import Spago.Registry as Registry
import Spago.Repl as SpagoRepl
import Type.Proxy (Proxy(..))
import Unsafe.Coerce as UnsafeCoerce

type GlobalArgs =
Expand All @@ -75,12 +76,16 @@ type InitArgs =
, useSolver :: Boolean
}

type FetchArgs =
{ packages :: List String
type FetchArgsRow a =
( packages :: List String
, selectedPackage :: Maybe String
, ensureRanges :: Boolean
, testDeps :: Boolean
}
, pure :: Boolean
| a
)

type FetchArgs a = Record (FetchArgsRow a)

type InstallArgs =
{ packages :: List String
Expand All @@ -91,6 +96,7 @@ type InstallArgs =
, pedanticPackages :: Boolean
, ensureRanges :: Boolean
, testDeps :: Boolean
, pure :: Boolean
}

type UninstallArgs =
Expand All @@ -109,6 +115,7 @@ type BuildArgs a =
, jsonErrors :: Boolean
, strict :: Maybe Boolean
, statVerbosity :: Maybe Core.StatVerbosity
, pure :: Boolean
| a
}

Expand Down Expand Up @@ -136,6 +143,7 @@ type RunArgs =
, ensureRanges :: Boolean
, strict :: Maybe Boolean
, statVerbosity :: Maybe Core.StatVerbosity
, pure :: Boolean
}

type TestArgs =
Expand All @@ -147,6 +155,7 @@ type TestArgs =
, execArgs :: Maybe (Array String)
, strict :: Maybe Boolean
, statVerbosity :: Maybe Core.StatVerbosity
, pure :: Boolean
}

type SourcesArgs =
Expand All @@ -170,6 +179,7 @@ type BundleArgs =
, ensureRanges :: Boolean
, strict :: Maybe Boolean
, statVerbosity :: Maybe Core.StatVerbosity
, pure :: Boolean
}

type PublishArgs =
Expand All @@ -184,7 +194,7 @@ data Command a
= Build (BuildArgs a)
| Bundle BundleArgs
| Docs DocsArgs
| Fetch FetchArgs
| Fetch (FetchArgs a)
| Init InitArgs
| Install InstallArgs
| Uninstall UninstallArgs
Expand Down Expand Up @@ -287,13 +297,14 @@ initArgsParser =
, useSolver: Flags.useSolver
}

fetchArgsParser :: Parser FetchArgs
fetchArgsParser :: Parser (FetchArgs ())
fetchArgsParser =
Optparse.fromRecord
{ packages: Flags.packages
, selectedPackage: Flags.selectedPackage
, ensureRanges: Flags.ensureRanges
, testDeps: Flags.testDeps
, pure: Flags.pure
}

sourcesArgsParser :: Parser SourcesArgs
Expand All @@ -314,6 +325,7 @@ installArgsParser =
, pedanticPackages: Flags.pedanticPackages
, ensureRanges: Flags.ensureRanges
, testDeps: Flags.testDeps
, pure: Flags.pure
}

uninstallArgsParser :: Parser UninstallArgs
Expand All @@ -335,6 +347,7 @@ buildArgsParser = Optparse.fromRecord
, jsonErrors: Flags.jsonErrors
, strict: Flags.strict
, statVerbosity: Flags.statVerbosity
, pure: Flags.pure
}

replArgsParser :: Parser ReplArgs
Expand All @@ -356,6 +369,7 @@ runArgsParser = Optparse.fromRecord
, ensureRanges: Flags.ensureRanges
, strict: Flags.strict
, statVerbosity: Flags.statVerbosity
, pure: Flags.pure
}

testArgsParser :: Parser TestArgs
Expand All @@ -368,6 +382,7 @@ testArgsParser = Optparse.fromRecord
, pedanticPackages: Flags.pedanticPackages
, strict: Flags.strict
, statVerbosity: Flags.statVerbosity
, pure: Flags.pure
}

bundleArgsParser :: Parser BundleArgs
Expand All @@ -388,6 +403,7 @@ bundleArgsParser =
, ensureRanges: Flags.ensureRanges
, strict: Flags.strict
, statVerbosity: Flags.statVerbosity
, pure: Flags.pure
}

publishArgsParser :: Parser PublishArgs
Expand Down Expand Up @@ -463,13 +479,15 @@ lsPathsArgsParser = Optparse.fromRecord
lsPackagesArgsParser :: Parser LsPackagesArgs
lsPackagesArgsParser = Optparse.fromRecord
{ json: Flags.json
, pure: Flags.pure
}

lsDepsArgsParser :: Parser LsDepsArgs
lsDepsArgsParser = Optparse.fromRecord
{ json: Flags.json
, transitive: Flags.transitive
, selectedPackage: Flags.selectedPackage
, pure: Flags.pure
}

data Cmd a = Cmd'SpagoCmd (SpagoCmd a) | Cmd'VersionCmd Boolean
Expand Down Expand Up @@ -508,6 +526,8 @@ main = do
, selectedPackage: args.selectedPackage
, ensureRanges: false
, testDeps: false
, isRepl: false
, pure: false
}
void $ runSpago env (Sources.run { json: args.json })
Init args@{ useSolver } -> do
Expand All @@ -528,7 +548,7 @@ main = do
logInfo "Set up a new Spago project."
logInfo "Try running `spago run`"
Fetch args -> do
{ env, fetchOpts } <- mkFetchEnv offline args
{ env, fetchOpts } <- mkFetchEnv offline (Record.insert (Proxy :: _ "isRepl") false args)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for the choice to use insert here vs. merge on line 562? Arbitrary?

Copy link
Member Author

@f-f f-f Dec 11, 2023

Choose a reason for hiding this comment

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

I tend to use insert if I'm only dealing with one key, but if you prefer merge I could try to swap it in and see if that works (all the record things are quite finicky when it comes to envs, for some reason)

Copy link
Member

Choose a reason for hiding this comment

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

I don't prefer either, it just looked like you were using merge with one field below and I didn't know if there was a reason to choose one or another that emerged from your env-wrangling :)

void $ runSpago env (Fetch.run fetchOpts)
RegistrySearch args -> do
env <- mkRegistryEnv offline
Expand All @@ -539,8 +559,8 @@ main = do
RegistryPackageSets args -> do
env <- mkRegistryEnv offline
void $ runSpago env (RegistryCmd.packageSets args)
Install args@{ packages, selectedPackage, ensureRanges, testDeps } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages, selectedPackage, ensureRanges, testDeps }
Install args@{ packages, selectedPackage, ensureRanges, testDeps, pure } -> do
{ env, fetchOpts } <- mkFetchEnv offline (Record.merge args { isRepl: false })
dependencies <- runSpago env (Fetch.run fetchOpts)
let
buildArgs = Record.merge
Expand All @@ -552,17 +572,17 @@ main = do
let options = { depsOnly: true, pursArgs: List.toUnfoldable args.pursArgs, jsonErrors: false }
runSpago env' (Build.run options)
Uninstall { packagesToRemove, selectedPackage, testDeps } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: packagesToRemove, selectedPackage, ensureRanges: false, testDeps: false }
{ env, fetchOpts } <- mkFetchEnv offline { packages: packagesToRemove, selectedPackage, ensureRanges: false, testDeps: false, isRepl: false, pure: false }
let options = { testDeps, dependenciesToRemove: Set.fromFoldable fetchOpts.packages }
runSpago { workspace: env.workspace, logOptions: env.logOptions } (Uninstall.run options)
Build args@{ selectedPackage, ensureRanges, jsonErrors } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges, testDeps: false }
Build args@{ selectedPackage, ensureRanges, jsonErrors, pure } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges, pure, testDeps: false, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
buildEnv <- runSpago env (mkBuildEnv args dependencies)
let options = { depsOnly: false, pursArgs: List.toUnfoldable args.pursArgs, jsonErrors }
runSpago buildEnv (Build.run options)
Publish { selectedPackage } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges: false, testDeps: false }
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges: false, testDeps: false, isRepl: false, pure: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
publishEnv <- runSpago env (mkPublishEnv dependencies)
void $ runSpago publishEnv (Publish.publish {})
Expand Down Expand Up @@ -592,30 +612,32 @@ main = do
, selectedPackage
, ensureRanges: false
, testDeps: false
, isRepl: true
, pure: false
}
dependencies <- runSpago env (Fetch.run fetchOpts)
supportPackages <- runSpago env (SpagoRepl.supportPackage env.workspace.packageSet)
replEnv <- runSpago env (mkReplEnv args dependencies supportPackages)
void $ runSpago replEnv Repl.run

Bundle args@{ selectedPackage, ensureRanges } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges, testDeps: false }
Bundle args@{ selectedPackage, ensureRanges, pure } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges, pure, testDeps: false, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
buildEnv <- runSpago env (mkBuildEnv args dependencies)
let options = { depsOnly: false, pursArgs: List.toUnfoldable args.pursArgs, jsonErrors: false }
runSpago buildEnv (Build.run options)
bundleEnv <- runSpago env (mkBundleEnv args)
runSpago bundleEnv Bundle.run
Run args@{ selectedPackage, ensureRanges } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges, testDeps: false }
Run args@{ selectedPackage, ensureRanges, pure } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges, pure, testDeps: false, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
buildEnv <- runSpago env (mkBuildEnv args dependencies)
let options = { depsOnly: false, pursArgs: List.toUnfoldable args.pursArgs, jsonErrors: false }
runSpago buildEnv (Build.run options)
runEnv <- runSpago env (mkRunEnv args buildEnv)
runSpago runEnv Run.run
Test args@{ selectedPackage } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, ensureRanges: false, testDeps: false }
Test args@{ selectedPackage, pure } -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage, pure, ensureRanges: false, testDeps: false, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
buildEnv <- runSpago env (mkBuildEnv (Record.union args { ensureRanges: false }) dependencies)
let options = { depsOnly: false, pursArgs: List.toUnfoldable args.pursArgs, jsonErrors: false }
Expand All @@ -624,34 +646,34 @@ main = do
runSpago testEnv Test.run
LsPaths args -> do
runSpago { logOptions } $ Ls.listPaths args
LsPackages args -> do
let fetchArgs = { packages: mempty, selectedPackage: Nothing, ensureRanges: false, testDeps: false }
LsPackages args@{ pure } -> do
let fetchArgs = { packages: mempty, selectedPackage: Nothing, pure, ensureRanges: false, testDeps: false, isRepl: false }
{ env: env@{ workspace }, fetchOpts } <- mkFetchEnv offline fetchArgs
dependencies <- runSpago env (Fetch.run fetchOpts)
let lsEnv = { workspace, dependencies, logOptions }
runSpago lsEnv (Ls.listPackageSet args)
LsDeps { selectedPackage, json, transitive } -> do
let fetchArgs = { packages: mempty, selectedPackage, ensureRanges: false, testDeps: false }
LsDeps { selectedPackage, json, transitive, pure } -> do
let fetchArgs = { packages: mempty, selectedPackage, pure, ensureRanges: false, testDeps: false, isRepl: false }
{ env, fetchOpts } <- mkFetchEnv offline fetchArgs
dependencies <- runSpago env (Fetch.run fetchOpts)
lsEnv <- runSpago env (mkLsEnv dependencies)
runSpago lsEnv (Ls.listPackages { json, transitive })
Docs args -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, ensureRanges: false, testDeps: true }
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, pure: false, selectedPackage: Nothing, ensureRanges: false, testDeps: true, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
docsEnv <- runSpago env (mkDocsEnv args dependencies)
runSpago docsEnv Docs.run
Upgrade _args -> do
{ env } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, ensureRanges: false, testDeps: false }
{ env } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, pure: false, ensureRanges: false, testDeps: false, isRepl: false }
runSpago env Upgrade.run
-- TODO: add selected to graph commands
GraphModules args -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, ensureRanges: false, testDeps: false }
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, pure: false, ensureRanges: false, testDeps: false, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
purs <- Purs.getPurs
runSpago { dependencies, logOptions, purs, workspace: env.workspace } (Graph.graphModules args)
GraphPackages args -> do
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, ensureRanges: false, testDeps: false }
{ env, fetchOpts } <- mkFetchEnv offline { packages: mempty, selectedPackage: Nothing, pure: false, ensureRanges: false, testDeps: false, isRepl: false }
dependencies <- runSpago env (Fetch.run fetchOpts)
purs <- Purs.getPurs
runSpago { dependencies, logOptions, purs, workspace: env.workspace } (Graph.graphPackages args)
Expand Down Expand Up @@ -891,7 +913,7 @@ mkReplEnv replArgs dependencies supportPackage = do
, selected
}

mkFetchEnv :: forall a. OnlineStatus -> FetchArgs -> Spago (LogEnv a) { env :: Fetch.FetchEnv (), fetchOpts :: Fetch.FetchOpts }
mkFetchEnv :: forall a b. OnlineStatus -> { isRepl :: Boolean | FetchArgsRow b } -> Spago (LogEnv a) { env :: Fetch.FetchEnv (), fetchOpts :: Fetch.FetchOpts }
mkFetchEnv offline args = do
let
parsePackageName p = case PackageName.parse p of
Expand All @@ -906,8 +928,8 @@ mkFetchEnv offline args = do
Left _err -> die $ "Failed to parse selected package name, was: " <> show args.selectedPackage

env <- mkRegistryEnv offline
workspace <- runSpago env (Config.readWorkspace maybeSelectedPackage)
let fetchOpts = { packages: packageNames, ensureRanges: args.ensureRanges, isTest: args.testDeps }
workspace <- runSpago env (Config.readWorkspace maybeSelectedPackage args.pure)
let fetchOpts = { packages: packageNames, ensureRanges: args.ensureRanges, isTest: args.testDeps, isRepl: args.isRepl }
pure { fetchOpts, env: Record.union { workspace } env }

mkRegistryEnv :: forall a. OnlineStatus -> Spago (LogEnv a) (Registry.RegistryEnv ())
Expand Down
2 changes: 0 additions & 2 deletions core/src/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,10 @@ type WorkspaceConfig =
, extra_packages :: Maybe (Map PackageName ExtraPackage)
, backend :: Maybe BackendConfig
, build_opts :: Maybe WorkspaceBuildOptionsInput
, lock :: Maybe Boolean
}

workspaceConfigCodec :: JsonCodec WorkspaceConfig
workspaceConfigCodec = CA.object "WorkspaceConfig"
$ CA.recordPropOptional (Proxy :: _ "lock") CA.boolean
$ CA.recordPropOptional (Proxy :: _ "package_set") setAddressCodec
$ CA.recordPropOptional (Proxy :: _ "backend") backendConfigCodec
$ CA.recordPropOptional (Proxy :: _ "build_opts") buildOptionsCodec
Expand Down
Loading
Loading