Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

FrozenPandaz
Copy link
Collaborator

@FrozenPandaz FrozenPandaz commented Aug 21, 2025

Summary

Fixes an issue where properties from package.json were being incorrectly copied to project.json when updating project configuration in projects that have both files.

Changes Made

Core Fix (Surgical Approach)

  • Modified updateProjectConfigurationInProjectJson with minimal changes:
    • When only project.json exists: Uses original logic (no changes)
    • When both files exist: Only includes properties that should logically belong in project.json
    • Targets handling: Checks each target individually to avoid copying targets from package.json
    • Other properties: Simple rule - include if originally in project.json OR not in package.json

Key Benefits

  • Minimal code changes: ~30 lines changed vs ~150+ in complex approach
  • Surgical fix: Only modifies behavior when both files exist
  • Maintains all existing functionality: No breaking changes
  • Easy to understand: Simple, clear logic without complex merge detection

Test Coverage

  • Property separation: Ensures tags, implicitDependencies, namedInputs from package.json don't get copied
  • Target isolation: Verifies individual targets are properly separated between files
  • Backwards compatibility: All existing tests continue to pass

Implementation Details

The fix works by:

  1. Reading the existing project.json to understand what was originally there
  2. Reading package.json to understand what should stay there
  3. For each property in the merged config, deciding whether it belongs in project.json based on simple rules
  4. Special handling for targets to check individual targets rather than the entire property

This approach fixes the core issue while keeping the implementation simple and maintainable.

Fixes #ISSUE_NUMBER (if applicable)

…during updates

When a project has both project.json and package.json files, the updateProjectConfiguration
function was incorrectly copying properties from package.json into project.json.

This change modifies updateProjectConfigurationInProjectJson to:
- Only include properties that were originally in project.json or are new
- Handle nested properties like targets and metadata intelligently
- Detect and prevent merge artifacts from being written to project.json
- Preserve existing behavior for empty targets and other edge cases

Includes comprehensive test coverage for the new behavior.
Copy link

vercel bot commented Aug 21, 2025

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

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Aug 21, 2025 11:19pm

Copy link
Contributor

nx-cloud bot commented Aug 21, 2025

🤖 Nx Cloud AI has a fix for the failures below

Fix generation failed • View Fix ↗


View your CI Pipeline Execution ↗ for commit 42fc605

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ❌ Failed 48m 13s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 2m 19s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗
nx documentation ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-21 23:57:52 UTC

… in project.json

Replace complex implementation with surgical fix that:
- Uses original logic when only project.json exists
- When both files exist, only copies properties that belong in project.json
- Handles targets specially to check individual targets
- Keeps implementation minimal and maintainable
…erties

Verifies that project.json can properly override properties from package.json
such as name, while maintaining proper separation of concerns between the files.
…different values

When updating project configuration, properties that have different values
than what's in package.json should be written to project.json to enable
proper overrides. Previously, properties would be skipped if they existed
in package.json, even if the new value was different.
Simplify the implementation to be closer to the original logic.
When no package.json exists, use original behavior exactly.
When package.json exists, filter projectConfiguration before spreading.
Maintain the same writeJson structure as original code.
Replace multiple specific assertions with single toEqual expectations
for each file, making tests more declarative and easier to read.
Each test now has exactly 2 expectations: one for project.json content
and one for package.json content.
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.

1 participant