Implement relative path handling for plugin paths#9299
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements relative path handling for bundler plugin paths to fix an issue where changing a username breaks bundler plugins. Previously, plugin paths were stored as absolute paths in the index file, which became invalid when the user's home directory path changed (e.g., from /Users/oldname to /Users/newname).
Changes:
- Plugin paths and load paths are now stored relative to the plugin root directory in the index file
- Paths are automatically converted between relative (for storage) and absolute (for runtime) formats
- Added comprehensive test coverage for the new path handling functionality
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| bundler/lib/bundler/plugin/index.rb | Implements path relativization/absolutization logic with helper methods; updates load_index to convert relative paths to absolute at load time, and save_index to store paths as relative |
| bundler/spec/bundler/plugin/index_spec.rb | Adds test coverage verifying that paths are stored relatively and correctly expanded when the plugin root changes (e.g., after a username change) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def relativize_path(path, base) | ||
| pathname = Pathname.new(path) | ||
| return path unless pathname.absolute? | ||
|
|
||
| base_path = Pathname.new(base) | ||
| if pathname.to_s.start_with?(base_path.to_s + "/") | ||
| pathname.relative_path_from(base_path).to_s | ||
| else | ||
| path | ||
| end | ||
| end |
There was a problem hiding this comment.
The relativize_path method doesn't handle ArgumentError that can be raised by relative_path_from on Windows when paths are on different drives. Other parts of the codebase (e.g., bundler/lib/bundler/shared_helpers.rb:228-233) rescue this exception and return the original path. Consider adding similar error handling here to ensure cross-platform compatibility.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
What was the end-user or developer problem that led to this PR?
Fixes #3340
What is your fix for the problem, implemented in this PR?
Use relative path for plugin directory and expand it to absolute path in bundler internal.
This implementation is a bit of redundant. I'm working to make more smaller code.
Make sure the following tasks are checked