Skip to content

Specifying global build.yaml for all projects in monorepo #3406

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

Closed
pitazzo opened this issue Nov 17, 2022 · 8 comments
Closed

Specifying global build.yaml for all projects in monorepo #3406

pitazzo opened this issue Nov 17, 2022 · 8 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@pitazzo
Copy link

pitazzo commented Nov 17, 2022

  • Dart SDK Version 2.18.2 (stable)
  • build_runner 2.2.0

Hi there,
I wonder whether would be possible specifying a full path to the build.yaml file in the build command of build_runner. I would love to only maintain one global build.yaml file for all the project in our monorepo. Being able to specify a full route in the root of the repo and the usage of a monorepo manager such as melos would made it possible.

@jakemac53
Copy link
Contributor

build.yaml files are also read when building other packages that depend on a given package, so I don't really see this working out well in the long term (the use case would be very narrow, and then it would be very confusing that your package behaves differently if depended on).

I would suggest that possibly melos could handle copying the file into each package from a central location?

@jakemac53 jakemac53 added the closed-not-planned Closed as we don't intend to take action on the reported issue label Sep 1, 2023
@lucavenir
Copy link

lucavenir commented Mar 6, 2025

@davidmorgan, please let me know if I'm being annoying, but since you've asked me to underline more build runner issues, here I go 😄 This is one of the most important to me.

Dart now supports mono repos. I love them.
Alas, in that long list of build_runner issues, I've mentioned how hard it is to setup the builder for mono repos.

I think the builder must be monorepo-aware to solve that. It should be "canon" (aka expected and documentated), and it should account for optimizations in that regard.

Thus, I'm not sure the above reply is relevant anymore. Melos should be considered a thing of the past.

Notice how mono repo support for build runner has been asked a multitude of times in this repository, and - as of now - they're all being closed as "not planned".
This can't be the case anymore, given the macros developments has gone south

@davidmorgan
Copy link
Contributor

Thanks @lucavenir, your input is much appreciated :) let me add this to the pile of things I plan to look at.

I'm not sure I fully understand what's being asked for, though; could you maybe give an example of build.yaml config that you'd want to share across packages in a monorepo?

@rrousselGit
Copy link

I assume one use-case would be Freezed config. It has a bunch of default values configured in the build.yaml: https://github.com/rrousselGit/freezed#changing-the-behavior-for-the-entire-project

So the idea would be to share those configs across all packages within a workspace

@lucavenir
Copy link

lucavenir commented Mar 6, 2025

Surely the configuration can be workspace-wide, as @rroussellGit showed. This is a "nice to have", for me. It means I avoid configuration duplication across the mono repo. Noice.

But the point is build optimizations AFAIK.
Virtually, nothing could be configured at the top level, just like we do in a single package.
Indeed, see the mono repo docs: we're now expected to define a root-level pubspec.yaml, specifying our workspace.
We're also supposed to write, for each package in the workspace, their resolution.

I think the builder might be aware of these to begin with, and skip as much work as it can.

To give you a better perspective: now I have a melos script launching dart run build_runner watch -d for each package in the repo. This allows me to never stop the development cycle. I'm not aware I can currently optimize this without manually triggering rebuilds.

This gives some performance penalties, obviously.

For example, adding a freezed class in packages/api triggers the builder in packages/client that depends on /api, even though nothing changed there.

Output (right after the new class is being saved to disk):

[api]: [INFO] ------------------------------------------------------------------------
[api]: 
[api]: [INFO] Starting Build
[api]: 
[api]: [INFO] Updating asset graph...
[api]: [INFO] Updating asset graph completed, took 0ms
[api]: 
[api]: [INFO] Running build...
[api]: [INFO] Running build completed, took 28ms
[api]: 
[api]: [INFO] Caching finalized dependency graph...
[api]: [INFO] Caching finalized dependency graph completed, took 29ms
[api]: 
[api]: [INFO] Succeeded after 60ms with 3 outputs (5 actions)
[api]: 
[client]: [INFO] ------------------------------------------------------------------------
[client]: 
[client]: [INFO] Starting Build
[client]: 
[client]: [INFO] Updating asset graph...
[client]: [INFO] Updating asset graph completed, took 1ms
[client]: 
[client]: [INFO] Running build...
[client]: [INFO] Running build completed, took 15ms
[client]: 
[client]: [INFO] Caching finalized dependency graph...
[client]: [INFO] Caching finalized dependency graph completed, took 59ms
[client]: 
[client]: [INFO] Succeeded after 79ms with 0 outputs (0 actions)

Here, [client] should not appear.

My request would be to let dart run build_runner watch -d be "runnable" in my monorepo, and I'd see it improved.

@davidmorgan
Copy link
Contributor

Hmm, yes, running for each package separately is doing a lot of duplicate work.

It would be interesting to reduce that somehow.

That's a lot more complicated than just saving copying the yaml files ;) ... but it definitely fits in to the general direction build_runner needs to go if it's going to be tighter integrated with the IDE.

Thanks.

@lucavenir
Copy link

lucavenir commented Mar 6, 2025

I can only imagine the complexity you're going through, so thank you for listening 🙏🏼

Should this stay open?

@davidmorgan
Copy link
Contributor

It's all good, I'm enjoying it ;)

Yes, this is a good issue to have open. Thanks for drawing my attention to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

5 participants