fix(core): use workspace package manager when fetching migrations via install#35866
Merged
Merged
Conversation
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
View your CI Pipeline Execution ↗ for commit 75ff3ba
☁️ Nx Cloud last updated this comment at |
AgentEnder
approved these changes
Jun 3, 2026
… install When `nx migrate` falls back to installing a package in a temporary directory to read its migrations, the install detected the package manager from that empty temp directory. With no lock file there, detection fell back to npm even in yarn/pnpm/bun workspaces, so the install ran with npm and ignored the workspace package manager's registry/auth configuration. The package manager is already resolved in `generateMigrationsJsonAndUpdatePackageJson` before the fetcher is created, so thread that value through `createFetcher` into the install fallback instead of re-detecting it against the temp directory.
…mp install For pnpm workspaces the temporary migration-fetch install runs `pnpm add -w`, which fails with "--workspace-root may only be used inside a workspace" unless a pnpm-workspace.yaml is present in the directory. Copy one into the temp dir, sanitized to fit the new location: drop `packages` (workspace member globs) and `patchedDependencies` (relative patch-file paths), which only resolve in the real workspace, and keep the rest (registry, auth, minimumReleaseAge, ...). This also lets the install honor the workspace's registry/auth and release-age settings instead of silently bypassing them.
cc127f0 to
8e307ef
Compare
…mp install [Self-Healing CI Rerun]
…mp install [Self-Healing CI Rerun]
… is preserved The hardcoded `addCommand = 'pnpm add -D'` override stripped `-w` from `pmCommands.addDev`. That was correct when the temp dir had no `pnpm-workspace.yaml`, but the recent fix to copy a sanitized `pnpm-workspace.yaml` into the temp dir promotes it to a workspace root and pnpm rejects `pnpm add -D` (no `-w`) there. Use `pmCommands.addDev` verbatim and thread the resolved package manager through `installPackageToTmp` / `installPackageToTmpAsync` / `preparePackageInstallation` so callers (init-v2, configure-ai-agents, latest-nx, set-up-ai-agents, devkit's ensurePackage) pass the right detection root rather than the function re-detecting from `workspaceRoot` by default.
… is preserved [Self-Healing CI Rerun]
Contributor
There was a problem hiding this comment.
Nx Cloud has identified a flaky task in your failed CI:
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
🎓 Learn more about Self-Healing CI on nx.dev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
When
nx migratecan't read a package's migrations from the registry, it falls back to installing thepackage in a temporary directory to read them. That fallback detected the package manager from the
temp directory itself — which has no lock file — so detection fell back to npm even in yarn / pnpm /
bun workspaces. The fetch then ran
npm install, ignoring the workspace package manager's registry,auth, and release-age configuration (for example, a private registry configured in
.yarnrc.yml, orpnpm's
minimumReleaseAge), which can break migrations that resolve through a private registry.Expected Behavior
The package manager is already resolved once in
generateMigrationsJsonAndUpdatePackageJson(beforethe fetcher is created). That value is now threaded through
createFetcherinto the install fallback,so the temporary install uses the workspace's package manager. The fetch helper no longer detects the
package manager at all, so it can't resolve it against the empty temp directory.
For pnpm workspaces the install runs
pnpm add -w, which requires apnpm-workspace.yamlto bepresent in the directory (otherwise it fails with
--workspace-root may only be used inside a workspace). A sanitized copy is now placed in the temp dir:packages(workspace member globs)and
patchedDependencies(relative patch-file paths) are dropped because they only resolve in thereal workspace, while
registry, auth, andminimumReleaseAgeare kept. This fixes the-wfailureand lets the install honor the workspace's registry/auth and release-age settings.
The install still runs in the temp directory; only the configuration and package-manager choice now
come from the workspace.
createTempNpmDirectoryalready copied.npmrc/.yarnrc/.yarnrc.yml/
bunfig.toml; this adds the sanitizedpnpm-workspace.yamlalongside them.Related Issue(s)
Relates to NXC-4499.