Skip to content

fix(content): support validator detection with pnpm enableGlobalVirtualStore#3791

Open
BellYun wants to merge 3 commits into
nuxt:mainfrom
BellYun:fix/pnpm-global-virtual-store-zod-detection
Open

fix(content): support validator detection with pnpm enableGlobalVirtualStore#3791
BellYun wants to merge 3 commits into
nuxt:mainfrom
BellYun:fix/pnpm-global-virtual-store-zod-detection

Conversation

@BellYun
Copy link
Copy Markdown

@BellYun BellYun commented May 17, 2026

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This fixes validator detection when using pnpm 11 with enableGlobalVirtualStore: true.

With pnpm's default layout, project dependencies are linked through the local virtual store at node_modules/.pnpm,
when enableGlobalVirtualStore is enabled, node_modules instead points to a shared central virtual store outside the project.

That make two issues in @nuxt/content:

  1. Validator package detection was resolving from the user project instead of @nuxt/content's own location, so zod could appear to be missing even when it was available through the module installation
  2. During content.config.ts evaluation, @nuxt/content could be evaluated more than once, which caused the validator registry to fall back to its stub state and throw the "Zod is not installed" error

This PR updates validator package detection to resolve from @nuxt/content itself and preserves the validator registry across duplicate module evaluation.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

@BellYun is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 21c729f0-8c7f-4559-858c-dfe829d63663

📥 Commits

Reviewing files that changed from the base of the PR and between c2b8030 and f276d79.

📒 Files selected for processing (1)
  • test/unit/validatorRegistry.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/validatorRegistry.test.ts

📝 Walkthrough

Walkthrough

This PR establishes a global singleton pattern for the validators context to prevent reset on duplicate module evaluation. src/utils/context.ts now stores a typed context on globalThis under a symbol key, with accessor methods to ensure all module instances share the same object. Supporting the change, src/utils/dependencies.ts switches package detection from dynamic import() to resolvePackageJSON() for compatibility with pnpm's virtual store. A new test suite verifies that re-importing the context modules returns the same singleton instance and confirms schema conversion operates without errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing validator detection with pnpm's enableGlobalVirtualStore feature.
Description check ✅ Passed The description thoroughly explains the problem, root causes, and solutions related to the validator detection and module evaluation issues, directly corresponding to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/unit/validatorRegistry.test.ts`:
- Around line 6-8: The test helper resetValidatorsContext currently uses a
dynamic delete on globalThis which trips `@typescript-eslint/no-dynamic-delete`;
replace the delete with an assignment to undefined on the same symbol key so the
singleton is cleared but no dynamic delete is used (modify
resetValidatorsContext to set (globalThis as Record<symbol,
unknown>)[SINGLETON_KEY] = undefined instead of deleting it), referencing the
SINGLETON_KEY and globalThis symbols to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbc76699-75bd-488d-b16c-c5c4d55f2265

📥 Commits

Reviewing files that changed from the base of the PR and between ab88eb3 and c2b8030.

📒 Files selected for processing (3)
  • src/utils/context.ts
  • src/utils/dependencies.ts
  • test/unit/validatorRegistry.test.ts

Comment thread test/unit/validatorRegistry.test.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2026

npm i https://pkg.pr.new/@nuxt/content@3791

commit: f276d79

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.

1 participant