-
Notifications
You must be signed in to change notification settings - Fork 471
Reuse package resolution for ppx #7776
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
base: master
Are you sure you want to change the base?
Conversation
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this covered by the testrepo |
No, yarn installed sury at the root level. And you can't force it to install at the package level. You really need resolution problem before that can happen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors and reuses package resolution logic for ppx (preprocessor extension) handling in monorepos. Previously, dependency resolution and ppx resolution used different logic, which caused issues when packages existed at different node_modules levels in a workspace.
- Extracted common package resolution logic into a reusable
try_package_path
function - Updated ppx flag processing to use the same resolution strategy as regular dependencies
- Changed error handling from strings to proper
anyhow::Result
types throughout the parsing pipeline
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
rewatch/src/helpers.rs | Added try_package_path function that implements multi-level package resolution logic |
rewatch/src/config.rs | Updated flatten_ppx_flags to use new resolution logic and proper error handling |
rewatch/src/build/parse.rs | Changed function signatures to return anyhow::Result and updated error handling |
rewatch/src/build/packages.rs | Replaced inline resolution logic with call to new try_package_path function |
rewatch/src/build.rs | Updated to handle new error-returning signature |
CHANGELOG.md | Added entry documenting the ppx resolution fix |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
let path = helpers::try_package_path( | ||
package_config, | ||
project_context, | ||
format!("{}{}{}", &package_config.name, MAIN_SEPARATOR, y).as_str(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string formatting with MAIN_SEPARATOR could be simplified using Path::join() which handles path separators correctly across platforms.
format!("{}{}{}", &package_config.name, MAIN_SEPARATOR, y).as_str(), | |
Path::new(&package_config.name).join(y).to_str().unwrap(), |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this really, making a Path and calling unwrap later seems worse.
Some('.') => helpers::try_package_path( | ||
package_config, | ||
project_context, | ||
format!("{}{}{}", package_config.name, MAIN_SEPARATOR, &ys[0]).as_str(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous occurrence, using Path::join() would be more idiomatic and handle cross-platform path separators automatically.
format!("{}{}{}", package_config.name, MAIN_SEPARATOR, &ys[0]).as_str(), | |
Path::new(&package_config.name).join(&ys[0]).to_string_lossy().as_ref(), |
Copilot uses AI. Check for mistakes.
Ok I think it did at some point and that's why the test used to fail, but well, yarn works in mysterious ways haha. Let's merge this, I think this is the last preventing me from using rewatch everywhere without workarounds. |
This is another attempt to solve ppx resolution in monorepos.
The gist is that some workspaces can have
node_modules
on the root and the package level.We take this into account for finding dependencies but didn't for ppx.
In this PR, I've refactored the same resolution code and reused it when looking for ppx.
I didn't add a test as it is very difficult to reproduce this in a yarn workspace.
It is my understanding that yarn will only show this behaviour when it fails to resolve a single version for the entire workspace.
@tsnobip could you give this one a go?