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

Add --no-config-format flag. Fixes #300. #302

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
f-f marked this conversation as resolved.
Show resolved Hide resolved
`spago.dhall` during operations.
f-f marked this conversation as resolved.
Show resolved Hide resolved

## [0.8.5] - 2019-06-18

Expand Down
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -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`:
Expand Down
3 changes: 2 additions & 1 deletion app/Spago.hs
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Spago/Config.hs
Expand Up @@ -173,11 +173,12 @@ addSourcePaths expr = expr
withConfigAST :: Spago m => (Expr -> m Expr) -> m ()
withConfigAST transform = do
rawConfig <- liftIO $ Dhall.readRawExpr pathText
hasDontFormatConfig <- 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 hasDontFormatConfig pathText (header, newExpr)
where
transformMExpr
:: Spago m
Expand Down
11 changes: 6 additions & 5 deletions src/Spago/Dhall.hs
Expand Up @@ -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 ()
f-f marked this conversation as resolved.
Show resolved Hide resolved
writeRawExpr hasDontFormatConfig 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 hasDontFormatConfig $ do
aniketd marked this conversation as resolved.
Show resolved Hide resolved
writeTextFile (pathFromText pathText) $ prettyWithHeader header expr <> "\n"
format pathText


-- | Returns a Dhall Text literal from a lone string
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/PackageSet.hs
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Spago/Prelude.hs
Expand Up @@ -116,6 +116,7 @@ instance Show SpagoError where

data GlobalOptions = GlobalOptions
{ debug :: Bool
, dontFormatConfig :: Bool
}

type Spago m =
Expand Down