Skip to content

Commit

Permalink
Remove commands for interop with psc-package (#425)
Browse files Browse the repository at this point in the history
* Remove commands for interop with psc-package

* Remove psc-package tests
  • Loading branch information
f-f authored and mergify[bot] committed Sep 30, 2019
1 parent 85e875d commit 92ea1e6
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 269 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

Breaking changes (😱!!!):
- **Remove `psc-package`-related commands (#423)**

Since `psc-package` is now deprecated, we no longer support the
`psc-package-local-setup`, `psc-package-insdhall` and `psc-package-clean` commands.

New features:
- Display a link to the generated docs' `index.html` (#379)
- Add `--open` flag to `spago docs` which opens generated docs in browser (#379)
Expand Down
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ $ node .
- [Generate documentation for my project](#generate-documentation-for-my-project)
- [Get source maps for my project](#get-source-maps-for-my-project)
- [Publish my library](#publish-my-library)
- [Use this together with `psc-package`](#use-this-together-with-psc-package)
- [Get all the licenses of my dependencies](#get-all-the-licenses-of-my-dependencies)
- [Know which `purs` commands are run under the hood](#know-which-purs-commands-are-run-under-the-hood)
- [Ignore or update the global cache](#ignore-or-update-the-global-cache)
Expand Down Expand Up @@ -784,27 +783,6 @@ All of this will be automated in future versions, removing the need for Pulp.
A library published in this way is [purescript-rave](https://github.com/reactormonk/purescript-rave).
### Use this together with `psc-package`
`spago` can help you setup your `psc-package` project to use the Dhall version of the package set.
We have two commands for it:
- **`psc-package-local-setup`**: this command creates a `packages.dhall` file in your project,
that points to the most recent package set, and lets you override and add arbitrary packages.
See the docs about this [here][package-sets].
- **`psc-package-insdhall`**: do the *Ins-Dhall-ation* of the local project setup: that is,
generates a local package set for `psc-package` from your `packages.dhall`, and points your
`psc-package.json` to it.
Functionally this is equivalent to running:
```sh
NAME='local'
TARGET=.psc-package/$NAME/.set/packages.json
mkdir -p .psc-package/$NAME/.set
dhall-to-json --pretty <<< './packages.dhall' > $TARGET
echo wrote packages.json to $TARGET
```
### Get all the licenses of my dependencies
Expand Down
52 changes: 1 addition & 51 deletions app/Spago.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Spago.GlobalCache (CacheFlag (..))
import Spago.Messages as Messages
import Spago.Packages (JsonFlag (..), PackagesFilter (..))
import qualified Spago.Packages
import qualified Spago.PscPackage as PscPackage
import qualified Spago.Purs as Purs
import Spago.Types
import qualified Spago.Version
Expand Down Expand Up @@ -88,26 +87,6 @@ data Command
-- | Freeze the package-set so it will be cached
| Freeze

-- | ### Commands for working with Psc-Package
--
-- Do the boilerplate of the local project setup to override and add arbitrary packages
-- See the package-sets docs about this here:
-- https://github.com/purescript/package-sets
| PscPackageLocalSetup Bool

-- | Do the Ins-Dhall-ation of the local project setup, equivalent to:
-- ```sh
-- NAME='local'
-- TARGET=.psc-package/$NAME/.set/packages.json
-- mktree -p .psc-package/$NAME/.set
-- dhall-to-json --pretty <<< './packages.dhall' > $TARGET
-- echo wrote packages.json to $TARGET
-- ```
| PscPackageInsDhall

-- | Deletes the .psc-package folder
| PscPackageClean

-- | Runs `purescript-docs-search search`.
| Search

Expand All @@ -123,7 +102,7 @@ data Command
parser :: CLI.Parser (Command, GlobalOptions)
parser = do
opts <- globalOptions
command <- projectCommands <|> packageSetCommands <|> publishCommands <|> pscPackageCommands <|> otherCommands <|> oldCommands
command <- projectCommands <|> packageSetCommands <|> publishCommands <|> otherCommands <|> oldCommands
pure (command, opts)
where
cacheFlag =
Expand Down Expand Up @@ -316,32 +295,6 @@ parser = do
, BumpVersion <$> dryRun <*> versionBump
)


pscPackageCommands = CLI.subcommandGroup "Psc-Package compatibility commands:"
[ pscPackageLocalSetup
, pscPackageInsDhall
, pscPackageClean
]

pscPackageLocalSetup =
( "psc-package-local-setup"
, "Setup a local package set by creating a new packages.dhall"
, PscPackageLocalSetup <$> force
)

pscPackageInsDhall =
( "psc-package-insdhall"
, "Insdhall the local package set from packages.dhall"
, pure PscPackageInsDhall
)

pscPackageClean =
( "psc-package-clean"
, "Clean cached packages by deleting the .psc-package folder"
, pure PscPackageClean
)


otherCommands = CLI.subcommandGroup "Other commands:"
[ version
]
Expand Down Expand Up @@ -402,8 +355,5 @@ main = do
-> Spago.Build.docs format sourcePaths depsOnly noSearch openDocs
Search -> Spago.Build.search
Version -> printVersion
PscPackageLocalSetup force -> PscPackage.localSetup force
PscPackageInsDhall -> PscPackage.insDhall
PscPackageClean -> PscPackage.clean
Bundle -> die Messages.bundleCommandRenamed
MakeModule -> die Messages.makeModuleCommandRenamed
1 change: 0 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ library:
- Cabal
- containers
- dhall
- dhall-json
- directory >= 1.3.4.0
- either
- exceptions
Expand Down
120 changes: 2 additions & 118 deletions src/Spago/PscPackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ module Spago.PscPackage where

import Spago.Prelude hiding (set)

import qualified Data.Aeson as JSON
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.Aeson.Encode.Pretty as JSON
import qualified Data.ByteString.Lazy as ByteString.Lazy
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Encoding as LT
import qualified Dhall.JSON as Dhall.JSON
import System.Directory (removePathForcibly)
import qualified Turtle as T

import qualified Spago.PackageSet as PackageSet


data PscPackage = PscPackage
{ name :: Text
Expand All @@ -25,111 +11,9 @@ data PscPackage = PscPackage
}
deriving (Show, Generic)

instance JSON.ToJSON PscPackage
instance JSON.FromJSON PscPackage
instance ToJSON PscPackage
instance FromJSON PscPackage

configPath :: IsString t => t
configPath = "psc-package.json"

pscPackageBasePathText :: Text
pscPackageBasePathText = ".psc-package/local/.set/"

pscPackageBasePath :: T.FilePath
pscPackageBasePath = T.fromText pscPackageBasePathText

packagesJsonText :: Text
packagesJsonText = pscPackageBasePathText <> "packages.json"

packagesJsonPath :: T.FilePath
packagesJsonPath = T.fromText packagesJsonText

pscPackageJson :: T.Text -> T.Text
pscPackageJson packageName = encodePscPackage $ PscPackage packageName "local" "" []

encodePscPackage :: PscPackage -> T.Text
encodePscPackage = LT.toStrict . LT.decodeUtf8 . encodePretty


-- | Given a path to a Dhall file and an output path to a JSON file,
-- reads the Dhall, converts it, and writes it as JSON
dhallToJSON :: Spago m => T.Text -> T.Text -> m ()
dhallToJSON inputPath outputPath = do
let config = JSON.Config
{ JSON.confIndent = JSON.Spaces 2
, JSON.confCompare = compare
, JSON.confNumFormat = JSON.Generic
, JSON.confTrailingNewline = False }

dhall <- readTextFile $ T.fromText inputPath

jsonVal <- liftIO $ Dhall.JSON.codeToValue Dhall.JSON.NoConversion Dhall.JSON.ForbidWithinJSON (Just $ Text.unpack inputPath) dhall

writeTextFile outputPath
$ Text.decodeUtf8
$ ByteString.Lazy.toStrict
$ JSON.encodePretty' config jsonVal


-- | Generates a local `packages.json` from the current `packages.dhall`
insDhall :: Spago m => m ()
insDhall = do
isProject <- testfile PackageSet.packagesPath
unless isProject $
die "Missing packages.dhall file. Run `spago psc-package-local-setup` first."
mktree pscPackageBasePath
T.touch packagesJsonPath

PackageSet.ensureFrozen PackageSet.packagesPath

try (dhallToJSON PackageSet.packagesPath packagesJsonText) >>= \case
Right _ -> do
echo $ "Wrote packages.json to " <> packagesJsonText
echo "Now you can run `psc-package install`."
Left (err :: SomeException) ->
die $ "Failed to insdhall: " <> tshow err


-- | Tries to create the `psc-package.json` file. Existing dependencies are preserved,
-- | unless `--force` has been used.
makePscPackage :: Spago m => Bool -> m ()
makePscPackage force = do
hasPscPackage <- testfile configPath
if hasPscPackage && not force
then do
pscPackage <- readTextFile configPath
case JSON.eitherDecodeStrict $ Text.encodeUtf8 pscPackage of
Left e -> die $ "The existing psc-package.json file is in the wrong format: " <>
Text.pack e
Right p -> do
writeTextFile configPath $
encodePscPackage $ p { set = "local", source = "" }
echo "An existing psc-package.json file was found and upgraded to use local package sets."

else do
T.touch configPath
pwd <- T.pwd
let projectName = case T.toText $ T.filename pwd of
Left _ -> "my-project"
Right n -> n
writeTextFile configPath $ pscPackageJson projectName


-- | Create `packages.dhall` and update `psc-package.json` to use the local set
localSetup :: Spago m => Bool -> m ()
localSetup force = do
PackageSet.makePackageSetFile force
makePscPackage force
echo "Set up local Dhall packages."
echo "Run `spago psc-package-insdhall` to generate the package set."


-- | Delete the .psc-package folder
clean :: Spago m => m ()
clean = do
let pscDir = "./.psc-package"
hasDir <- testdir pscDir
if hasDir
then do
liftIO $ removePathForcibly $ T.encodeString pscDir
echo "Packages cache was cleaned."
else echo "Nothing to clean here."
1 change: 0 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ packages:
- .
extra-deps:
- dhall-1.26.0
- dhall-json-1.4.1
- github-0.22
- async-pool-0.9.0.2@sha256:3aca5861a7b839d02a3f5c52ad6d1ce368631003f68c3d9cb6d711c29e9618db,1599
- binary-instances-1@sha256:cdef50410f2797de38f021d328d38c32b2f4abeaab86bfaf78e0657150863090,2613
Expand Down
7 changes: 0 additions & 7 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ packages:
sha256: cbd35293fc6b2ef77e5d64fca3775b2915aea86ad0c3425e08d21c950fcd06ea
original:
hackage: dhall-1.26.0
- completed:
hackage: dhall-json-1.4.1@sha256:5b0dac356e84d03e855aa4e8aa455532c4c4a274154e26756ae77ebbc82c89a4,5398
pantry-tree:
size: 3387
sha256: 77290c47daa5960e967ff219ce9c44ffd3035e64acd6a1d42268eb366b2c4264
original:
hackage: dhall-json-1.4.1
- completed:
hackage: github-0.22@sha256:13f09e904248a40dd173c08f2859d0dfda178a7c27f88df20b70a0d5a7614757,6909
pantry-tree:
Expand Down
51 changes: 0 additions & 51 deletions test/PscPackageSpec.hs

This file was deleted.

2 changes: 0 additions & 2 deletions test/psc-package-local-test/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions test/psc-package-local-test/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions test/psc-package-local-test/psc-package.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/psc-package-local-test/src/Main.purs

This file was deleted.

0 comments on commit 92ea1e6

Please sign in to comment.