Skip to content

Conversation

@danieljharvey
Copy link
Contributor

@danieljharvey danieljharvey commented Sep 22, 2019

Description of the change

As per issue #377 building in a Monorepo ends creating a lot of duplication. This change adds a build flag --sharedOutput which will ask purs to output into the "root" folder (hopefully where the main packages.dhall lives, but basically the highest up source file in the tree that Dhall tells us about).

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README
  • Added a test for the contribution (if applicable)

P.S.: the above checks are not compulsory to get a change merged, so you may skip them. However, taking care of them will result in less work for the maintainers and will be much appreciated 😊

(length (System.FilePath.splitSearchPath path))
(length <$> current)
then Just path
else current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! However I wonder how brittle it is in the end.
Just for inspiration I went looking what Dhall itself actually does with the graph we use here, and turns out it's being used to print dot graphs.

Here's the implementation, and here's a result for our monorepo:
deps

So it looks like we have all the info available to find out which one is the "rootmost" import for all the cases (while here we'd get it wrong if the "main packages.dhall is not the highest in the file hierarchy). So looking at the graph (which we can build because we get all the parent-child relationships in the graph) a better heuristic than the one I proposed before seems to be "pick the topmost packages.dhall which is not a remote import, an import as Location, or as Text"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh right - sounds like we have everything we need to do this nicely. Will give this a smash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this implementation work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have liked something more like "is this file importing this other one" rather than "is this directory shorter", but let's go with this for now

@danieljharvey
Copy link
Contributor Author

danieljharvey commented Sep 26, 2019

Hello! I think everything above should be resolved now - added another test to be sure that including a module from higher up in the tree than packages.dhall wouldn't trick it and it seems to be OK. (edit: terrible grammar)

@danieljharvey danieljharvey changed the title Add --sharedOutput flag to Spago build command Add output folder sharing and --no-share-output flag to Spago build command Oct 1, 2019
@danieljharvey
Copy link
Contributor Author

Actually - looks like this goes wrong when running tests - it builds everything then the run.js file in .spago points at the wrong output folder. Will investigate.

@f-f
Copy link
Member

f-f commented Oct 1, 2019

@danieljharvey
Copy link
Contributor Author

danieljharvey commented Oct 2, 2019

Yeah - looks like it - going to make a more generic “getOutputPath” function to use here - how do you feel about a spago output-path command that can also be used by purs-loader etc?

@f-f
Copy link
Member

f-f commented Oct 2, 2019

@danieljharvey yeah getOutputPath sounds great. I also agree we should have a command to get the output path, though I'd say that should go in another issue/PR, so we can merge this one ASAP!

Copy link
Contributor

@jhrcek jhrcek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about this feature, but left some suggestions inline anyway :-)

@danieljharvey
Copy link
Contributor Author

Hey @f-f - this is working for me now, and have addressed changes from above.

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danieljharvey looks great, thanks for doing this! 💯

(length (System.FilePath.splitSearchPath path))
(length <$> current)
then Just path
else current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have liked something more like "is this file importing this other one" rather than "is this directory shorter", but let's go with this for now

@f-f f-f changed the title Add output folder sharing and --no-share-output flag to Spago build command Add output folder sharing and --no-share-output flag to build Oct 3, 2019
@f-f f-f merged commit 52ddd50 into purescript:master Oct 3, 2019
f-f added a commit that referenced this pull request Dec 18, 2019
This PR disables output sharing that was introduced in #422. 

The reasoning for this is twofold:
1. this change seems to break `psc-ide` and various other tooling
2. Spago messing with people's `output` folder doesn't really feel right, because e.g. it forces people to depend on wherever Spago decides the output folder to be in their project

We could of course just invert the logic of the flag and make it opt-in instead, but I just don't think we should encourage point (2) above.

The "proper" way to do this IMHO is that Spago could do some kind of "build artifact caching": i.e. sharing compiled JS between projects compiled with the same set of packages and compiler. This is a strictly better solution, because:
- it doesn't mess with people's output folder
- it enables artifact sharing even between different projects and not just in the same monorepo
@f-f f-f mentioned this pull request Dec 18, 2019
f-f added a commit that referenced this pull request Dec 19, 2019
This commit disables output sharing that was introduced in #422. 

The reasoning for this is twofold:
1. this change seems to break `psc-ide` and various other tooling
2. Spago messing with people's `output` folder doesn't really feel right,
  because e.g. it forces people to depend on wherever Spago decides the
  output folder to be in their project

We could of course just invert the logic of the flag and make it opt-in
instead, but I just don't think we should encourage point (2) above.

The "proper" way to do this IMHO is that Spago could do some kind of
"build artifact caching": i.e. sharing compiled JS between projects
compiled with the same set of packages and compiler.
This is a strictly better solution, because:
- it doesn't mess with people's output folder
- it enables artifact sharing even between different projects and not
  just in the same monorepo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants