From d6553047d6f67a9507ac0b1741c8620900c0bd37 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 14 Mar 2023 22:46:47 +0100 Subject: [PATCH] Release 0.1.3.1 * Upgrade code to run with base 4.16 * Stop using cabal-generated module * Fix sjw not returning with exit code 1 on errors --- CHANGELOG.md | 6 ++++++ SJW.cabal | 6 ++---- benchmark/Main.hs | 22 +++++++++++++++------- src/Main.hs | 22 ++++++++++++---------- src/SJW.hs | 7 ------- src/SJW/Dependencies.hs | 2 +- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5af1b8..74d16f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Revision history for SJW +## 0.1.3.1 -- 2023-03-14 + +* Upgrade code to run with base 4.16 +* Stop using cabal-generated module +* Fix sjw not returning with exit code 1 on errors + ## 0.1.3.0 -- 2022-08-09 * Add support for disjunct package folders diff --git a/SJW.cabal b/SJW.cabal index 4148fdf..68970d1 100644 --- a/SJW.cabal +++ b/SJW.cabal @@ -3,7 +3,7 @@ cabal-version: 2.4 -- further documentation, see http://haskell.org/cabal/users-guide/ name: SJW -version: 0.1.3.0 +version: 0.1.3.1 synopsis: The Simple Javascript Wrench description: SJW is a very simple tool to pack several JS modules into a single script. @@ -35,7 +35,7 @@ library , SJW.Module.Imports , SJW.Source build-depends: attoparsec >= 0.13.2 && < 0.15 - , base >=4.9 && <4.16 + , base >=4.9 && <4.17 , containers >= 0.5.0 && < 0.7 , directory >= 1.2.0 && < 1.4 , filepath >= 1.4.2 && < 1.5 @@ -50,8 +50,6 @@ library executable sjw main-is: src/Main.hs - other-modules: Paths_SJW - autogen-modules: Paths_SJW -- other-extensions: build-depends: attoparsec , base diff --git a/benchmark/Main.hs b/benchmark/Main.hs index 6ae0dc6..256c09f 100644 --- a/benchmark/Main.hs +++ b/benchmark/Main.hs @@ -19,10 +19,11 @@ {-# LANGUAGE NamedFieldPuns #-} module Main where -import SJW (Path(..), compile, source, sourceCode) +import SJW (Path(..), compile, source) import Control.Monad (foldM) import Data.Time.Clock (diffUTCTime, getCurrentTime) import System.Directory (createDirectoryIfMissing, doesDirectoryExist) +import System.Exit (die) import System.FilePath ((), (<.>)) import System.Random (randomRIO) import Text.Printf (printf) @@ -107,9 +108,16 @@ main = do generateDAG 10000 10 (50, 100) >>= mapM_ writeFakeModule else return () start <- getCurrentTime - maybe (return ()) (\_ -> return ()) =<< sourceCode =<< compile (source [destDir]) - end <- getCurrentTime - mapM_ putStrLn [ - "Compiled 10k modules in " ++ show (diffUTCTime end start) - , "Left the fake project in " ++ destDir ++ " if you want to poke around" - ] + compile (source [destDir]) >>= either fails (succeeds start) + where + fails errorMsg = die $ + printf + "%s\nThe benchmark crashed and failed to compile the modules generated in %s" + errorMsg + destDir + succeeds start _ = do + end <- getCurrentTime + mapM_ putStrLn [ + "Compiled 10k modules in " ++ show (diffUTCTime end start) + , "Left the fake project in " ++ destDir ++ " if you want to poke around" + ] diff --git a/src/Main.hs b/src/Main.hs index 940a463..a17b621 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -24,14 +24,18 @@ import Control.Applicative (many, optional) #if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>)) #endif -import qualified Data.Text as Text (unpack) -import Data.Version (showVersion) +import qualified Data.Text.IO as Text (putStr, writeFile) +import Data.Version (Version(..), showVersion) import Options.Applicative ( Parser, execParser, fullDesc, info, header, help, helper, long, metavar , short, strArgument, strOption, value ) -import Paths_SJW (version) -import SJW (Source, compile, mainIs, source, sourceCode) +import SJW (Source, compile, mainIs, source) +import System.Exit (die) +import System.IO (stderr, hPutStrLn) + +version :: Version +version = Version [0, 1, 3, 1] [] data Config = Config { includes :: [String] @@ -81,10 +85,8 @@ getSource (Config {includes, mainModuleName = Just moduleName, target}) = main :: IO () main = do config@(Config {outputFile}) <- getConfig - result <- SJW.sourceCode =<< SJW.compile (getSource config) - case result of - Nothing -> return () - Just code -> output outputFile $ Text.unpack code + SJW.compile (getSource config) >>= either die (logAnd (write outputFile)) where - output "-" = putStr - output fileName = writeFile fileName + logAnd f (a, logs) = mapM_ (hPutStrLn stderr) logs *> f a + write "-" = Text.putStr + write fileName = Text.writeFile fileName diff --git a/src/SJW.hs b/src/SJW.hs index 571d271..0b419eb 100644 --- a/src/SJW.hs +++ b/src/SJW.hs @@ -24,7 +24,6 @@ module SJW ( , compile , mainIs , source - , sourceCode ) where import Control.Applicative ((<|>)) @@ -41,7 +40,6 @@ import SJW.Source (CodePath(..), Source(..), Path(..), source) import System.Directory (doesDirectoryExist) import System.Environment (lookupEnv) import System.FilePath (()) -import System.IO (stderr, hPutStrLn) import System.Posix.User (getRealUserID, getUserEntryForID, homeDirectory) import Text.Printf (printf) @@ -58,11 +56,6 @@ compile inputSource = runExceptT $ do modules = Map.empty } -sourceCode :: Result -> IO (Maybe Text) -sourceCode (Left errorMessage) = hPutStrLn stderr errorMessage >> return Nothing -sourceCode (Right (output, logs)) = - mapM_ (hPutStrLn stderr) logs >> return (Just output) - mainIs :: Source -> String -> Source mainIs context dotSeparated = context {mainModule = read dotSeparated} diff --git a/src/SJW/Dependencies.hs b/src/SJW/Dependencies.hs index 3e1134d..aee559d 100644 --- a/src/SJW/Dependencies.hs +++ b/src/SJW/Dependencies.hs @@ -73,7 +73,7 @@ visit (loopStart, (Temporary, _)) = do throwError $ printLoop loop visit (path, (New, set)) = do modifyState ((path, Temporary), (path:)) - mapM_ (\depPath -> (,) depPath <$> gets ((!depPath) . graph) >>= visit) set + mapM_ (\depPath -> (,) depPath <$> gets ((! depPath) . graph) >>= visit) set modifyState ((path, Permanent), (drop 1)) tell [path]