Skip to content

Use oxc_resolver for ppx path resolution #7740

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tsnobip
Copy link
Member

@tsnobip tsnobip commented Jul 30, 2025

An attempt to fix rescript-lang/rewatch#104.

I tried it on my yarn modern monorepo and it did fix PPX resolution.

I couldn't test ppx-flag with a relative path, so don't hesitate to chime in if you have this setup!

@tsnobip tsnobip force-pushed the yarn-modern-monorepo branch 2 times, most recently from 724c2f8 to c55b479 Compare July 30, 2025 12:19
@tsnobip tsnobip force-pushed the yarn-modern-monorepo branch from 96ff029 to 6ec8e86 Compare August 6, 2025 12:27
Copy link

pkg-pr-new bot commented Aug 6, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7740

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7740

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7740

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7740

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7740

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7740

commit: 5ddf39c

@tsnobip tsnobip force-pushed the yarn-modern-monorepo branch from 6ec8e86 to af7843f Compare August 7, 2025 07:22
@zth
Copy link
Collaborator

zth commented Aug 7, 2025

For a layman - will oxc_resolver help with the pnpm issues/inconsistencies as well?

@tsnobip tsnobip force-pushed the yarn-modern-monorepo branch from 91f0307 to 70893a1 Compare August 7, 2025 08:23
@tsnobip
Copy link
Member Author

tsnobip commented Aug 7, 2025

For a layman - will oxc_resolver help with the pnpm issues/inconsistencies as well?

@zth that's the aim of this PR for PPX resolution, but maybe it could be used for module resolution altogether! I haven't looked at it though!

@zth
Copy link
Collaborator

zth commented Aug 7, 2025

Tangentially related, but there seems to be a deno_resolver crate available as well. cc @jderochervlk

@nojaf
Copy link
Member

nojaf commented Aug 7, 2025

maybe it could be used for module resolution altogether!

yeah, that be great. I'm interested in this as well.

Already thinking about the following: once oxc has a formatter crate, we might be able to use that on the JavaScript output (optionally).

@zth
Copy link
Collaborator

zth commented Aug 7, 2025

yeah, that be great. I'm interested in this as well.

Already thinking about the following: once oxc has a formatter crate, we might be able to use that on the JavaScript output (optionally).

This has been up for discussion before, IIRC. I'd personally love that, but if I remember correctly there were some objections. Anyway, worth exploring for sure. That'd let us not need to care that much about formatting when outputting from the compiler.

EDIT: IMO we should lean on something like oxc as much as we need for the JS side, now that we've taken on Rust as a "dependency" for the build system. oxc and the likes are one of the advantages of the Rust ecosystem.

@tsnobip tsnobip force-pushed the yarn-modern-monorepo branch from 70893a1 to 933697c Compare August 7, 2025 08:54
@tsnobip tsnobip force-pushed the yarn-modern-monorepo branch from 933697c to 554be65 Compare August 7, 2025 09:06
@tsnobip tsnobip marked this pull request as ready for review August 8, 2025 07:45
@tsnobip tsnobip requested review from jfrolich and nojaf August 8, 2025 07:45
nojaf
nojaf previously approved these changes Aug 8, 2025
Copy link
Member

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try this and see what users say about it.

"-ppx".to_string(),
oxc_resolver
.resolve(root_path, y)
.unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a novice Rustacean, I believe this leads to a panic when resolution failed.
However unlikely this may be, doing the .expect() will allow us to know that this part failed. So, I'm more in favour of that. Put a good message in there what we could not resolve.

@@ -26,6 +26,7 @@ serde = { version = "1.0.152", features = ["derive"] }
serde_json = { version = "1.0.93" }
sysinfo = "0.29.10"
tempfile = "3.10.1"
oxc_resolver = "11.6.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, there is a 11.6.1 I saw.

package_name: &String,
) -> Vec<String> {
pub fn flatten_ppx_flags(root_path: &Path, flags: &Option<Vec<OneOrMore<String>>>) -> Vec<String> {
let oxc_resolver = Resolver::new(ResolveOptions::default());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea if this is a costly thing to make?
Imagine we have 8 projects in a monorepo that all need to resolve some ppx thing. Does is make sense to recreate the oxc_resolver each time or should we have one instance of this during the lifetime of the application run?

@nojaf nojaf self-requested a review August 8, 2025 13:40
flags: &Option<Vec<OneOrMore<String>>>,
package_name: &String,
) -> Vec<String> {
pub fn flatten_ppx_flags(root_path: &Path, flags: &Option<Vec<OneOrMore<String>>>) -> Vec<String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having some second doubts here.
Is the problem not more related that a ppx flag needs an absolute path?
So, in case of a symlink we need to follow the canonical path instead?

@nojaf nojaf dismissed their stale review August 8, 2025 13:43

No longer sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pnpm monorepo support - ppx resolution failing
3 participants