-
Notifications
You must be signed in to change notification settings - Fork 113
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
Make packwerk work with in-repo engines using load_path aliases #206
Comments
I'm all to solve this problem, but not to add new configurations. Maybe we should always deal with absolute, normalize paths? Any reason why you want to use the symlink and not the absolute, non-symlinked path? |
@rafaelfranca thanks for the reply.
Since the non symlinked versions live outside of the application directory, I thought that would be an easier path to go. I figured it would be pretty hard for packwerk to discover and resolve paths to code files that were not "below" |
Yeah, looking further into this approach, it seems like it would be pretty difficult to make the rest of packwerk play nice with paths that aren't below If we want to do this without new config options, I wonder if we can modify |
Alright, so I might have a path forward. Here's the basic approach I'm considering
How does this approach sound? |
I don't think we can assume packages will be inside Packages can be anywhere. It probably will require a lot of changes, but I feel like it would be better to always be dealing with absolute (real) paths instead of relative paths, and by doing that the problem you are describing would not exist. |
Let me see if I can understand the right way to frame this problem. What I think I'm hearing is this
Does that sound right? |
Yes. I think they key here are the changes to |
We have the same setup, monorepo, with multiple engines. We do have a number of symlinks that allow these engines to share stuff, like the fixtures directory. Would love to see support for this setup added, as it would make adopting packwerk much simpler. |
@rafaelfranca Cool, this is a concrete enough start for me to dig into it. I'm out for the next two weeks, so if there's anyone else invested enough in this problem to get started, feel free, but I'll pick it up when I come back if not. |
Picking this back up now, and I might have a different approach after discussing some things with a few team members. Rather than trying to solve the problems related to symlinks, I'm actually considering an approach which instead makes packwerk scan for packages outside of the root directory. The idea would be to use something like This means that a If we want to check that inside the engine we're respecting or package boundaries, we'll have to execute a another What do folks think about this new approach? @pboling I'm not sure if this would work for your setup or not |
I'm having a little trouble understanding the problem and wondering if you're available sometime (maybe next week) to jump on a quick zoom so I can understand the layout of your application and the behavior you're hoping for. Also free today 3:45 EST. If you don't have time, I can read this through again a bit more closely and try to ask some clarifying questions. |
@alexevanczuk Sure I can do 3:45 today. Feel free to shoot me an email with an invite at the address on my profile, or DM me in the rubymod slack |
I've gone ahead and opened a PR (#216) with this approach. It's passing all tests, but I still need to run a test against our repo. @alexevanczuk Helped and ran it against an existing repo using a traditional structure, and we know it doesn't create in regressions there. |
Description
This is similar to #47 , but there are some distinctions because we're discussing engines, which are autoloaded, vs gems that are not.
The context is that we have a mono-repo setup like this
root_dir
|- engine_1
|- engine_2
|- app_1
|- app_2
where multiple apps will use the same engines. Each engine is symlinked under an apps vendor directory like
root_dir/app_1/vendor/gems/engine_1 ->
root_dir/engine_1`We attempted to setup packwerk for a given app with a
root_dir/app_1/packwerk.yml
, with a root package atroot_dir/app_1/package.yml
and a package inside an engine likeroot_dir/engine_1/app/models/users/package.yml
.We found that we could properly setup the
packwerk.yml
include
andpackage_paths
to follow the symlinks inside ofvendor
and scan all the files both in the app folder, and in the engine folders, but it would never flag any violations.In digging in, we found the problem was with the constant resolution workflow. Although the autoload paths for the engines were available in
Rails.autoloaders
, the path found there wasroot_dir/engine_1/**
instead ofroot_dir/app_1/vendor/gems/engine_1
. As a result it was being filtered out of the paths provided to theConstantResolver
byApplicationLoadPaths.filter_relevant_paths
We experimented with monkey patching
filter_relevant_paths
to transform the path names for all these in-repo engines to use the full symlink path. When we did that, everything worked as expected.I wanted to propose the idea that we upstream our patch by adding a new key to the
packwerk.yml
configuration file named something likeload_path_aliases
. This would take a hash where the keys would be theload_path
as discovered inRails.autoloaders
and the value would be an alias that the path should be transformed to. Then we'd modifyApplicationLoadPaths
to go through these aliases, and transform all the paths before passing them intoConstantResolver
Does this seem like a reasonable approach? If folks are open to it, I can put together a PR
To Reproduce
Setup a mono repo as described above. If folks would like a clearer example, I can setup a sample application.
Expected Behaviour
Under this proposal, a developer could a define a
packwerk.yml
with this newload_path_aliases
something like thisThen any paths that started with
../engine_1/
would be replaced with an equivalent starting withvendor/gems/engine_1
Version Information
The text was updated successfully, but these errors were encountered: