Skip to content

fix(pm): gate Yarn commands on the version yarnPath selects - #3532

Merged
fengmk2 merged 19 commits into
voidzero-dev:mainfrom
jong-kyung:fix/yarn-effective-version
Nov 23, 2026
Merged

fengmk2 merged 19 commits into
voidzero-dev:mainfrom
jong-kyung:fix/yarn-effective-version

Conversation

@jong-kyung

@jong-kyung jong-kyung commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3327

Vite+ used the launcher version from packageManager to decide which Yarn commands, options, and argument forms to use. The launcher hands each command to the release in yarnPath unless ignorePath or YARN_IGNORE_PATH turns that off, so the two versions can differ.

For example, a project pins yarn@2.4.2 in packageManager, and its .yarnrc.yml points yarnPath to a Yarn 3.8.7 release. Yarn 3 supports unlink, but Vite+ checked the Yarn 2 launcher, printed a warning, skipped the command, and exited with code 0. The portal: resolution stayed in package.json.

Approach

  • Before resolving a command for a Yarn launcher that Vite+ downloaded, look for anything that can make it delegate. Classic and Berry follow different settings, so Vite+ checks all of them, as shown in the table below.
  • Detection only looks for yarnPath or yarn-path in the rc files of the current, parent, and home directories, and for YARN_YARN_PATH in any letter case. A false match only costs one yarn --version, so Vite+ does not parse the files.
  • When a setting is found, run yarn --version through the launcher on every command, so Yarn applies its own rules for yarnPath, ignorePath, substitutions, and YARN_IGNORE_PATH. A delegating query took about 200ms in a local test. Caching can be revisited if that causes a noticeable slowdown.
  • Stop with Yarn's output when the query fails, instead of falling back to the launcher version.
  • Skip the check for a Yarn found on PATH, because it already reported its version from the project directory.
Setting Classic launcher Berry launcher
yarnPath in .yarnrc.yml in the current, parent, or home directory Delegates Delegates
yarn-path in .yarnrc Delegates Ignores
YARN_YARN_PATH Ignores Delegates
ignorePath: true Ignores Stops delegation
YARN_IGNORE_PATH=1 Stops delegation Stops delegation

Yarn version resolution after this change

Each package-manager command in a Yarn project follows this path before Vite+ resolves it.

flowchart TD
    A["A package-manager command runs in a Yarn project"] --> B{"Which Yarn runs it?"}
    B -- "Yarn found on PATH" --> C["Vite+ uses the version that Yarn reported from the project.<br/>No extra process starts."]
    B -- "Yarn downloaded by Vite+" --> D{"Can any setting make the launcher delegate?"}
    D -- "No, as in most Yarn 4 and Classic projects" --> E["Vite+ uses the launcher version.<br/>No extra process starts."]
    D -- "Yes, as in most Yarn 2 and 3 projects" --> F["Vite+ runs yarn --version through the launcher."]
    F --> G{"Did the query succeed?"}
    G -- "No" --> H["Vite+ stops with Yarn's output."]
    G -- "Yes" --> I["Vite+ resolves the command with that version."]
Loading

The Yarn launcher from packageManager hands commands to the release in
yarnPath, but command gates, Berry argument branches, and the tips setting
used the launcher version. When the versions differed, Vite+ could skip a
supported command and exit with code 0.

When an rc file or YARN_YARN_PATH can make the launcher delegate, ask it for
its version and cache the answer under a key built from the rc files, the
target release, the Yarn path variables, and the launcher version. Projects
without such a setting start no extra process.
Run real Yarn launchers that delegate through yarnPath, including the Classic
launcher, ignorePath, YARN_IGNORE_PATH, a release replaced in place, and
failed version queries.
@jong-kyung jong-kyung self-assigned this Nov 22, 2026
@jong-kyung jong-kyung added test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: create-e2e Run `vp create` e2e tests test: sfw labels Nov 22, 2026
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T23:58:52.766547Z d7e3de2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0cebd16ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_pm_cli/src/yarn_path.rs Resolved
Comment thread crates/vp_pm_cli/src/yarn_path.rs Resolved
A trailing comment on a yarnPath line became part of the release path, so
the cache key recorded a missing file and kept an old version after the
release was replaced in place. Read quoted values up to their closing quote
and plain values up to a comment.

