Skip to content

Commit

Permalink
Add --no-config-format global flag. Fixes purescript#300.
Browse files Browse the repository at this point in the history
- Add `dontFormatConfig` to `GlobalOptions`
- Add condition to `Spago.Dhall.writeRawExpr` with `Bool` parameter
  • Loading branch information
Aniket Deshpande committed Jul 5, 2019
1 parent a77b869 commit be3041e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
`spago.dhall` during operations.

## [0.8.5] - 2019-06-18

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 ()
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
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ instance Show SpagoError where

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

type Spago m =
Expand Down

0 comments on commit be3041e

Please sign in to comment.