syncpack icon indicating copy to clipboard operation
syncpack copied to clipboard

fix(versions): Empty Objects are removed when format or fix-mismatches invoked.

Open denis-fwd opened this issue 1 year ago • 2 comments
trafficstars

Description

Greetings! I am syncpack newest fan. Thank you for your effort. I am coming to you as I have an issue that, after reviewing, the source appears to not be a user error.

My issue is this - I would like to have a property in package.json which is empty. This is due to nx and the use of root-level tasks: https://nx.dev/recipes/running-tasks/root-level-scripts#setup. However, anytime I run fix-mismatches the empty object tied to nx property disappears.

Related: https://github.com/JamieMason/syncpack/issues/117

Steps to reproduce:

  1. Create a root nx property inpackage.json
  2. Run syncpack fix-mismatches
  3. Observe the removal of the property and its object.

Suggested Solution

I believe the issue is related to this function - https://github.com/JamieMason/syncpack/blob/main/src/bin-fix-mismatches/fix-mismatches.ts#L94

I propose that the configuration consider a deny list, that suggests to syncpack "I know what I am doing" for the following operations. Something like:

{
  "denyList": {
    "nx": {
      "path": "nx",
      "operations": ["fix-mismatches"]    
    }
  }
}

I realize this interface may not be needed in its entirety to solve my issue. However I believe something like this can allow for more refined customization and implicitly allows the code paths to continue working as they do today.

Help Needed

I am hoping a fix can be made in the area identified if it is the correct code path. Happy to test out any solution!

denis-fwd avatar Jun 13 '24 18:06 denis-fwd

Thanks a lot @denis-fwd, great issue and you're exactly right.

  1. We only need to check and clean up empty objects if a Banned Version Group has been fixed and eg. devDependencies is now empty as a result.
  2. We should only check and clean up empty objects in the places syncpack has removed banned dependencies.

But, the way I've done it is pretty sloppy – it always runs and is not targeted about what it cleans up. I'll get this fixed in the next version.

JamieMason avatar Jun 16 '24 07:06 JamieMason

@JamieMason no the thanks goes to you. I appreciate your work and look forward to the next release. For folks coming across this issue, I've created my own sloppy fix for this in the interim:

If I set the field like this to avoid it getting deleted:

// package.json
{
  "nx": {
     "targets": [] 
  }
}

@JamieMason feel free to close this at your leisure.

denis-fwd avatar Jun 17 '24 15:06 denis-fwd

Hey @denis-fwd, this should be fixed now in 13.0.2.

FYI also @tylerbutler as it looks like #117 must have regressed at some point, as the empty object removal code was back in there.

JamieMason avatar Feb 05 '25 17:02 JamieMason

@JamieMason thanks looking forward to upgrading - thank you for this!

denis-fwd avatar Feb 07 '25 01:02 denis-fwd