purescriptspago

How do you install a specific package version with Spago?


With tools like npm we can install a specific version

npm install foo@1.2.0 

How do you install a specific version using spago install?


Solution

  • Firstly, that's not what spago install does. Instead of "adding a package to your project", spago install downloads all packages that are currently referenced in your spago.dhall file.

    Secondly, the idea with Spago is that you don't choose a specific package version. Instead what you choose is a "snapshot", which is a collection of certain versions of all available packages that are guaranteed to compile and work together. This is a measure intended to prevent version conflicts and versioning hell (and this is similar to how Haskell stack works)

    The snapshot is defined in your packages.dhall file, and then you specify the specific packages that you want to use in spago.dhall. The version for each package comes from the snapshot.

    But if you really need to install a very specific version of a package, and you really know what you're doing, then you can modify the snapshot itself, which is described in packages.dhall.

    By default your packages.dhall file might look something like this:

    let upstream =
          https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.5-20200103/src/packages.dhall sha256:0a6051982fb4eedb72fbe5ca4282259719b7b9b525a4dda60367f98079132f30
    
    let additions = {=}
    
    let overrides = {=}
    
    in  upstream // additions // overrides
    

    This is the default template that you get after running spago new.

    In order to override the version for a specific package, add it to the overrides map like this:

    let overrides =
      { foo =
          upstream.foo // { version = "v1.2.0" }
      }
    

    And then run spago install. Spago should pull in version 1.2.0 of the foo package for you.