Skip to content

fix(vitest): resolve addPlugin default in init generator#34990

Merged
FrozenPandaz merged 1 commit into
masterfrom
fix-vitest-add
Mar 24, 2026
Merged

fix(vitest): resolve addPlugin default in init generator#34990
FrozenPandaz merged 1 commit into
masterfrom
fix-vitest-add

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Contributor

Current Behavior

Running nx add @nx/vitest does not register the @nx/vitest plugin in nx.json. The init generator had a wrapper function (initGenerator) that hardcoded addPlugin: false before spreading the user-provided schema. Since nx add calls the generator via CLI without passing addPlugin, the value stayed false — and the ??= default logic in initGeneratorInternal never fired because false is not nullish.

Expected Behavior

Running nx add @nx/vitest should register the @nx/vitest plugin in nx.json, matching the behavior of other plugins like @nx/jest, @nx/vite, and @nx/playwright.

Related Issue(s)

Changes

  • Merged initGenerator and initGeneratorInternal into a single initGenerator function that uses the ??= default logic directly
  • Added unit tests for the init generator covering plugin registration defaults, NX_ADD_PLUGINS env var, addPlugin: true vs false behavior, package.json handling, and namedInputs

The init generator had a wrapper function that hardcoded addPlugin: false,
preventing the plugin from being added when running nx add @nx/vitest.
Merged the two functions so the ??= default logic runs correctly.
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 24, 2026 16:49
@FrozenPandaz FrozenPandaz requested a review from MaxKless March 24, 2026 16:49
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 24, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit d4cc80d
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69c2c0acbb737100080e384d
😎 Deploy Preview https://deploy-preview-34990--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 24, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit d4cc80d
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69c2c0ac063f360008676e6d
😎 Deploy Preview https://deploy-preview-34990--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Mar 24, 2026

View your CI Pipeline Execution ↗ for commit d4cc80d

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 45m 49s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 10s View ↗
nx-cloud record -- pnpm nx conformance:check ✅ Succeeded 7s View ↗
nx build workspace-plugin ✅ Succeeded 1m View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-24 17:42:10 UTC

@FrozenPandaz FrozenPandaz enabled auto-merge (squash) March 24, 2026 17:28
@FrozenPandaz FrozenPandaz disabled auto-merge March 24, 2026 17:28
@FrozenPandaz FrozenPandaz enabled auto-merge (squash) March 24, 2026 17:35
@FrozenPandaz FrozenPandaz merged commit 7da0798 into master Mar 24, 2026
24 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-vitest-add branch March 24, 2026 17:42
FrozenPandaz added a commit that referenced this pull request Mar 26, 2026
## Current Behavior

Running `nx add @nx/vitest` does not register the `@nx/vitest` plugin in
`nx.json`. The init generator had a wrapper function (`initGenerator`)
that hardcoded `addPlugin: false` before spreading the user-provided
schema. Since `nx add` calls the generator via CLI without passing
`addPlugin`, the value stayed `false` — and the `??=` default logic in
`initGeneratorInternal` never fired because `false` is not nullish.

## Expected Behavior

Running `nx add @nx/vitest` should register the `@nx/vitest` plugin in
`nx.json`, matching the behavior of other plugins like `@nx/jest`,
`@nx/vite`, and `@nx/playwright`.

## Related Issue(s)

<!-- No existing issue tracked for this -->

## Changes

- Merged `initGenerator` and `initGeneratorInternal` into a single
`initGenerator` function that uses the `??=` default logic directly
- Added unit tests for the init generator covering plugin registration
defaults, `NX_ADD_PLUGINS` env var, `addPlugin: true` vs `false`
behavior, package.json handling, and namedInputs

(cherry picked from commit 7da0798)
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants