diff --git a/app/Spago.hs b/app/Spago.hs index 8099e3e89..68f103171 100644 --- a/app/Spago.hs +++ b/app/Spago.hs @@ -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 @@ -114,6 +114,7 @@ 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 @@ -121,6 +122,11 @@ parser = do 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 @@ -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 diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 14fa3fdbf..303faab68 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -8,6 +8,7 @@ module Spago.Build , docs , Watch (..) , NoBuild (..) + , NoInstall (..) , BuildOptions (..) , Purs.ExtraArg (..) , Purs.ModuleName (..) @@ -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] } @@ -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 diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index f4bb16ae9..66ca6b629 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -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"