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
This commit is contained in:
Tissevert 2023-03-14 22:46:47 +01:00
parent db7b0b5d89
commit d6553047d6
6 changed files with 36 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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"
]

View File

@ -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

View File

@ -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}

View File

@ -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]