Skip to content
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

feat(core): add yarn pnp support #7639

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

feat(core): add yarn pnp support #7639

wants to merge 4 commits into from

Conversation

hardfist
Copy link
Contributor

@hardfist hardfist commented Aug 21, 2024

Summary

Don't merge this before Rspack 1.0.0
support yarn pnp feature, closes #2236

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Aug 21, 2024
Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 29c1487
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/66c5a6a208822c0008f1433e

@hardfist hardfist changed the title chore: add test case feat(core): add yarn pnp support Aug 21, 2024
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Aug 21, 2024
@hardfist
Copy link
Contributor Author

!bench

@rspack-bot
Copy link

⏳ Triggered benchmark: Open

@hardfist hardfist requested review from h-a-n-a and SyMind August 21, 2024 07:19
@@ -9822,10 +9822,12 @@ type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>;

// @public (undocumented)
class ResolverFactory {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@h-a-n-a is this real public api? how users can access this api?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not according to the generated api.md

) -> napi::Result<JsResolver> {
let pnp_manifest_path = find_closest_pnp_manifest_path(context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This API seems to have a recursive I/O operation. Is it possible to make it opt-in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then we may need feature flag in rspack like

module.exports = {
   pnp: true | false
}
``

Copy link
Contributor Author

@hardfist hardfist Aug 21, 2024

Choose a reason for hiding this comment

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

actually this can be passed from js side by require('module').findPnpApi and enhanced-resolve call it for every resolve call(which is time consuming, https://github.com/webpack/enhanced-resolve/blob/247edebc909040ff99200108f7165e57f4fac2b1/lib/ResolverFactory.js#L138),but with better support for monorepo(like multi .pnp.cjs support, @arcanis not sure whether multi .pnp.cjs is legit usage of yarn)
I think we can support bultin resolve plugin so uers don't use pnp don't pay the cost of pnpapi call

const rspack = require('@rspack/core');
module.exports = {
   // enable pnp functionality by builtin plugin
    plugins: [new rspack.pnpRspackPlugin()]
}

Copy link

Choose a reason for hiding this comment

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

Note that we could make the implementation smarter, and only check directories that haven't been checked before, assuming we keep a cache of some sort (a HashMap<Path, Option<Path>> would be enough); this would trim most of the recursion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you think the cache logic should be implemented in find_closest_pnp_manifest_path or outside

@@ -136,7 +136,7 @@ export class JsResolver {

export class JsResolverFactory {
constructor()
get(type: string, options?: RawResolveOptionsWithDependencyType): JsResolver
get(type: string, options?: RawResolveOptionsWithDependencyType,pnpManifestPath: string|undefined): JsResolver
Copy link

Choose a reason for hiding this comment

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

Do you plan to move the pnpManifestPath into the option bag (here and in the other places where the manifest path is passed as free function)? Ideally the PnP-specific references should be kept to a minimum imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, don't want to change resolveOption api signature, I'm not sure whether it's worthy to support manifest per request or manifest per project. if we need to support manifest per project, we need to pass it to resolveOptions at least in rust side.

Comment on lines +38 to +40
let pnp_manifest = pnp_manifest_path
.and_then(|x| load_pnp_manifest(x).ok())
.map(Arc::new);
Copy link

Choose a reason for hiding this comment

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

nit: Perhaps this function should return a Result, or panic if the PnP file exists but can't be loaded (since presumably it'd cause all resolutions to fail with cryptic "module not found" errors)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for tip, yes, it need some api change

) -> napi::Result<JsResolver> {
let pnp_manifest_path = find_closest_pnp_manifest_path(context);
Copy link

Choose a reason for hiding this comment

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

Note that we could make the implementation smarter, and only check directories that haven't been checked before, assuming we keep a cache of some sort (a HashMap<Path, Option<Path>> would be enough); this would trim most of the recursion.

Copy link

stale bot commented Oct 21, 2024

This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump").

@stale stale bot added the stale label Oct 21, 2024
@arcanis
Copy link

arcanis commented Oct 21, 2024

Bump, I still have it in my backlog (I've been in on-and-off paternity leave since August, so my bandwidth has been limited - but I'm still very interested to bring it to the finish line).

@stale stale bot removed the stale label Oct 21, 2024
@hardfist
Copy link
Contributor Author

Bump, I still have it in my backlog (I've been in on-and-off paternity leave since August, so my bandwidth has been limited - but I'm still very interested to bring it to the finish line).

thank you, we'll continue investigating yarn pnp support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Yarn PnP workspace
4 participants