-
Notifications
You must be signed in to change notification settings - Fork 203
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
Enhance the expressiveness of buildExtensions
with allowing directory moves
#1689
Comments
I would like this, and if I ever have child I will name them "Dart" after you guys if you can make it happen...... |
@bagintz - can you describe your use case? |
It is simply to keep all the generated files in a single, separate folder to keep my models "clean" and easier to read. It is not a show stopper, but a matter of convenience. |
Thanks for the info. Note that if we are able to deliver the feature as described in this specific issue it would be a configuration made by the builder author and not a setting for the end user. A configuration to allow you to choose to do this with builders you didn't write would require #683 as well. There was a similar request made and a longer discussion at google/json_serializable.dart#306 |
Alright, I was thinking about this some recently, and I have a very rough idea that I think would probably be expressive enough to be pretty general, while not being to complex or difficult to implement. Essentially, the idea is to allow capture groups inside the input extensions, which can be filled in arbitrarily into the output extensions. I haven't thought much about the syntax, but lets say for example you mark a capture group with
So, given one of the initial examples, to output to builders:
my_builder:
build_extensions:
docs/{{0}}.dart:
- web/docs/{{0}}.md I believe these could directly translate to a regex, so the above for instance would translate to this regex This essentially begs two fairly obvious questions (and more I'm sure):
In terms of speed I think we will just have to measure. It should only really affect initial asset graph build time so that shouldn't be difficult. For builder ordering I am thinking we could just use the last token as the extension, and treat that the same way as normal input/output extensions today. So in the above example it would run after any generator that produces |
I really like the idea of having a capture group in the extensions config. It buys a lot of expressiveness for not too much conceptual complexity and I think we can smoothly upgrade to that without impacting existing config. I don't think we can use regexes for this, they don't exist in starlark as far as I know and I'd still like for this to be compatible with bazel. If we limit it to one capture group then we can implement it with a prefix/suffix match easily enough. I think we could use Some questions:
Also a minor nit:
That's not the way it works today, your input extensions don't impact ordering, only |
Yes, I think its critical to support this to support entire directory moves (you can't know the full structure as a builder, and only supporting top level dirs would be unfortunate).
Maybe we should allow the user to choose, possibly by following regex syntax (preceding |
Oh, I totally thought we did that... 🤔. |
Any update on this? Spreading generated code throughout the main project is not maintainable and looks messy. |
There is no update yet and we don't have any planned work to address this. As a reminder, this particular issue impacts capability as a builder author. If you are hoping for the ability as a user to be able to shift around generated code that will not be feasible even if we add the feature requested in this issue. |
Hi there. I'm the author of https://github.com/gql-dart/ferry, and this feature would add a lot of value for our users. We currently generate several files per user-generated As a workaround, we've been recommending that users define their
However, if a user wants to edit the Ideally, we'd keep the Widget and the |
@smkhalsa would the "capture groups" proposal I had above support what you want to do? What would your ideal file layout be? |
@jakemac53 yes, I believe so. Here's an example of one of our builder's build_extensions:
Which results in the following directory structure:
So by modifying our build_extensions like so...
...and pulling our
|
That mostly sounds good, I did have a restriction in place originally that you couldn't start with a capture group, although to be completely honest I can't remember why 😆 . It does seem necessary for what you would want to do, which also seems like a common thing to want to solve with this. I think this basically boils down to the 2nd question that @natebosch had originally. |
For us it would have to match nested directory structures, not just the root, since our objective is to colocate graphql operations (and their generated data classes) next to widgets. |
@jakemac53 anything I can do to push this forward? |
@smkhalsa I think we have some general agreement here on at least a path forward. I think what needs to happen next is somebody working up a prototype that we could play with. I am not sure when myself or other owners here would have the time to do that. We do generally accept contributions, but this would be a fairly large feature with a lot of risk in terms of it never landing, and needing thorough testing. So it wouldn't be for the faint of heart haha. |
It seems like this issue keeps coming up not only for users of the build package itself (#1689, #2732, #3126, #1132), but also for users of many downstream packages. For example: Any chance this could get added to the roadmap for an upcoming release? |
I started playing around with this, but I wasn't sure if I got the semantics right. Maybe someone can help clarify if this is the behavior we want, I can then start working on a draft PR to evaluate. The way I see it is that we essentially split build inputs into an (optional) directory matcher and a file extension matcher, right? So Also, should Do we want to allow a directory part in the build outputs if no directory matcher is present in the build input? E.g, is Do we want to allow a directory part in the build input if none is used in the build output? Could a builder specify |
I wouldn't think of it as a directory/extension matcher really. You could for instance have extensions like: Basically, we retain the principle that the entire build extension key is still a suffix match, we just allow some wildcard capture groups within it. As discussed above we probably do want to consider adding a special identifier (maybe
Those should work the same as normal extensions today, so
This should output
I don't quite understand this one, maybe you were just missing the capture groups. So for instance I do think
The equivalent of this would be
This goes to the explanation of the last one, if you don't use them in the output extensions you will end up with conflicting files. I don't know of any valid use case for it. |
Support capture groups for build extensions. Closes #1689.
This is now released with package:build version Note that if you use Big thanks to @simolus3 for the implementation! 🥳 🚀 |
Btw the docs for the new feature are here https://github.com/dart-lang/build/blob/master/docs/writing_a_builder.md#capture-groups |
Build extensions covers a large set of use cases and has a simple implementation, but doesn't cover more complex situations.
We should consider selectively expanding what we can express with specific use cases that are likely to happen. One that has come up a couple times is the idea of parallel directory structure. For instance writing outputs to
/web/docs
when the inputs are in/docs
- but keeping the remaining paths identical.When we originally proposed the build extension scheme we did suggest the configuration language could be expanded - our criteria was just that it was static configuration over a snippet of code.
Pros:
generate_for
/sources
interaction noted below). May make some builds easier to understand if they are today working around this with hacks.Cons:
Builder
to hold this information.generate_for
and a target'ssources
is already hard to understand - this would make it even harder.I think if we can find a few use cases that would be solved by something simple here we should consider it.
The text was updated successfully, but these errors were encountered: