@@ -80,6 +80,9 @@ import Run (AFF, EFFECT, Run)
80
80
import Run as Run
81
81
import Run.Except (EXCEPT )
82
82
import Run.Except as Except
83
+ import Spago.Core.Config as Spago
84
+ import Spago.Core.Prelude as Spago.Prelude
85
+ import Spago.Log as Spago.Log
83
86
import Sunde as Sunde
84
87
85
88
-- | Operations can be exercised for old, pre-registry packages, or for packages
@@ -371,31 +374,58 @@ publish source payload = do
371
374
, " sources indicated by the `files` key in your manifest."
372
375
]
373
376
374
- -- If this is a legacy import, then we need to construct a `Manifest` for it.
377
+ -- If the package doesn't have a purs.json we can try to make one - possible scenarios:
378
+ -- - in case it has a spago.yaml then we know how to read that, and have all the info to move forward
379
+ -- - if it's a legacy import then we can try to infer as much info as possible to make a manifest
375
380
let packagePursJson = Path .concat [ packageDirectory, " purs.json" ]
376
381
hadPursJson <- Run .liftEffect $ FS.Sync .exists packagePursJson
377
382
unless hadPursJson do
378
- Notify .notify $ " Package source does not have a purs.json file. Creating one from your bower.json and/or spago.dhall files..."
379
- address <- case existingMetadata.location of
380
- Git _ -> Except .throw " Legacy packages can only come from GitHub."
381
- GitHub { subdir: Just subdir } -> Except .throw $ " Legacy packages cannot use the 'subdir' key, but this package specifies a " <> subdir <> " subdir."
382
- GitHub { owner, repo } -> pure { owner, repo }
383
-
384
- version <- case LenientVersion .parse payload.ref of
385
- Left _ -> Except .throw $ " The provided ref " <> payload.ref <> " is not a version of the form X.Y.Z or vX.Y.Z, so it cannot be used."
386
- Right result -> pure $ LenientVersion .version result
387
-
388
- Legacy.Manifest .fetchLegacyManifest payload.name address (RawVersion payload.ref) >>= case _ of
389
- Left manifestError -> do
390
- let formatError { error, reason } = reason <> " " <> Legacy.Manifest .printLegacyManifestError error
391
- Except .throw $ String .joinWith " \n "
392
- [ " Could not publish your package because there were issues converting its spago.dhall and/or bower.json files into a purs.json manifest:"
393
- , formatError manifestError
394
- ]
395
- Right legacyManifest -> do
396
- Log .debug $ " Successfully produced a legacy manifest from the package source. Writing it to the package source..."
397
- let manifest = Legacy.Manifest .toManifest payload.name version existingMetadata.location legacyManifest
398
- Run .liftAff $ writeJsonFile Manifest .codec packagePursJson manifest
383
+ let packageSpagoYaml = Path .concat [ packageDirectory, " spago.yaml" ]
384
+ hasSpagoYaml <- Run .liftEffect $ FS.Sync .exists packageSpagoYaml
385
+ case hasSpagoYaml of
386
+ true -> do
387
+ Notify .notify $ " Package source does not have a purs.json file, creating one from your spago.yaml file..."
388
+ -- Need to make a Spago log env first, disable the logging
389
+ let spagoEnv = { logOptions: { color: false , verbosity: Spago.Log.LogQuiet } }
390
+ maybeConfig <- Spago.Prelude .runSpago spagoEnv (Spago .readConfig packageSpagoYaml)
391
+ case maybeConfig of
392
+ Left err' -> Except .throw $ String .joinWith " \n "
393
+ [ " Could not publish your package - a spago.yaml was present, but it was not possible to read it:"
394
+ , err'
395
+ ]
396
+ Right { yaml: config } -> do
397
+ -- Once we have the config we are still not entirely sure it fits into a Manifest
398
+ -- E.g. need to make sure all the ranges are present
399
+ case spagoToManifest config of
400
+ Left err -> Except .throw $ String .joinWith " \n "
401
+ [ " Could not publish your package - there was an error while converting your spago.yaml into a purs.json manifest:"
402
+ , err
403
+ ]
404
+ Right manifest -> do
405
+ Log .debug " Successfully converted a spago.yaml into a purs.json manifest"
406
+ Run .liftAff $ writeJsonFile Manifest .codec packagePursJson manifest
407
+ false -> do
408
+ Notify .notify $ " Package source does not have a purs.json file. Creating one from your bower.json and/or spago.dhall files..."
409
+ address <- case existingMetadata.location of
410
+ Git _ -> Except .throw " Legacy packages can only come from GitHub."
411
+ GitHub { subdir: Just subdir } -> Except .throw $ " Legacy packages cannot use the 'subdir' key, but this package specifies a " <> subdir <> " subdir."
412
+ GitHub { owner, repo } -> pure { owner, repo }
413
+
414
+ version <- case LenientVersion .parse payload.ref of
415
+ Left _ -> Except .throw $ " The provided ref " <> payload.ref <> " is not a version of the form X.Y.Z or vX.Y.Z, so it cannot be used."
416
+ Right result -> pure $ LenientVersion .version result
417
+
418
+ Legacy.Manifest .fetchLegacyManifest payload.name address (RawVersion payload.ref) >>= case _ of
419
+ Left manifestError -> do
420
+ let formatError { error, reason } = reason <> " " <> Legacy.Manifest .printLegacyManifestError error
421
+ Except .throw $ String .joinWith " \n "
422
+ [ " Could not publish your package because there were issues converting its spago.dhall and/or bower.json files into a purs.json manifest:"
423
+ , formatError manifestError
424
+ ]
425
+ Right legacyManifest -> do
426
+ Log .debug $ " Successfully produced a legacy manifest from the package source. Writing it to the package source..."
427
+ let manifest = Legacy.Manifest .toManifest payload.name version existingMetadata.location legacyManifest
428
+ Run .liftAff $ writeJsonFile Manifest .codec packagePursJson manifest
399
429
400
430
Log .debug " A valid purs.json is available in the package source."
401
431
@@ -981,3 +1011,28 @@ getPacchettiBotti = do
981
1011
982
1012
packagingTeam :: Team
983
1013
packagingTeam = { org: " purescript" , team: " packaging" }
1014
+
1015
+ spagoToManifest :: Spago.Config -> Either String Manifest
1016
+ spagoToManifest config = do
1017
+ package@{ name, description, dependencies: Spago.Dependencies deps } <- note " Did not find a package in the config" config.package
1018
+ publishConfig@{ version, license } <- note " Did not find a `publish` section in the package config" package.publish
1019
+ location <- note " Did not find a `location` field in the publish config" publishConfig.location
1020
+ let
1021
+ checkRange :: Tuple PackageName (Maybe Range ) -> Either PackageName (Tuple PackageName Range )
1022
+ checkRange (Tuple packageName maybeRange) = case maybeRange of
1023
+ Nothing -> Left packageName
1024
+ Just r -> Right (Tuple packageName r)
1025
+ let { fail: failedPackages, success } = partitionEithers $ map checkRange (Map .toUnfoldable deps :: Array _ )
1026
+ dependencies <- case failedPackages of
1027
+ [] -> Right (Map .fromFoldable success)
1028
+ errs -> Left $ " The following packages did not have their ranges specified: " <> String .joinWith " , " (map PackageName .print errs)
1029
+ pure $ Manifest
1030
+ { version
1031
+ , license
1032
+ , name
1033
+ , location
1034
+ , description
1035
+ , dependencies
1036
+ , owners: Nothing -- TODO Spago still needs to add this to its config
1037
+ , files: Nothing -- TODO Spago still needs to add this to its config
1038
+ }
0 commit comments