diff --git a/README.md b/README.md index 9ba2b2edd..4dca66c03 100644 --- a/README.md +++ b/README.md @@ -1428,6 +1428,9 @@ package: # The registry will then check if the package version is included # in this range. - package-with-range: ">=1.1.1 <2.0.0" + # 4) specify an exact version + # Shorthand for ">=1.2.3 <1.2.4", pinning to a specific patch version. + - package-with-exact-version: "1.2.3" # Optional description for the package description: "a useful package" diff --git a/core/src/Config.purs b/core/src/Config.purs index 5e9339243..148d5ff91 100644 --- a/core/src/Config.purs +++ b/core/src/Config.purs @@ -324,7 +324,11 @@ spagoRangeCodec = CJ.prismaticCodec "SpagoRange" rangeParse printSpagoRange CJ.s where rangeParse str = if str == "*" then Just widestRange - else hush $ Range.parse str + -- First try parsing as a range (e.g. ">=1.0.0 <2.0.0") + else case hush $ Range.parse str of + Just range -> Just range + -- Then try parsing as an exact version (e.g. "1.0.0" -> ">=1.0.0 <1.0.1") + Nothing -> Range.exact <$> hush (Version.parse str) printSpagoRange :: Range -> String printSpagoRange range = diff --git a/spago.lock b/spago.lock index c56cf1a3c..22c0eb8c9 100644 --- a/spago.lock +++ b/spago.lock @@ -1772,7 +1772,7 @@ }, "registry-lib": { "git": "https://github.com/purescript/registry-dev.git", - "ref": "fc203a9e2a0b96a90ace20dc6958c157cbbca16b", + "ref": "43194a1f079ed1e0b8e17c5d9a0e9c213ed40f49", "subdir": "lib" }, "search-trie": { @@ -3436,7 +3436,7 @@ "registry-lib": { "type": "git", "url": "https://github.com/purescript/registry-dev.git", - "rev": "fc203a9e2a0b96a90ace20dc6958c157cbbca16b", + "rev": "43194a1f079ed1e0b8e17c5d9a0e9c213ed40f49", "subdir": "lib", "dependencies": [ "aff", diff --git a/spago.yaml b/spago.yaml index 469056525..c756a6dc4 100644 --- a/spago.yaml +++ b/spago.yaml @@ -88,7 +88,7 @@ workspace: extraPackages: registry-lib: git: https://github.com/purescript/registry-dev.git - ref: fc203a9e2a0b96a90ace20dc6958c157cbbca16b + ref: 43194a1f079ed1e0b8e17c5d9a0e9c213ed40f49 subdir: lib html-parser-halogen: dependencies: diff --git a/test/Spago/Config.purs b/test/Spago/Config.purs index 35b8b4322..bed40f10c 100644 --- a/test/Spago/Config.purs +++ b/test/Spago/Config.purs @@ -3,10 +3,12 @@ module Test.Spago.Config where import Test.Prelude import Codec.JSON.DecodeError as CJ +import Data.Map as Map import Data.String as String import Registry.License as License import Registry.Location (Location(..)) import Registry.PackageName as PackageName +import Registry.Range as Range import Registry.Version as Version import Spago.Core.Config (SetAddress(..)) import Spago.Core.Config as C @@ -35,6 +37,19 @@ spec = <> "\n\n\n-------\nActual:\n-------\n" <> Yaml.stringifyYaml C.configCodec parsed + Spec.it "parses exact version ranges (e.g. '1.0.0' -> '>=1.0.0 <1.0.1')" do + let + yaml = """ + package: + name: test + dependencies: + - prelude: "6.0.1" + """ + parsed = unsafeFromRight $ Yaml.parseYaml C.configCodec yaml + C.Dependencies deps = (unsafeFromJust parsed.package).dependencies + actual = Map.lookup (mkPackageName "prelude") deps <#> map Range.print + actual `Assert.shouldEqual` Just (Just ">=6.0.1 <6.0.2") + Spec.it "reports errors" do Yaml.parseYaml C.configCodec invalidLicenseYaml `shouldFailWith` ( "$.package.publish.license: Could not decode PackageConfig:"