Skip to content

Commit 7b57771

Browse files
committed
compilers is a NonEmptyArray
1 parent 8c8d728 commit 7b57771

7 files changed

Lines changed: 20 additions & 41 deletions

File tree

app/src/App/API.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ publish maybeLegacyIndex payload = do
738738

739739
Storage.upload (un Manifest manifest).name (un Manifest manifest).version tarballPath
740740
Log.debug $ "Adding the new version " <> Version.print (un Manifest manifest).version <> " to the package metadata file."
741-
let newPublishedVersion = { hash, ref: payload.ref, compilers: Left payload.compiler, publishedTime, bytes }
741+
let newPublishedVersion = { hash, ref: payload.ref, compilers: NonEmptyArray.singleton payload.compiler, publishedTime, bytes }
742742
let newMetadata = metadata { published = Map.insert (un Manifest manifest).version newPublishedVersion metadata.published }
743743

744744
Registry.writeMetadata (un Manifest manifest).name (Metadata newMetadata)
@@ -786,7 +786,7 @@ publish maybeLegacyIndex payload = do
786786
Log.debug $ "Some compilers failed: " <> String.joinWith ", " (map Version.print (Set.toUnfoldable (Map.keys invalidCompilers)))
787787

788788
Comment.comment $ "Found compatible compilers: " <> String.joinWith ", " (map (\v -> "`" <> Version.print v <> "`") (NonEmptySet.toUnfoldable validCompilers))
789-
let compilersMetadata = newMetadata { published = Map.update (Just <<< (_ { compilers = Right (NonEmptySet.toUnfoldable1 validCompilers) })) (un Manifest manifest).version newMetadata.published }
789+
let compilersMetadata = newMetadata { published = Map.update (Just <<< (_ { compilers = NonEmptySet.toUnfoldable1 validCompilers })) (un Manifest manifest).version newMetadata.published }
790790
Registry.writeMetadata (un Manifest manifest).name (Metadata compilersMetadata)
791791
Log.debug $ "Wrote new metadata " <> printJson Metadata.codec (Metadata compilersMetadata)
792792

app/test/App/API.purs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,11 @@ spec = do
137137