Yarn Berry matches YARN_* variables without regard to case, so a lowercase
yarn_ignore_path, yarn_yarn_path, or yarn_rc_filename could change the
effective version without changing the key. Match these names without regard
to case for both detection and the cache key.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7615c0c9c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_pm_cli/src/yarn_path.rs Resolved
Yarn Berry lets a later spelling of a YARN_* variable override an earlier
one, so two environments with the same values under different spellings can
select different releases. Hash the original names in environment order
instead of sorted canonical names.
Name the inputs the cache key covers instead of claiming it tracks every
input that can change the effective version, and read quoted rc values
with split_once.
The unlink check also passed for a manifest that was never linked. Assert
that vp link added a portal: resolution before each unlink that must
remove it.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac5af1eaf4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_pm_cli/src/yarn_path.rs Resolved
The line scanner kept growing YAML rules for comments and quotes. Read
.yarnrc.yml with serde_norway, which the workspace already builds through
vt_workspace, and keep a small reader for Classic .yarnrc, which is not
YAML. When an rc file does not parse, ask Yarn so it reports the error.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41a8259bbc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_pm_cli/src/yarn_path.rs Resolved
Yarn accepts some rc files that serde_norway rejects, such as files with
duplicate keys. The cache key then missed the yarnPath release, so a release
replaced in place kept the old cached version. Ask Yarn on every command in
that case instead of reading or writing the cache.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8cd842a29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_pm_cli/src/dispatch.rs Resolved
@jong-kyung
jong-kyung marked this pull request as ready for review November 22, 2026 08:59

@liangmiQwQ liangmiQwQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks good to me overall. However, I'm not sure if the cache mechanism brings too much complexity and edge cases. I also ran Codex reviews in my app locally and found several more edge cases.

For me, I'd lean toward calling yarn --version directly when we detect a possible override, since there are also similar pnpm --version, bun --version calls when they are on PATH. If we still found it costly in practice, we might better to introduce something like a shared helper for that --version check?

(Need @fengmk2's idea 🙇)

@jong-kyung

Copy link
Copy Markdown
Collaborator Author

Thanks, that makes sense to me. I added the cache to avoid an extra yarn --version, which took about 200ms in my local test, on every command in Yarn 2 and 3 projects that use yarnPath. But most of the edge cases came from the cache key, so calling yarn --version directly seems like the better trade-off, and it matches how we handle pnpm and bun. I'll wait for @fengmk2's input and then update the PR.

fengmk2 commented Nov 22, 2026

Copy link
Copy Markdown
Member

I agree with removing the cache. Let’s call yarn --version only when we detect a possible override. We can revisit caching if the extra lookup causes a noticeable slowdown in practice.

@jong-kyung
jong-kyung marked this pull request as draft November 22, 2026 14:48
The cache key had to follow Yarn's rc parsing, substitutions, and release
files, and each mismatch could return a stale version. Ask the launcher
with yarn --version whenever a setting may make it delegate, and drop the
cache and the YAML parser.

Detection now only looks for yarnPath or yarn-path in the rc files and for
YARN_YARN_PATH, so a form that Vite+ cannot parse still leads to a query.
These steps replaced a release in place to check cache invalidation, which
no longer exists.
Move the managed Yarn check out of dispatch, update the manager version only
when Yarn may delegate, and replace the NODE_OPTIONS comment with a test that
fails when the version query keeps user preloads.
Drop the patch-commit step that repeats the ignorePath unlink check, read
package.json through one helper, and reject unknown verify modes.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: aefd686d15

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jong-kyung
jong-kyung marked this pull request as ready for review November 22, 2026 23:51
typos flagged the `caf` prefix of the previous byte string. The test only
needs a byte that is not valid UTF-8.
Non-UTF-8 rc files are uncommon. Keep the substitution case on the same line.
@fengmk2
fengmk2 merged commit 13c3d4b into voidzero-dev:main Nov 23, 2026
150 checks passed
@jong-kyung
jong-kyung deleted the fix/yarn-effective-version branch November 23, 2026 09:30
@fengmk2 fengmk2 mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: sfw

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Yarn command gates use the launcher version instead of the version selected by yarnPath

3 participants