Skip to content

feat(es/loader): add opt-in Yarn PnP resolver (refs #3247) - #11823

Draft
Mukunda Rao Katta (MukundaKatta) wants to merge 2 commits into
swc-project:mainfrom
MukundaKatta:feat/yarn-pnp-resolver
Draft

feat(es/loader): add opt-in Yarn PnP resolver (refs #3247)#11823
Mukunda Rao Katta (MukundaKatta) wants to merge 2 commits into
swc-project:mainfrom
MukundaKatta:feat/yarn-pnp-resolver

Conversation

@MukundaKatta

Copy link
Copy Markdown

Summary

Refs #3247. Adds an opt-in Yarn Plug'n'Play resolver to swc_ecma_loader. Addresses the maintainer's blocker (running .pnp.cjs JS in a Rust host) by reading the JSON manifest variant .pnp.data.json, which Yarn emits when pnpEnableInlining: false is set.

Files changed

  • crates/swc_ecma_loader/src/resolvers/pnp.rs (new, 539 lines incl. 6 unit tests)
  • crates/swc_ecma_loader/src/resolvers/mod.rs — module gate
  • crates/swc_ecma_loader/Cargo.toml — new opt-in pnp feature; only adds serde_json; tempfile as dev-dep
  • Cargo.lock — auto-updated for tempfile dev-dep

Public API

  • PnpResolver::new(path) and PnpResolver::discover(start_dir)
  • resolve_bare(from, specifier)
  • Full Resolve trait impl

Bare specifiers (incl. scoped) handled. Relative/absolute/node-builtin specifiers pass through (returns Ok(None)) so callers compose with NodeModulesResolver. Manifest cached in Arc.

Scope notes

Resolver intentionally stops at the package directory + subpath and lets the existing node resolver handle main/exports — avoids logic duplication. Maintainers may prefer a fuller package.json["exports"]/zip-fs walk; happy to extend if so.

Test plan

  • cargo fmt -p swc_ecma_loader --check clean
  • cargo clippy -p swc_ecma_loader --features pnp --all-targets -- -D warnings clean
  • cargo test -p swc_ecma_loader --features pnp passes 6/6 (split_specifier, discover hit/miss, resolve_bare hit, relative/builtin pass-through, unknown-module pass-through)
  • Default-feature build/test still green

Adds a `pnp` cargo feature on `swc_ecma_loader` that enables a new
`PnpResolver`. The resolver reads `.pnp.data.json` (the JSON manifest
emitted by Yarn when `pnpEnableInlining: false`) so resolution works
without executing `.pnp.cjs`.

- New module `crates/swc_ecma_loader/src/resolvers/pnp.rs`.
- Feature `pnp` gates the module and only pulls `serde_json`.
- `PnpResolver::discover` walks parent dirs for the manifest.
- Implements the `Resolve` trait for bare specifiers; relative/absolute
  imports and node builtins are passed through so callers can compose
  with `NodeModulesResolver`.
- Unit tests cover specifier splitting, manifest discovery, dependency
  resolution and pass-through cases.

Refs swc-project#3247.
@changeset-bot

changeset-bot Bot commented Apr 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 863aac4

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

CLAassistant commented Apr 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@socket-security

socket-security Bot commented Apr 25, 2026

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm js-beautify is 100.0% likely obfuscated

Confidence: 1.00

Location: Package overview

From: package.jsonnpm/js-beautify@1.14.7

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/js-beautify@1.14.7. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@codspeed-hq

codspeed-hq Bot commented Apr 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks
⏩ 220 skipped benchmarks1


Comparing MukundaKatta:feat/yarn-pnp-resolver (863aac4) with main (3ed7243)

Open in CodSpeed

Footnotes

  1. 220 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Binary Sizes

File Size
swc.linux-x64-gnu.node 27M (27782984 bytes)

Commit: ece9042

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants