Skip to content

fix(core): use workspace package manager when fetching migrations via install#35866

Merged
FrozenPandaz merged 6 commits into
masterfrom
fix/migrate-temp-install-uses-workspace-pm
Jun 4, 2026
Merged

fix(core): use workspace package manager when fetching migrations via install#35866
FrozenPandaz merged 6 commits into
masterfrom
fix/migrate-temp-install-uses-workspace-pm

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Contributor

@FrozenPandaz FrozenPandaz commented Jun 3, 2026

Current Behavior

When nx migrate can't read a package's migrations from the registry, it falls back to installing the
package 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, or
pnpm's minimumReleaseAge), which can break migrations that resolve through a private registry.

Expected Behavior

The package manager is already resolved once in generateMigrationsJsonAndUpdatePackageJson (before
the fetcher is created). That value is now threaded through createFetcher into 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 a pnpm-workspace.yaml to be
present 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 the
real workspace, while registry, auth, and minimumReleaseAge are kept. This fixes the -w failure
and 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. createTempNpmDirectory already copied .npmrc / .yarnrc / .yarnrc.yml
/ bunfig.toml; this adds the sanitized pnpm-workspace.yaml alongside them.

Related Issue(s)

Relates to NXC-4499.

@FrozenPandaz FrozenPandaz requested a review from a team as a code owner June 3, 2026 17:34
@FrozenPandaz FrozenPandaz requested a review from lourw June 3, 2026 17:34
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 3, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 46adf25
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a20eb6cf413fb00083dd314
😎 Deploy Preview https://deploy-preview-35866--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.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 3, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 46adf25
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a20eb6c7d8ee300089fb157
😎 Deploy Preview https://deploy-preview-35866--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.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Jun 3, 2026

View your CI Pipeline Execution ↗ for commit 75ff3ba

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

☁️ Nx Cloud last updated this comment at 2026-06-04 03:29:29 UTC

nx-cloud[bot]

This comment was marked as outdated.

… 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.
@FrozenPandaz FrozenPandaz force-pushed the fix/migrate-temp-install-uses-workspace-pm branch from cc127f0 to 8e307ef Compare June 3, 2026 20:06
@FrozenPandaz FrozenPandaz enabled auto-merge (squash) June 3, 2026 20:07
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

FrozenPandaz and others added 2 commits June 3, 2026 22:20
… 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.
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.

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.

Nx Cloud View detailed reasoning in Nx Cloud ↗


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

@FrozenPandaz FrozenPandaz merged commit bf90783 into master Jun 4, 2026
18 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/migrate-temp-install-uses-workspace-pm branch June 4, 2026 03:30
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.

2 participants