Skip to content

fix(migrate): dedupe vite/vitest under pnpm by adding a direct vite dep#1933

Merged
fengmk2 merged 12 commits into
mainfrom
fix/1932-pnpm-vite-dedupe
Jun 25, 2026
Merged

fix(migrate): dedupe vite/vitest under pnpm by adding a direct vite dep#1933
fengmk2 merged 12 commits into
mainfrom
fix/1932-pnpm-vite-dedupe

Conversation

@fengmk2

@fengmk2 fengmk2 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Closes #1932.

Under pnpm, a created/migrated monorepo resolved vite-plus / vite / vitest to 2 instances each: packages depending on vite-plus without a direct vite (the workspace root and packages/utils) left vitest's vite peer for pnpm's autoInstallPeers to satisfy with a second, upstream vite. That upstream vite lacks vite's vite-task-client integration, which broke the vp test cache.

Fix (pnpm-only, in the migrator): wherever vite-plus is depended upon, add a direct vite devDep aliased to the override target so vitest's peer binds to @voidzero-dev/vite-plus-core. npm/yarn/bun already redirect the transitive/peer vite via root overrides/resolutions, so they are untouched.

Also adds a "Verify single dependency instances" CI guard, drops the temporary PNPM_CONFIG_MINIMUM_RELEASE_AGE=0 band-aid from #1774, and covers the cases with unit tests.

@fengmk2 fengmk2 self-assigned this Jun 24, 2026
@netlify

netlify Bot commented Jun 24, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview ready!

Name Link
🔨 Latest commit 9a6ed05
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a3c8fe3a3d7b900087bcbc2
😎 Deploy Preview https://deploy-preview-1933--viteplus-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@fengmk2 fengmk2 changed the title test(ci): reproduce pnpm duplicate vite/vitest instances (#1932) fix(migrate): dedupe vite/vitest under pnpm by adding a direct vite dep (#1932) Jun 24, 2026
@fengmk2 fengmk2 requested review from Brooooooklyn and wan9chi June 24, 2026 12:05
@fengmk2 fengmk2 marked this pull request as ready for review June 24, 2026 12:05
@fengmk2 fengmk2 force-pushed the fix/1932-pnpm-vite-dedupe branch from 121b36a to 4de2889 Compare June 24, 2026 13:29
@fengmk2

fengmk2 commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@fengmk2 fengmk2 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 Jun 24, 2026

@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: 4de2889644

ℹ️ 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 .github/workflows/test-vp-create.yml Outdated
@fengmk2 fengmk2 changed the title fix(migrate): dedupe vite/vitest under pnpm by adding a direct vite dep (#1932) fix(migrate): dedupe vite/vitest under pnpm by adding a direct vite dep Jun 24, 2026
fengmk2 added 11 commits June 25, 2026 00:55
Under pnpm, `vp create vite:monorepo` resolves vite-plus / vite / vitest
to 2 instances each (the workspace root and packages/utils auto-install
an upstream vite to satisfy vitest's peer, since they have no direct vite
for the override to bind). This step asserts a single instance via
`vp why` and is expected to fail for the monorepo + pnpm matrix entry,
reproducing the bug before the fix.

Refs #1932
Print the complete `vp why <pkg>` output (not just the summary lines) for
any package that resolves to multiple instances, so the reproduction job
shows the full dependency tree that explains the split.

Refs #1932
Under pnpm, any importer that depends on vite-plus (which bundles vitest)
needs a direct `vite` dep so the `vite` override binds vitest's required
`vite` peer to @voidzero-dev/vite-plus-core. Without a direct edge, pnpm's
autoInstallPeers installs a separate upstream vite to satisfy the peer,
splitting vite-plus / vite / vitest into duplicate instances (the extra
vite also lacks vite's vite-task-client integration, breaking the vp test
cache).

Mirror the override as a direct vite devDep in the workspace root
(rewriteRootWorkspacePackageJson) and every package (rewritePackageJson),
pnpm-only. npm/yarn/bun redirect the transitive/peer vite via root
overrides/resolutions, so they are untouched.

Closes #1932
The direct-`vite` dedupe fix makes the bundled vitest resolve `vite` to
@voidzero-dev/vite-plus-core (which carries the vite-task-client
integration) regardless of which upstream version the age gate would pick,
so the PNPM_CONFIG_MINIMUM_RELEASE_AGE=0 workaround is no longer needed.
The "Verify single dependency instances" step is now a passing regression
guard rather than a known-failing reproduction.

Refs #1932
Apply oxfmt to the new migrator blocks, hoist the test pkg literal out of
a factory to satisfy oxlint, and regenerate the global migration snapshots
that now include the direct `vite` devDep for pnpm vite-plus consumers.

Refs #1932
- Extract `ensureDirectViteForPnpm` and reuse it for the root, per-package,
  and standalone migration paths (was duplicated, and the standalone path
  was missing entirely, so a pnpm project adopting vite-plus without a prior
  vite still reproduced the duplicate-instance bug).
- Skip injection when `vite` is declared only as a peerDependency, so a vite
  plugin's peer contract (e.g. `vite ^6`) is preserved instead of getting a
  conflicting concrete devDep (reverts the two skip-vite-peer snapshots).
- Guard against a custom VP_OVERRIDE_PACKAGES without a `vite` key, which
  crashed the root branch with a TypeError.
- Treat any declared vite spec (including an empty string) as already-direct.
- Drop an em-dash from a new comment.

Refs #1932
Drop the inert getCatalogDependencySpec options (dependencyName /
packageManager / catalogDependencyResolver) - they only affect an existing
value or a peerDependencies field, neither of which applies to the fresh
devDependencies entry this helper writes - and the now-unused
catalogDependencyResolver parameter. Add the `vite` key in place via `??=`
to match the sibling npm branch instead of rebuilding the object.

No behavior change.
The rationale lives in the ensureDirectViteForPnpm JSDoc; drop the repeated
explanation (and #1932 tag) from the three call sites, keeping only the one
non-obvious note about the standalone path needing a second pass.
Wrap the six rewritePackageJson #1932 cases in a
`describe('pnpm direct-vite dedupe (#1932)')` block and drop the per-test
`(#1932)` tags; also drop the redundant tag from the provider-context case.
The issue is now referenced once (the describe name) instead of seven times.
Use `vp why -r` so the guard inspects every workspace package, not just the
root importer, catching a duplicate confined to a sub-package. Addresses the
Codex review comment.
oxfmt sorts package.json dependencies, but the #1932 helper appended `vite`
last. `vp create` re-formats afterward so it was fine, but `vp migrate` has
no format pass, so a migrated project failed a follow-up `vp check` (caught
by the vp-config E2E). Insert `vite` in sorted position instead; regenerate
the affected migration snapshots.
@fengmk2 fengmk2 force-pushed the fix/1932-pnpm-vite-dedupe branch from 4de2889 to f73fdbe Compare June 24, 2026 16:56
@fengmk2 fengmk2 requested a review from cpojer June 25, 2026 00:34
@fengmk2 fengmk2 merged commit 0b9e8de into main Jun 25, 2026
56 checks passed
@fengmk2 fengmk2 deleted the fix/1932-pnpm-vite-dedupe branch June 25, 2026 02:41
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.

pnpm monorepo: duplicate vite/vitest instances cause vp test cache misses

3 participants