Skip to content

fix(js): detect changes to pnpm.overrides and overrides in package.json#31914

Merged
Coly010 merged 2 commits intomasterfrom
fix-override-detection
Dec 16, 2025
Merged

fix(js): detect changes to pnpm.overrides and overrides in package.json#31914
Coly010 merged 2 commits intomasterfrom
fix-override-detection

Conversation

@AgentEnder
Copy link
Copy Markdown
Member

Current Behavior

getProjectPathsAffectedByDependencyUpdates in @packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts doesn't return projects affected when updating pnpm.overrides or overrides in package.json.

Expected Behavior

When overrides, resolutions, or pnpm.overrides fields are changed in package.json, the affected projects should be properly detected and returned.

Related Issue(s)

This addresses reports that affected project detection isn't working properly when package manager override configurations are changed.

Changes Made

  • Enhanced getTouchedNpmPackages function to detect changes to overrides, resolutions, and pnpm.overrides fields
  • When a known package is changed in overrides, only that specific package is marked as affected
  • When an unknown package is changed in overrides, all projects are marked as affected (since overrides can affect transitive dependencies)
  • Added comprehensive tests for all override scenarios

🤖 Generated with Claude Code

@AgentEnder AgentEnder requested a review from a team as a code owner July 14, 2025 17:05
@AgentEnder AgentEnder requested a review from xiongemi July 14, 2025 17:05
@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nx-dev Ready Ready Preview Dec 16, 2025 10:34am

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Jul 14, 2025

View your CI Pipeline Execution ↗ for commit 16bb9d0

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 9m 52s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 36s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 13s 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 2025-12-16 10:46:07 UTC

Copy link
Copy Markdown
Contributor

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about patches?

@AgentEnder AgentEnder force-pushed the fix-override-detection branch from ecb4304 to 5e56229 Compare September 4, 2025 20:46
) {
// Changes to overrides, resolutions, or pnpm.overrides
// Find which package was changed and mark projects that depend on it as affected
const packageName = c.path[0] === 'pnpm' ? c.path[2] : c.path[1];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code could encounter an array index out of bounds error when processing package overrides. For 'pnpm.overrides', the path structure is ['pnpm', 'overrides', packageName], making c.path[2] correct. For regular 'overrides'/'resolutions', the path is ['overrides'/'resolutions', packageName], making c.path[1] correct.

However, if a change affects the entire overrides object rather than a specific package (e.g., adding/removing the whole object), then c.path[1] or c.path[2] could be undefined. Consider adding a check to ensure the path has sufficient elements before accessing these indices:

const packageName = c.path[0] === 'pnpm' 
  ? (c.path.length > 2 ? c.path[2] : undefined) 
  : (c.path.length > 1 ? c.path[1] : undefined);

if (!packageName) {
  // Handle case where the entire overrides object was changed
  return Object.keys(projectGraph.nodes);
}
Suggested change
const packageName = c.path[0] === 'pnpm' ? c.path[2] : c.path[1];
const packageName = c.path[0] === 'pnpm' ? (c.path.length > 2 ? c.path[2] : undefined) : (c.path.length > 1 ? c.path[1] : undefined);
if (!packageName) {
// Handle case where the entire overrides object was changed
return Object.keys(projectGraph.nodes);
}

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

- Add detection for overrides, resolutions, and pnpm.overrides changes
- Return specific packages when known, all projects when unknown
- Add comprehensive tests for all override scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Coly010 Coly010 force-pushed the fix-override-detection branch from 5e56229 to 49ffaf3 Compare December 16, 2025 09:44
@Coly010 Coly010 requested a review from a team as a code owner December 16, 2025 09:44
@Coly010 Coly010 requested review from Coly010 and removed request for xiongemi December 16, 2025 09:44
@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 16, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 16bb9d0
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/694134d60f3ae80008b192de
😎 Deploy Preview https://deploy-preview-31914--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.

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.

✅ The fix from Nx Cloud was applied

These changes fix the TypeScript compilation error by removing the invalid hash property from the five newly added test cases in npm-packages.spec.ts. The FileChange interface only supports file and getChanges properties, so our tests now correctly follow the existing pattern used throughout the test file.

Suggested Fix changes
diff --git a/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts b/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts
index 21cf2f073b..2818b7fb5f 100644
--- a/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts
+++ b/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts
@@ -330,7 +330,6 @@ describe('getTouchedNpmPackages', () => {
       [
         {
           file: 'package.json',
-          hash: 'some-hash',
           getChanges: () => [
             {
               type: JsonDiffType.Modified,
@@ -363,7 +362,6 @@ describe('getTouchedNpmPackages', () => {
       [
         {
           file: 'package.json',
-          hash: 'some-hash',
           getChanges: () => [
             {
               type: JsonDiffType.Modified,
@@ -396,7 +394,6 @@ describe('getTouchedNpmPackages', () => {
       [
         {
           file: 'package.json',
-          hash: 'some-hash',
           getChanges: () => [
             {
               type: JsonDiffType.Added,
@@ -429,7 +426,6 @@ describe('getTouchedNpmPackages', () => {
       [
         {
           file: 'package.json',
-          hash: 'some-hash',
           getChanges: () => [
             {
               type: JsonDiffType.Deleted,
@@ -462,7 +458,6 @@ describe('getTouchedNpmPackages', () => {
       [
         {
           file: 'package.json',
-          hash: 'some-hash',
           getChanges: () => [
             {
               type: JsonDiffType.Deleted,

Revert fix via Nx Cloud  

View interactive diff ↗
This fix was applied by Colum Ferry

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

Co-authored-by: AgentEnder <AgentEnder@users.noreply.github.com>
@Coly010 Coly010 merged commit 98e4792 into master Dec 16, 2025
20 checks passed
@Coly010 Coly010 deleted the fix-override-detection branch December 16, 2025 11:05
FrozenPandaz pushed a commit that referenced this pull request Dec 16, 2025
…on (#31914)

## Current Behavior

`getProjectPathsAffectedByDependencyUpdates` in
`@packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts`
doesn't return projects affected when updating `pnpm.overrides` or
`overrides` in package.json.

## Expected Behavior

When `overrides`, `resolutions`, or `pnpm.overrides` fields are changed
in package.json, the affected projects should be properly detected and
returned.

## Related Issue(s)

This addresses reports that affected project detection isn't working
properly when package manager override configurations are changed.

## Changes Made

- Enhanced `getTouchedNpmPackages` function to detect changes to
`overrides`, `resolutions`, and `pnpm.overrides` fields
- When a known package is changed in overrides, only that specific
package is marked as affected
- When an unknown package is changed in overrides, all projects are
marked as affected (since overrides can affect transitive dependencies)
- Added comprehensive tests for all override scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
Co-authored-by: AgentEnder <AgentEnder@users.noreply.github.com>
@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 Dec 22, 2025
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.

4 participants