packages feed

hpack 0.24.0 → 0.25.0

raw patch · 4 files changed

+51/−27 lines, 4 filesdep ~GlobPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: Glob

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,4 +1,7 @@-## next+## Changes in 0.25.0+  - Keep non-existing literal files on glob expansion (see #101)++## Changes in 0.24.0   - Add support for `verbatim` Cabal escape hatch   - Allow `version` be a numbers   - Ignore fields that start with an underscore everywhere, not just globally
hpack.cabal view
@@ -1,11 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.23.0.+-- This file has been generated from package.yaml by hpack version 0.24.0. -- -- see: https://github.com/sol/hpack ----- hash: 0260680387a428cfeb1d8d836b9a16adc24a270dd054e78b49d6b13693dcadcd+-- hash: bdc3b02a4c50d7839928d668388a26aa10ba6b493748bcfc2eb9cabd61cc016d  name:           hpack-version:        0.24.0+version:        0.25.0 synopsis:       An alternative format for Haskell packages description:    See README at <https://github.com/sol/hpack#readme> category:       Development@@ -30,7 +30,7 @@   ghc-options: -Wall   build-depends:       Cabal-    , Glob+    , Glob >=0.9.0     , aeson >=1.0.0     , base >=4.8 && <5     , bifunctors@@ -81,7 +81,7 @@   ghc-options: -Wall   build-depends:       Cabal-    , Glob+    , Glob >=0.9.0     , aeson >=1.0.0     , base >=4.8 && <5     , bifunctors@@ -116,7 +116,7 @@   cpp-options: -DTEST   build-depends:       Cabal-    , Glob+    , Glob >=0.9.0     , HUnit     , QuickCheck     , aeson >=1.0.0
src/Hpack/Util.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} module Hpack.Util (   GhcOption , GhcProfOption@@ -20,6 +19,7 @@ import           Control.Exception import           Control.Monad import           Data.Char+import           Data.Bifunctor import           Data.List hiding (sort) import           Data.Ord import           System.IO.Error@@ -100,23 +100,40 @@ toPosixFilePath :: FilePath -> FilePath toPosixFilePath = Posix.joinPath . splitDirectories +data GlobResult = GlobResult {+  _globResultPattern :: String+, _globResultCompiledPattern :: Pattern+, _globResultFiles :: [FilePath]+}+ expandGlobs :: String -> FilePath -> [String] -> IO ([String], [FilePath]) expandGlobs name dir patterns = do-  files <- globDir_ compiledPatterns dir >>= mapM removeDirectories-  let warnings = [warn pattern | ([], pattern) <- zip files patterns]-  return (warnings, combineResults files)+  files <- globDir compiledPatterns dir >>= mapM removeDirectories+  let+    results :: [GlobResult]+    results = map (uncurry $ uncurry GlobResult) $ zip (zip patterns compiledPatterns) files+  return (combineResults results)   where-    globDir_ :: [Pattern] -> FilePath -> IO [[FilePath]]-#if MIN_VERSION_Glob(0,9,0)-    globDir_ = globDir-#else-    globDir_ xs = fmap fst . globDir xs-#endif-    combineResults :: [[FilePath]] -> [FilePath]-    combineResults = nub . sort . map (toPosixFilePath . makeRelative dir) . concat+    combineResults :: [GlobResult] -> ([String], [FilePath])+    combineResults = bimap concat (nub . sort . concat) . unzip . map fromResult -    warn :: String -> String-    warn pattern = "Specified pattern " ++ show pattern ++ " for " ++ name ++ " does not match any files"+    fromResult :: GlobResult -> ([String], [FilePath])+    fromResult (GlobResult pattern compiledPattern files) = case files of+      [] -> (warning, literalFile)+      xs -> ([], map normalize xs)+      where+        warning = [warn pattern compiledPattern]+        literalFile+          | isLiteral compiledPattern = [pattern]+          | otherwise = []++    normalize :: FilePath -> FilePath+    normalize = toPosixFilePath . makeRelative dir++    warn :: String -> Pattern -> String+    warn pattern compiledPattern+      | isLiteral compiledPattern = "Specified file " ++ show pattern ++ " for " ++ name ++ " does not exist"+      | otherwise = "Specified pattern " ++ show pattern ++ " for " ++ name ++ " does not match any files"      compiledPatterns :: [Pattern]     compiledPatterns = map (compileWith options) patterns
test/Hpack/UtilSpec.hs view
@@ -77,8 +77,8 @@    describe "expandGlobs" $ around withTempDirectory $ do     it "accepts simple files" $ \dir -> do-        touch (dir </> "foo.js")-        expandGlobs "field-name" dir ["foo.js"] `shouldReturn` ([], ["foo.js"])+      touch (dir </> "foo.js")+      expandGlobs "field-name" dir ["foo.js"] `shouldReturn` ([], ["foo.js"])      it "removes duplicates" $ \dir -> do       touch (dir </> "foo.js")@@ -128,11 +128,15 @@      context "when a pattern does not match anything" $ do       it "warns" $ \dir -> do-        expandGlobs "field-name" dir ["foo"] `shouldReturn`-          (["Specified pattern \"foo\" for field-name does not match any files"], [])+        expandGlobs "field-name" dir ["*.foo"] `shouldReturn`+          (["Specified pattern \"*.foo\" for field-name does not match any files"], [])      context "when a pattern only matches a directory" $ do       it "warns" $ \dir -> do         createDirectory (dir </> "foo")-        expandGlobs "field-name" dir ["foo"] `shouldReturn`-          (["Specified pattern \"foo\" for field-name does not match any files"], [])+        expandGlobs "field-name" dir ["fo?"] `shouldReturn`+          (["Specified pattern \"fo?\" for field-name does not match any files"], [])++    context "when a literal file does not exist" $ do+      it "warns and keeps the file" $ \dir -> do+        expandGlobs "field-name" dir ["foo.js"] `shouldReturn` (["Specified file \"foo.js\" for field-name does not exist"], ["foo.js"])