Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Spago #28

Merged
merged 2 commits into from Apr 30, 2019

Conversation

Projects
None yet
4 participants
@thomashoneyman
Copy link
Owner

commented Apr 27, 2019

Bower is getting older and older (and deprecated). Another package manager for PureScript has emerged as a quite useful and usable alternative, called Spago. I've evaluated the tool for Halogen RealWorld before, but ultimately decided against it, with this reasoning. However, the tool has improved over the last six months and I have had some annoyances with Bower while converting this project to Halogen 5, so I wanted to take another look.

Spago serves as a package manager and build tool for PureScript.

As a package manager, Spago allows you to list dependencies and download packages for your project. Instead of downloading dependencies based on their explicitly-provided version, however, Spago uses package sets to decide which version of a package to download.

A package set is a large list of packages that are known to build together. You can download any dependency from the package set and know that you won't have version mismatches. Where in Bower you would write "purescript-halogen": "v4.0.0", in Spago you would write "halogen".

A public package set is kept up-to-date at purescript/package-sets. By default, Spago uses the latest of this package set when initialized, and you can automatically update to the latest package set at any time.

This works well for most dependencies, but sometimes a package is missing from the package set (perhaps it is too new, or not well-known), you need to depend on a version not in the package set (for example, halogen v5.0.0, which is at this time not publicly released), or you need to depend on a fork or a local copy for development purposes. In Spago this is addressed by applying additions or overrides to the package set you depend on. I have no experience with Dhall, the configuration language used for the additions and overrides, and it was still quite easy and simple to do.

See some examples of additions and overrides For example, you can use the existing Halogen package from the package set, but simply override the version number with:
let overrides = { halogen = upstream.halogen // { version = "v5.0.0" }

or override the source repository and set the version to a particular branch with:

let overrides = 
  { remotedata =
      upstream.remotedata //
        { repo = "https://github.com/thomashoneyman/purescript-remotedata.git"
        , version = "update-dependencies"
        }
  }

and you can add a package that does not exist in the package set with:

let additions = 
  { slug =
      mkPackage
        [  "maybe"
        , "strings"
        , "unicode"
        , "generics-rep"
        , "argonaut-codecs"
        ]
        "https://github.com/thomashoneyman/purescript-slug.git"
        "v1.0.0"
  }

Spago is also a build tool. Once you have downloaded your dependencies with spago install you can use spago build to build the project; spago build --watch to watch for local changes, and spago bundle to bundle a single file with dead code elimination you can load in a <script> tag. There's plenty more you can do with Spago to build your project, but those are the main commands relevant to a single-page application like this one; the Spago documentation is quite good.

I enjoyed converting Halogen RealWorld to Spago and it seems like it's becoming the future of PureScript as Bower fades. Of course, before merging, I'm open to discussion as to whether Spago is the correct introduction for PureScript users exploring a teaching repository like this one, or whether Bower would be the safer tool to remain with for now.

@thomashoneyman thomashoneyman self-assigned this Apr 27, 2019

@afcondon

This comment has been minimized.

Copy link

commented Apr 27, 2019

As someone who's hoping to try moving an app from Pux to Halogen sometime this year, and who's already enjoyed using package-sets (non-customized as yet) to remove the bower dependency i'm really , really happy that you've done this and look forward to learning from it.

@kettlebell

This comment has been minimized.

Copy link

commented Apr 27, 2019

I'm in favour of this approach. By the way you've created such a fantastic resource Thomas. Many thanks!

@JordanMartinez

This comment has been minimized.

Copy link

commented Apr 27, 2019

I'm in favor of this as well. I'm starting to work on updating my bottom-up approach to explaining Halogen to v5.0.0. Rather than trying to get the docs merged into the Halogen project, it'll be its own "clone-and-play" repository, similar to my learning repo. It'll be a Spago project as well, so the two should go hand-in-hand.
See https://github.com/JordanMartinez/learn-halogen

@thomashoneyman thomashoneyman changed the base branch from subscription to halogen-5 Apr 30, 2019

@thomashoneyman thomashoneyman changed the base branch from halogen-5 to subscription Apr 30, 2019

@thomashoneyman thomashoneyman merged commit 25fd5c5 into subscription Apr 30, 2019

@thomashoneyman thomashoneyman deleted the spago branch Apr 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.