Skip to content

fix: fix PnP ESM loader integration#255

Merged
JounQin merged 1 commit intoun-ts:mainfrom
clemyan:fix-pnp-esm
Jan 14, 2026
Merged

fix: fix PnP ESM loader integration#255
JounQin merged 1 commit intoun-ts:mainfrom
clemyan:fix-pnp-esm

Conversation

@clemyan
Copy link
Contributor

@clemyan clemyan commented Oct 28, 2025

When running in PnP context, setupTsRunner detects whether the runtime support module.register, and uses module.register in the worker thread to load the PnP loader in the worker thread during runAsWoker. If it is not supported, --loader </path/to/.pnp.loader.mjs> is added to the worker's execArgv.

This is problematic for two reasons:

  1. The worker path is resolved without the PnP loader. So the worker will fail if the worker path is only resolvable under PnP.
  2. The worker thread always fails because there is a chicken-and-egg problem -- the worker thread can't resolve synckit without the PnP loader, but the PnP loader is only loaded in runAsWorker which needs synckit to be resolvable.

This PR makes it so that the execArgv --loader method is always used

Fixes #254

Summary by CodeRabbit

  • Bug Fixes
    • Fixed PnP ESM support handling in synckit

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

🦋 Changeset detected

Latest commit: 3057f9c

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

This PR includes changesets to release 1 package
Name Type
synckit Patch

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

The PR removes conditional MODULE_REGISTER_SUPPORTED checks to ensure PnP ESM loaders are consistently injected across worker initialization and subprocess execution paths, fixing Yarn PnP support in ESLint contexts.

Changes

Cohort / File(s) Change Summary
Changeset entry
.changeset/honest-forks-juggle.md
Documents patch release for synckit with PnP ESM support fix
PnP loader unconditional handling
src/helpers.ts, src/index.ts
Removes MODULE_REGISTER_SUPPORTED conditional guards and ensures PnP loaders are always appended to execArgv and worker initialization paths when present

Sequence Diagram(s)

sequenceDiagram
    participant Worker as Worker Process
    participant Helper as setupTsRunner
    participant execArgv as execArgv
    
    Note over Worker,Helper: Before: Conditional PnP injection
    Worker->>Helper: Check MODULE_REGISTER_SUPPORTED
    alt MODULE_REGISTER_SUPPORTED true
        Helper->>execArgv: Add PnP loader to execArgv
    else MODULE_REGISTER_SUPPORTED false
        Helper->>execArgv: Skip PnP loader
    end
    
    Note over Worker,Helper: After: Unconditional PnP injection
    Worker->>Helper: Initialize
    Helper->>execArgv: Always add PnP loader if present
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Specific areas for attention:
    • Verify that removal of MODULE_REGISTER_SUPPORTED condition doesn't break compatibility on Node versions where the module.register API isn't available
    • Confirm PnP loader injection works correctly for both ESM and CommonJS contexts in the worker initialization path
    • Validate that unconditional loader prepending handles edge cases where pnpLoaderPath may be undefined or null

Possibly related PRs

Poem

