fix(js): detect changes to pnpm.overrides and overrides in package.json#31914
fix(js): detect changes to pnpm.overrides and overrides in package.json#31914
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
View your CI Pipeline Execution ↗ for commit 16bb9d0
☁️ Nx Cloud last updated this comment at |
828257d to
ecb4304
Compare
ecb4304 to
5e56229
Compare
| ) { | ||
| // 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]; |
There was a problem hiding this comment.
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);
}| 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
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>
5e56229 to
49ffaf3
Compare
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
✅ 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,
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>
…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>
|
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. |
Current Behavior
getProjectPathsAffectedByDependencyUpdatesin@packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.tsdoesn't return projects affected when updatingpnpm.overridesoroverridesin package.json.Expected Behavior
When
overrides,resolutions, orpnpm.overridesfields 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
getTouchedNpmPackagesfunction to detect changes tooverrides,resolutions, andpnpm.overridesfields🤖 Generated with Claude Code