Skip to content

fix(devkit): prevent double install in generators for TS solution workspaces#34891

Merged
FrozenPandaz merged 9 commits intomasterfrom
fix-double-install
Mar 20, 2026
Merged

fix(devkit): prevent double install in generators for TS solution workspaces#34891
FrozenPandaz merged 9 commits intomasterfrom
fix-double-install

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Contributor

@FrozenPandaz FrozenPandaz commented Mar 17, 2026

Current Behavior

In TS solution workspaces, library generators pass alwaysRun=true to installPackagesTask to ensure symlinks are created for new packages. However, when the init generator already triggered an install (via addDependenciesToPackageJson), the alwaysRun flag bypasses the cache and forces a redundant second install.

Expected Behavior

Only a single install should run per generator invocation. If install already ran this cycle, subsequent ensureInstall calls should be skipped since the previous install already picked up all filesystem changes (including pnpm-workspace.yaml updates for symlinks).

Fix

Renamed alwaysRun to ensureInstall in installPackagesTask and simplified the install condition:

if (packageJsonDiffers || (ensureInstall && !installAlreadyRan))

This handles both cases:

  • First library (deps change): init callback runs install → ensureInstall callback sees install already ran → skips. One install.
  • Second+ library (no dep changes): init callbacks are no-ops → ensureInstall callback sees no prior install → runs. One install.

Related Issue(s)

@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 17, 2026 21:56
@FrozenPandaz FrozenPandaz requested a review from MaxKless March 17, 2026 21:56
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 17, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 42c254b
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69bd7007fcff140008993bbc
😎 Deploy Preview https://deploy-preview-34891--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 17, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 42c254b
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69bd7007debda700088fc056
😎 Deploy Preview https://deploy-preview-34891--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.

…on workspaces

The library generators for @nx/js, @nx/node, and @nx/vue were passing
`alwaysRun=true` to `installPackagesTask` in TS solution workspaces,
which bypasses the package.json cache and causes a redundant second
install. The init generator already triggers an install via
`addDependenciesToPackageJson`, so the cache correctly deduplicates
when `alwaysRun` is not set.
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Mar 17, 2026

View your CI Pipeline Execution ↗ for commit 42c254b

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 53m 23s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 9s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 9s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-20 17:02:15 UTC

@FrozenPandaz FrozenPandaz marked this pull request as draft March 17, 2026 22:05
… already ran

When alwaysRun is true and install already executed this generator
cycle (cache is set), skip the redundant install. The previous install
already picked up all filesystem changes including workspace config
updates needed for symlinks.
@FrozenPandaz FrozenPandaz changed the title fix(core): prevent double install in library generators fix(devkit): prevent double install in generators for TS solution workspaces Mar 17, 2026
…brary generators

The library generators need ensureInstall=true for the second+
library case where no deps change but install must run for symlinks.
Renamed parameter since it no longer always runs — it skips when
install already ran this cycle.
@FrozenPandaz FrozenPandaz self-assigned this Mar 17, 2026
@FrozenPandaz FrozenPandaz marked this pull request as ready for review March 17, 2026 22:19
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

@FrozenPandaz FrozenPandaz enabled auto-merge (squash) March 19, 2026 13:42
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud 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

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud has identified a possible root cause for your failed CI:

We investigated the maven-batch-runner:_package failure and determined it is caused by a corrupted Nx database on the CI runner ("Database file exists but has no metadata table"), which is unrelated to the devkit changes in this PR. This error does not appear on the master branch and requires an environment reset (nx reset) to resolve rather than any code change.

No code changes were suggested for this issue.

Trigger a rerun:

Rerun CI

Nx Cloud View detailed reasoning on Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

@FrozenPandaz FrozenPandaz merged commit 7d25d08 into master Mar 20, 2026
23 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-double-install branch March 20, 2026 17:02
@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 26, 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