138138
case Map.lookup version effectMetadata.published of
139139
Nothing -> Except.throw $ "Expected " <> formatPackageVersion name version <> " to be in metadata."
140-
Just published -> case published.compilers of
141-
Left one -> Except.throw $ "Expected " <> formatPackageVersion name version <> " to have a compiler matrix but unfinished single version: " <> Version.print one
142-
Right many -> do
143-
let many' = NonEmptyArray.toArray many
144-
let expected = map Utils.unsafeVersion [ "0.15.3", "0.15.4", "0.15.5" ]
145-
unless (many' == expected) do
146-
Except.throw $ "Expected " <> formatPackageVersion name version <> " to have a compiler matrix of " <> Utils.unsafeStringify (map Version.print expected) <> " but got " <> Utils.unsafeStringify (map Version.print many')
140+
Just published -> do
141+
let many' = NonEmptyArray.toArray published.compilers
142+
let expected = map Utils.unsafeVersion [ "0.15.3", "0.15.4", "0.15.5" ]
143+
unless (many' == expected) do
144+
Except.throw $ "Expected " <> formatPackageVersion name version <> " to have a compiler matrix of " <> Utils.unsafeStringify (map Version.print expected) <> " but got " <> Utils.unsafeStringify (map Version.print many')
147145

148146
-- Finally, we can verify that publishing the package again should fail
149147
-- since it already exists.
@@ -186,13 +184,11 @@ spec = do
186184

187185
case Map.lookup transitive.version transitiveMetadata.published of
188186
Nothing -> Except.throw $ "Expected " <> formatPackageVersion transitive.name transitive.version <> " to be in metadata."
189-
Just published -> case published.compilers of
190-
Left one -> Except.throw $ "Expected " <> formatPackageVersion transitive.name transitive.version <> " to have a compiler matrix but unfinished single version: " <> Version.print one
191-
Right many -> do
192-
let many' = NonEmptyArray.toArray many
193-
let expected = map Utils.unsafeVersion [ "0.15.3", "0.15.4", "0.15.5" ]
194-
unless (many' == expected) do
195-
Except.throw $ "Expected " <> formatPackageVersion transitive.name transitive.version <> " to have a compiler matrix of " <> Utils.unsafeStringify (map Version.print expected) <> " but got " <> Utils.unsafeStringify (map Version.print many')
187+
Just published -> do
188+
let many' = NonEmptyArray.toArray published.compilers
189+
let expected = map Utils.unsafeVersion [ "0.15.3", "0.15.4", "0.15.5" ]
190+
unless (many' == expected) do
191+
Except.throw $ "Expected " <> formatPackageVersion transitive.name transitive.version <> " to have a compiler matrix of " <> Utils.unsafeStringify (map Version.print expected) <> " but got " <> Utils.unsafeStringify (map Version.print many')
196192

197193
Registry.readManifest transitive.name transitive.version >>= case _ of
198194
Nothing -> Except.throw $ "Expected " <> PackageName.print transitive.name <> " to be in manifest index."

app/test/App/Legacy/PackageSet.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ unsafeMetadataEntry (Tuple name version) = do
209209
{ ref: LenientVersion.raw version
210210
, hash: unsafeFromRight $ Sha256.parse "sha256-gb24ZRec6mgR8TFBVR2eIh5vsMdhuL+zK9VKjWP74Cw="
211211
, bytes: 0.0
212-
, compilers: Right (NonEmptyArray.singleton (Utils.unsafeVersion "0.15.2"))
212+
, compilers: NonEmptyArray.singleton (Utils.unsafeVersion "0.15.2")
213213
, publishedTime: DateTime (Utils.unsafeDate "2022-07-07") bottom
214214
}
215215

lib/src/Metadata.purs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ codec = Profunctor.wrapIso Metadata $ CJ.named "Metadata" $ CJ.object
7373
-- | not rely on its presence!
7474
type PublishedMetadata =
7575
{ bytes :: Number
76-
, compilers :: Either Version (NonEmptyArray Version)
76+
, compilers :: NonEmptyArray Version
7777
, hash :: Sha256
7878
, publishedTime :: DateTime
7979

@@ -84,23 +84,11 @@ type PublishedMetadata =
8484
publishedMetadataCodec :: CJ.Codec PublishedMetadata
8585
publishedMetadataCodec = CJ.named "PublishedMetadata" $ CJ.Record.object
8686
{ bytes: CJ.number
87-
, compilers: compilersCodec
87+
, compilers: CJ.Common.nonEmptyArray Version.codec
8888
, hash: Sha256.codec
8989
, publishedTime: Internal.Codec.iso8601DateTime
9090
, ref: CJ.string
9191
}
92-
where
93-
compilersCodec :: CJ.Codec (Either Version (NonEmptyArray Version))
94-
compilersCodec = Codec.codec' decode encode
95-
where
96-
decode :: JSON -> Except CJ.DecodeError (Either Version (NonEmptyArray Version))
97-
decode json = except do
98-
map Left (CJ.decode Version.codec json)
99-
<|> map Right (CJ.decode (CJ.Common.nonEmptyArray Version.codec) json)
100-
101-
encode = case _ of
102-
Left version -> CJ.encode Version.codec version
103-
Right versions -> CJ.encode (CJ.Common.nonEmptyArray Version.codec) versions
10492

10593
-- | Metadata about an unpublished package version.
10694
type UnpublishedMetadata =

lib/src/Solver.purs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ buildCompilerIndex pursCompilers index metadata = CompilerIndex do
6363

6464
getDependencies (Manifest manifest) = fromMaybe manifest.dependencies do
6565
Metadata { published } <- Map.lookup manifest.name metadata
66-
{ compilers: eitherCompilers } <- Map.lookup manifest.version published
67-
-- If the dependency hasn't yet had all compilers computed for it,
68-
-- then we don't add it to the dependencies to avoid over-
69-
-- constraining the solver.
70-
compilers <- Either.hush eitherCompilers
71-
-- Otherwise, we construct a maximal range for the compilers the
66+
{ compilers } <- Map.lookup manifest.version published
67+
-- Construct a maximal range for the compilers the
7268
-- indicated package version supports.
7369
let
7470
min = Foldable1.minimum compilers

lib/test/Registry/Operation/Validation.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Test.Registry.Operation.Validation where
22

33
import Prelude
44

5+
import Data.Array.NonEmpty as NonEmptyArray
56
import Data.Either (Either(..))
67
import Data.Either as Either
78
import Data.Foldable (for_)
@@ -63,7 +64,7 @@ spec = do
6364
now = unsafeDateTime "2022-12-12T12:00:00.000Z"
6465
outOfRange = unsafeDateTime "2022-12-10T11:00:00.000Z"
6566
inRange = unsafeDateTime "2022-12-11T12:00:00.000Z"
66-
compilers = Left (unsafeVersion "0.13.0")
67+
compilers = NonEmptyArray.singleton (unsafeVersion "0.13.0")
6768

6869
publishedMetadata = { bytes: 100.0, hash: defaultHash, publishedTime: outOfRange, compilers, ref: "" }
6970

scripts/src/LegacyImporter.purs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,7 @@ compatibleCompilers allMetadata resolutions = do
13291329
associated = Map.toUnfoldableUnordered resolutions # Array.mapMaybe \(Tuple name version) -> do
13301330
Metadata metadata <- Map.lookup name allMetadata
13311331
published <- Map.lookup version metadata.published
1332-
case published.compilers of
1333-
Left _ -> Nothing
1334-
Right compilers -> Just { name, version, compilers: compilers }
1332+
Just { name, version, compilers: published.compilers }
13351333

13361334
case Array.uncons associated of
13371335
Nothing ->

0 commit comments

Comments
 (0)