Skip to content

Commit

Permalink
Merge branch 'master' into topic/http-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f committed Jul 16, 2019
2 parents 87ef717 + b9db2ca commit 4fb9a19
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ script:
# get newest purescript from github releases
TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
TAG="v0.13.0"
TAG="v0.13.2"
wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/$PURS_OS.tar.gz
tar -xvf $HOME/purescript.tar.gz -C $HOME/
chmod a+x $HOME/purescript
Expand Down
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PureScript package manager and build tool powered by [Dhall][dhall] and
- [Super quick tutorial](#super-quick-tutorial)
- [How do I...](#how-do-i)
- [Switch from `psc-package`](#switch-from-psc-package)
- [Switch from `bower`](#switch-from-bower)
- [See what commands and flags are supported](#see-what-commands-and-flags-are-supported)
- [Download my dependencies locally](#download-my-dependencies-locally)
- [Build and run my project](#build-and-run-my-project)
Expand Down Expand Up @@ -76,7 +77,7 @@ Our main design goals are:
- **Reproducible builds**: thanks to [package sets][package-sets] and [Dhall][dhall], if your
project builds today it will also build tomorrow and every day after that.

Some tools that inspired `spago` are: [Rust's Cargo][cargo], [Haskell's Stack][stack],
Some tools that inspired `spago` are: [Rust's Cargo][cargo], [Haskell's Stack][stack],
[`psc-package`][psc-package], [`pulp`][pulp] and [`purp`][purp].


Expand All @@ -90,7 +91,7 @@ either `bower` or `psc-package`:
- If you use `psc-package`, you have the problem of not having the ability of overriding
packages versions when needed, leading everyone to make their own package-set, which
then goes unmaintained, etc.

Of course you can use the package-set-local-setup to solve this issue, but this is
exactly what we're doing here: integrating all the workflow in a single tool, `spago`,
instead of having to install and use `pulp`, `psc-package`, `purp`, etc.
Expand All @@ -113,10 +114,10 @@ For more details see the [`CONTRIBUTING.md`][contributing]

The recommended installation method for Windows, Linux and macOS is `npm` (see the latest releases on npm
[here][spago-npm]):

```
npm install -g spago
```
```

Other installation methods available:
- Download the binary from the [latest GitHub release][spago-latest-release]
Expand All @@ -129,7 +130,7 @@ Other installation methods available:
- You might have issues with `npm` and Docker (e.g. getting the message "Downloading the spago binary failed.." etc)
You have two options:
- either **do not run npm as root**, because it doesn't work well with binaries. Use it as a nonprivileged user.
- or use `--unsafe-perm`: `npm install -g --unsafe-perm spago`
- or use `--unsafe-perm`: `npm install -g --unsafe-perm spago`

**Notes for Linux users:**
- If you get networking errors (e.g. "Host Not Found") you may need to install `netbase`.
Expand Down Expand Up @@ -165,7 +166,7 @@ This last command will create a bunch of files:
Let's take a look at the two [Dhall][dhall] configuration files that `spago` requires:
- `packages.dhall`: this file is meant to contain the *totality* of the packages
available to your project (that is, any package you might want to import).

In practice it pulls in the [official package-set][package-sets] as a base,
and you are then able to add any package that might not be in the package set,
or override existing ones.
Expand Down Expand Up @@ -223,6 +224,20 @@ You'll note that most of the `psc-package` commands are the same in `spago`, so
your existing build is just a matter of search-and-replace most of the times.


### Switch from `bower`

Switching from `bower` is a bit more involved, because the package list models
are different. Start by running `spago init`. Then prompt spago to install your
current `bower` dependencies by running:

```
spago install $(jq < bower.json ".dependencies | keys | .[] | .[11:]" | tr '\n' ' ' | tr -d '"')
spago install $(jq < bower.json ".devDependencies | keys | .[] | .[11:]" | tr '\n' ' ' | tr -d '"')
```

If spago doesn't find some of them (because they're not on the package set), [add them manually](#add-a-package-to-the-package-set).


### See what commands and flags are supported

For an overview of the available commands, run:
Expand All @@ -249,7 +264,7 @@ $ spago install
```

This will download all the transitive dependencies of your project (i.e. the direct dependencies,
i.e. the ones listed in the `dependencies` key of `spago.dhall`, plus all their dependencies,
i.e. the ones listed in the `dependencies` key of `spago.dhall`, plus all their dependencies,
recursively) to the local `.spago` folder (and the global cache, if possible).

However, running this directly is usually **not necessary**, as all commands that need the dependencies
Expand All @@ -268,7 +283,7 @@ This is just a thin layer above the PureScript compiler command `purs compile`.
The build will produce very many JavaScript files in the `output/` folder. These
are CommonJS modules, and you can just `require()` them e.g. on Node.

It's also possible to include custom source paths when building (`src` and `test`
It's also possible to include custom source paths when building (`src` and `test`
are always included):

```bash
Expand Down Expand Up @@ -905,7 +920,7 @@ Every time `spago` will need to "install dependencies" it will:
to the project-local cache
- download [a metadata file from the `package-sets-metadata`][package-sets-metadata-file] repo
if missing from the global cache or older 24 hours.
This file contains the list of *tags* and *commits* for every package currently in the package
set, updated hourly.
- check if the tag or commit of the package we need to download is in this cached index,
Expand All @@ -915,11 +930,11 @@ Every time `spago` will need to "install dependencies" it will:
from GitHub and copied to both the global and the local cache
- otherwise, the repo is just cloned to the local cache
Note: a question that might come up while reading the above might be "why not just hit GitHub
Note: a question that might come up while reading the above might be "why not just hit GitHub
to check commits and tags for every repo while installing?"
The problem is that GitHub limits token-less API requests to 50 per hour, so any
decently-sized installation will fail to get all the "cacheable" items, making the
decently-sized installation will fail to get all the "cacheable" items, making the
global cache kind of useless. So we are just caching all of that info for everyone here.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ install:
- set PATH=%APPDATA%\npm;%PATH%
- ps: |
$releases = "https://api.github.com/repos/purescript/purescript/releases"
$tag = "v0.13.0"
$tag = "v0.13.2"
$download = "https://github.com/purescript/purescript/releases/download/$tag/win64.tar.gz"
Invoke-WebRequest $download -Out purescript.tar.gz
- tar -xvf purescript.tar.gz
Expand Down
23 changes: 18 additions & 5 deletions src/Spago/GlobalCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import qualified System.Environment
import qualified System.FilePath as FilePath
import qualified Turtle

import qualified Spago.Messages as Messages
import Spago.PackageSet (PackageName (..))


Expand Down Expand Up @@ -151,16 +152,19 @@ getMetadata cacheFlag = do


-- | Directory in which spago will put its global cache
-- | Code from: https://github.com/dhall-lang/dhall-haskell/blob/d8f2787745bb9567a4542973f15e807323de4a1a/dhall/src/Dhall/Import.hs#L578
-- Code from: https://github.com/dhall-lang/dhall-haskell/blob/d8f2787745bb9567a4542973f15e807323de4a1a/dhall/src/Dhall/Import.hs#L578
--
-- In order we try to get:
-- - the folder pointed by `$XDG_CACHE_HOME`
-- - the folder pointed by `$HOME/.cache`
-- - the project-local `.cache`
getGlobalCacheDir :: Spago m => m FilePath.FilePath
getGlobalCacheDir = do
echoDebug "Running `getGlobalCacheDir`"
cacheDir <- alternative₀ <|> alternative₁ <|> err
cacheDir <- alternative₀ <|> alternative₁ <|> alternative₂ <|> alternative₃ <|> err
pure $ cacheDir </> "spago"
where
err = do
echo "Error: was not able to get a directory for the global cache. Set either `HOME` or `XDG_CACHE_HOME`"
empty
err = die Messages.cannotGetGlobalCacheDir

alternative₀ = do
maybeXDGCacheHome <- do
Expand All @@ -177,6 +181,15 @@ getGlobalCacheDir = do
Just homeDirectory -> return (homeDirectory </> ".cache")
Nothing -> empty

alternative₂ = do
maybeWindowsHomeDirectory <- liftIO (System.Environment.lookupEnv "HomePath")

case maybeWindowsHomeDirectory of
Just homeDirectory -> return (homeDirectory </> ".cache")
Nothing -> empty

alternative₃ = pure ".spago-global-cache"


-- | Fetch the tarball at `archiveUrl` and unpack it into `destination`
fetchTarball :: Spago m => FilePath.FilePath -> Text -> m ()
Expand Down
11 changes: 11 additions & 0 deletions src/Spago/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ cannotFindPackagesButItsFine = makeMessage
[ "WARNING: did not find a " <> surroundQuote "packages.dhall" <> " in your current location, skipping compiler version check"
]

cannotGetGlobalCacheDir :: Text
cannotGetGlobalCacheDir = makeMessage
[ "ERROR: Spago was not able to get a directory for the global cache. To fix this there are some things you could do:"
, ""
, "- Set either the `HOME` or `XDG_CACHE_HOME` environment variable. Depending on your OS you'll have to type a different thing in your terminal to do it:"
, " On Windows: set XDG_CACHE_DIR=\"C:\\tmp\\spago\""
, " On Linux/Mac: export XDG_CACHE_HOME='/tmp/spago'"
, ""
, "- Disable the global cache entirely, by passing to Spago `--global-cache skip`"
]

foundExistingProject :: Text -> Text
foundExistingProject pathText = makeMessage
[ "Found a " <> surroundQuote pathText <> " file, skipping copy. Run `spago init --force` if you wish to overwrite it."
Expand Down
11 changes: 5 additions & 6 deletions src/Spago/PackageSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ path :: FilePath
path = pathFromText pathText


-- | Tries to create the `packages.dhall` file. Fails when the file already exists,
-- unless `--force` has been used.
-- | Tries to create the `packages.dhall` file if needed
makePackageSetFile :: Bool -> IO ()
makePackageSetFile force = do
unless force $ do
hasPackagesDhall <- testfile path
when hasPackagesDhall $ echo $ Messages.foundExistingProject pathText
writeTextFile path Templates.packagesDhall
hasPackagesDhall <- testfile path
if force || not hasPackagesDhall
then writeTextFile path Templates.packagesDhall
else echo $ Messages.foundExistingProject pathText
Dhall.format DoFormat pathText


Expand Down
4 changes: 2 additions & 2 deletions templates/packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ let additions =
-}

let mkPackage =
https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.0-20190626/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57
https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.0-20190713/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57

let upstream =
https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.0-20190626/src/packages.dhall sha256:9905f07c9c3bd62fb3205e2108515811a89d55cff24f4341652f61ddacfcf148
https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.0-20190713/src/packages.dhall sha256:906af79ba3aec7f429b107fd8d12e8a29426db8229d228c6f992b58151e2308e

let overrides = {=}

Expand Down
3 changes: 2 additions & 1 deletion test/PscPackageSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ spec = beforeAll clean $ afterAll_ clean $ around_ (withCwd testDir) $ do
spago ["psc-package-insdhall"] >>= shouldBeSuccess
testfile ".psc-package/local/.set/packages.json" >>= (`shouldBe` True)

{-
it "Psc-Package build should work successfully" $ do
procStrictWithErr "psc-package" ["build"] empty >>= shouldBeSuccess

-}

describe "spago psc-package-clean" $ do

Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/bundle-app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/fixtures/bundle-module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fb9a19

Please sign in to comment.