Skip to content

Compiling packages in a monorepo #377

@joneshf

Description

@joneshf

Concern

Compiling everything in a monorepo is too slow for large monorepos. Compiling individual packages requires recompilation work.

Context

Let's say I've got a monorepo setup similar to what's in the README:

$ tree -I 'node_modules|output|package.json|yarn.lock'
.
├── app1
│   ├── spago.dhall
│   └── src
│       └── Main.purs
├── lib1
│   ├── spago.dhall
│   └── src
│       └── Lib1.purs
├── lib2
│   ├── spago.dhall
│   └── src
│       └── Lib2.purs
└── packages.dhall

6 directories, 7 files

As the project grows, compiling everything from the top becomes slower and slower. If I wanted to iterate quickly within the lib1 package, I can move to that directory and run the build:

$ cd lib1
$ spago build --watch

This puts the output directory in lib1 and compiles everything there.

If I then wanted to iterate in lib2, I could move to that directory and run the build:

$ cd ../lib2
$ spago build --watch

Unfortunately, because the output directory is in lib1, I've got to recompile everything into lib2/output.

Workaround

This can be mitigated by running

$ spago build --watch -- --output ../output

in both lib1 and lib2. They compile to a top-level output directory, and compilation results can be shared between them. If I then move to app1 or app1/test and do similar, they also get the benefits of the pre-compiled results.

Questions

  • Is this the best way to address the concern, currently? If not, what's a better way?
  • Could spago make this easier somehow?
    One thing that's been in the back of my head is allowing build to know which package to build:
    $ spago build lib1
    spago could do the bookkeeping of the output directory.
    I'm open to other ideas as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions