diff --git a/CHANGELOG.md b/CHANGELOG.md index 1653b2673..0559c3fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Bugfixes: New features: - Add support for starting a repl within a folder which has not been setup as a spago project (#168) - Add `--format` flag to `spago docs` (#294) +- Add `--no-config-format` global flag. Fixes #300. Skips formatting + `spago.dhall` during operations. ## [0.8.5] - 2019-06-18 diff --git a/README.md b/README.md index 50440b05f..6c16f6625 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,17 @@ $ spago run --node-args "arg1 arg2" ``` +### Avoid re-formatting the `spago.dhall` and `packages.dhall` with each command + +You can pass the `--no-config-format` or `-F` global flag: + +``` bash +$ spago build -F +Installation complete. +Build succeeded. +``` + + ### Test my project You can also test your project with `spago`: diff --git a/app/Spago.hs b/app/Spago.hs index 0307afe6f..092291ca9 100644 --- a/app/Spago.hs +++ b/app/Spago.hs @@ -114,6 +114,7 @@ parser = do where 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" + noConfigFormat = CLI.switch "no-config-format" 'F' "Disable formatting the configuration file `spago.dhall`" 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)" @@ -160,7 +161,7 @@ parser = do replPackageNames = CLI.many $ CLI.opt (Just . PackageName) "dependency" 'd' "Package name to add to the REPL 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 <*> noInstall <*> passthroughArgs - globalOptions = GlobalOptions <$> verbose + globalOptions = GlobalOptions <$> verbose <*> noConfigFormat packagesFilter = let wrap = \case "direct" -> Just DirectDeps diff --git a/src/Spago/Config.hs b/src/Spago/Config.hs index 16a473157..3ea3a43c6 100644 --- a/src/Spago/Config.hs +++ b/src/Spago/Config.hs @@ -173,11 +173,12 @@ addSourcePaths expr = expr withConfigAST :: Spago m => (Expr -> m Expr) -> m () withConfigAST transform = do rawConfig <- liftIO $ Dhall.readRawExpr pathText + hasNoConfigFormat <- asks dontFormatConfig case rawConfig of Nothing -> die Messages.cannotFindConfig Just (header, expr) -> do newExpr <- transformMExpr transform expr - liftIO $ Dhall.writeRawExpr pathText (header, newExpr) + liftIO $ Dhall.writeRawExpr hasNoConfigFormat pathText (header, newExpr) where transformMExpr :: Spago m diff --git a/src/Spago/Dhall.hs b/src/Spago/Dhall.hs index 59f9b6256..f1ec64d7c 100644 --- a/src/Spago/Dhall.hs +++ b/src/Spago/Dhall.hs @@ -50,14 +50,15 @@ readRawExpr pathText = do else (pure Nothing) -writeRawExpr :: Text -> (Text, DhallExpr Dhall.Import) -> IO () -writeRawExpr pathText (header, expr) = do +writeRawExpr :: Bool -> Text -> (Text, DhallExpr Dhall.Import) -> IO () +writeRawExpr hasNoConfigFormat pathText (header, expr) = do -- After modifying the expression, we have to check if it still typechecks -- if it doesn't we don't write to file. resolvedExpr <- Dhall.Import.load expr - throws (Dhall.TypeCheck.typeOf resolvedExpr) - writeTextFile (pathFromText pathText) $ prettyWithHeader header expr <> "\n" - format pathText + _ <- throws (Dhall.TypeCheck.typeOf resolvedExpr) + unless hasNoConfigFormat $ do + writeTextFile (pathFromText pathText) $ prettyWithHeader header expr <> "\n" + format pathText -- | Returns a Dhall Text literal from a lone string diff --git a/src/Spago/PackageSet.hs b/src/Spago/PackageSet.hs index 06d375ccc..2161696e9 100644 --- a/src/Spago/PackageSet.hs +++ b/src/Spago/PackageSet.hs @@ -116,7 +116,7 @@ upgradePackageSet = do echo $ "Upgrading the package set version to " <> quotedTag let newExpr = fmap (upgradeImports releaseTagName) expr echo $ Messages.upgradingPackageSet releaseTagName - liftIO $ Dhall.writeRawExpr pathText (header, newExpr) + liftIO $ Dhall.writeRawExpr False pathText (header, newExpr) -- If everything is fine, refreeze the imports freeze where diff --git a/src/Spago/Prelude.hs b/src/Spago/Prelude.hs index c713374d3..725354350 100644 --- a/src/Spago/Prelude.hs +++ b/src/Spago/Prelude.hs @@ -116,6 +116,7 @@ instance Show SpagoError where data GlobalOptions = GlobalOptions { debug :: Bool + , dontFormatConfig :: Bool } type Spago m =