Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions app/Spago.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import qualified Turtle as CLI

import Spago.Build (BuildOptions (..), ExtraArg (..), ModuleName (..),
NoBuild (..), SourcePath (..), TargetPath (..), Watch (..),
WithMain (..))
WithMain (..), NoInstall (..))
import qualified Spago.Build
import Spago.GlobalCache (CacheFlag (..))
import Spago.Messages as Messages
Expand Down Expand Up @@ -114,13 +114,19 @@ parser = do
force = CLI.switch "force" 'f' "Overwrite any project found in the current directory"
verbose = CLI.switch "verbose" 'v' "Enable additional debug logging, e.g. printing `purs` commands"
watchBool = CLI.switch "watch" 'w' "Watch for changes in local files and automatically rebuild"
noInstallBool = CLI.switch "no-install" 'n' "Don't run the automatic installation of packages"
clearScreenBool = CLI.switch "clear-screen" 'l' "Clear the screen on rebuild (watch mode only)"
noBuildBool = CLI.switch "no-build" 's' "Skip build step"
watch = do
res <- watchBool
pure $ case res of
True -> Watch
False -> BuildOnce
noInstall = do
res <- noInstallBool
pure $ case res of
True -> NoInstall
False -> DoInstall
clearScreen = do
res <- clearScreenBool
pure $ case res of
Expand Down Expand Up @@ -150,7 +156,7 @@ parser = do
packageName = CLI.arg (Just . PackageName) "package" "Specify a package name. You can list them with `list-packages`"
packageNames = CLI.many $ CLI.arg (Just . PackageName) "package" "Package name to add as dependency"
passthroughArgs = many $ CLI.arg (Just . ExtraArg) " ..any `purs compile` option" "Options passed through to `purs compile`; use -- to separate"
buildOptions = BuildOptions <$> limitJobs <*> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> passthroughArgs
buildOptions = BuildOptions <$> limitJobs <*> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> noInstall <*> passthroughArgs
globalOptions = GlobalOptions <$> verbose
packagesFilter =
let wrap = \case
Expand Down
9 changes: 8 additions & 1 deletion src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Spago.Build
, docs
, Watch (..)
, NoBuild (..)
, NoInstall (..)
, BuildOptions (..)
, Purs.ExtraArg (..)
, Purs.ModuleName (..)
Expand Down Expand Up @@ -37,12 +38,16 @@ data Watch = Watch | BuildOnce
-- or skip it, in the case of 'bundleApp' and 'bundleModule'.
data NoBuild = NoBuild | DoBuild

-- | Flag to skip the automatic installation of libraries on build
data NoInstall = NoInstall | DoInstall

data BuildOptions = BuildOptions
{ maybeLimit :: Maybe Int
, cacheConfig :: Maybe GlobalCache.CacheFlag
, shouldWatch :: Watch
, shouldClear :: Watch.ClearScreen
, sourcePaths :: [Purs.SourcePath]
, noInstall :: NoInstall
, passthroughArgs :: [Purs.ExtraArg]
}

Expand All @@ -63,7 +68,9 @@ build BuildOptions{..} maybePostBuild = do
echoDebug "Running `spago build`"
config@Config.Config{ packageSet = PackageSet.PackageSet{..}, ..} <- Config.ensureConfig
deps <- Packages.getProjectDeps config
Fetch.fetchPackages maybeLimit cacheConfig deps packagesMinPursVersion
case noInstall of
DoInstall -> Fetch.fetchPackages maybeLimit cacheConfig deps packagesMinPursVersion
NoInstall -> pure ()
let projectGlobs = configSourcePaths <> sourcePaths
allGlobs = Packages.getGlobs deps <> projectGlobs
buildAction = do
Expand Down
10 changes: 9 additions & 1 deletion test/SpagoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,22 @@ spec = around_ setup $ do
mv "src/Main.purs" "another_source_path/Main.purs"
spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess

it "Spago should not install packages when passing the --no-install flag" $ do

spago ["init"] >>= shouldBeSuccess
spago ["build", "--no-install"] >>= shouldBeFailure
spago ["install"] >>= shouldBeSuccess
spago ["build", "--no-install"] >>= shouldBeSuccess

it "Spago should add sources to config when key is missing" $ do

configV1 <- readFixture "spago-configV1.dhall"
spago ["init"] >>= shouldBeSuccess
-- Replace initial config with the old config format (without 'sources')
mv "spago.dhall" "spago-old.dhall"
writeTextFile "spago.dhall" configV1

spago ["build"] >>= shouldBeSuccess
spago ["install"] >>= shouldBeSuccess
mv "spago.dhall" "spago-configV2.dhall"
checkFixture "spago-configV2.dhall"

Expand Down