🐰 A yarn's knot was tangled tight,
PnP loaders causing quite a plight,
We hopped away the conditions away,
Now loaders load without delay! 🎯

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: fix PnP ESM loader integration" is directly related to the core changes in the pull request. The changeset and code modifications consistently address fixing how PnP ESM loaders are integrated by removing MODULE_REGISTER_SUPPORTED conditional logic and ensuring the loader is always added to worker execArgv. The title is clear, specific, and accurately summarizes the main objective of addressing the PnP ESM loader integration bug reported in issue #254.
Linked Issues Check ✅ Passed The code changes directly address all primary objectives from issue #254. The modifications in src/helpers.ts and src/index.ts remove the MODULE_REGISTER_SUPPORTED conditional logic and eliminate the late module.register call, implementing the stated solution to always use the execArgv --loader method for PnP loaders. This resolves both identified problems: the worker path resolution issue and the chicken-and-egg timing problem where module.register was invoked too late. The changeset entry appropriately documents the PnP ESM support fix for the patch release.
Out of Scope Changes Check ✅ Passed All code changes are directly scoped to addressing the PnP ESM loader integration issue from #254. The modifications to src/helpers.ts and src/index.ts specifically target the removal of MODULE_REGISTER_SUPPORTED conditional logic and the problematic module.register approach, replacing them with unconditional execArgv --loader handling. The changeset file addition is appropriate for documenting the fix. No changes unrelated to the stated PR objectives are present in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@sonarqubecloud
Copy link

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 3057f9c in 1 minute and 2 seconds. Click for details.
  • Reviewed 65 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. .changeset/honest-forks-juggle.md:1
  • Draft comment:
    Changelog entry is clear and concise.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. src/helpers.ts:312
  • Draft comment:
    Unconditionally prepending the --loader flag ensures the PnP loader is loaded early, resolving the chicken‐and‐egg issue (#254).
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, explaining why a change was made. It doesn't provide a suggestion, ask for confirmation, or point out a potential issue.
3. src/index.ts:107
  • Draft comment:
    Removing the module.register call in the worker thread avoids late loader registration, ensuring modules (like synckit) are resolvable under PnP as intended.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, explaining the effect of removing a specific call. It doesn't provide a suggestion, ask for confirmation, or point out a potential issue. It seems to violate the rule against purely informative comments.

Workflow ID: wflow_FB8wS5GLUyaUkBzB

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/helpers.ts (1)

601-601: Consider removing unused pnpLoaderPath from workerData.

The pnpLoaderPath is no longer extracted or used in the worker (see Line 108 in src/index.ts), as the PnP loader is now unconditionally passed via execArgv. Passing unused data to workerData is unnecessary.

Apply this diff to remove the unused field:

-    workerData: { sharedBufferView, workerPort, pnpLoaderPath },
+    workerData: { sharedBufferView, workerPort },

Note: If you make this change, also consider updating the WorkerData interface in src/types.ts to remove the pnpLoaderPath field for consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7604672 and 3057f9c.

📒 Files selected for processing (3)
  • .changeset/honest-forks-juggle.md (1 hunks)
  • src/helpers.ts (1 hunks)
  • src/index.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/index.ts (1)
src/types.ts (1)
  • WorkerData (24-28)
src/helpers.ts (1)
src/constants.ts (1)
  • LOADER_FLAG (104-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
.changeset/honest-forks-juggle.md (1)

1-5: Changeset structure looks good.

The changeset is properly formatted with the correct package name, appropriate patch bump type for a bug fix, and a clear description that aligns with the PR objectives to fix PnP ESM loader integration.

src/helpers.ts (1)

315-315: LGTM! Fixes the PnP ESM loader timing issue.

Unconditionally adding the PnP loader to execArgv ensures the loader is active before the worker attempts to resolve any dependencies, eliminating the chicken-and-egg problem where module.register was called too late.

src/index.ts (1)

108-108: LGTM! Correctly removes unused PnP loader path extraction.

Since the PnP loader is now unconditionally preloaded via execArgv (see src/helpers.ts line 315), the worker no longer needs to extract or register the loader path. This simplifies the worker initialization and aligns with the unified loader approach.

@JounQin
Copy link
Member

JounQin commented Jan 14, 2026

Sorry I never noticed this PR previously.

Since you're the member of yarn berry project, I believe you know better about PnP surely, so LGTM.

Let's see what would happen after merging.

Copy link

Copilot AI left a 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 fixes PnP (Plug'n'Play) ESM loader integration by changing how the PnP loader is registered in worker threads. Previously, the code conditionally used module.register() inside the worker thread or --loader in execArgv, which caused a chicken-and-egg problem where the worker couldn't resolve dependencies without the PnP loader, but the loader was only registered after the worker started. The fix ensures the PnP loader is always added via the --loader execArgv flag.

Changes:

  • Removed conditional module.register() call from worker threads that caused initialization issues
  • Simplified PnP loader setup to always use --loader flag in execArgv
  • Cleaned up unused imports related to module registration

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/index.ts Removed module.register logic and related imports from runAsWorker function
src/helpers.ts Removed MODULE_REGISTER_SUPPORTED conditional, now always adds --loader flag for PnP
.changeset/honest-forks-juggle.md Added changeset documenting the PnP ESM support fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JounQin JounQin merged commit 4fb10bd into un-ts:main Jan 14, 2026
12 checks passed
@JounQin JounQin mentioned this pull request Jan 14, 2026
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.

[Bug?]: Yarn pnp fails with synckit and prettier plugin in eslint context

3 participants