-
Notifications
You must be signed in to change notification settings - Fork 3k
Auto-detect and merge lockfile conflicts #18007
Comments
|
possibly another way to look at this could be providing a way to force regeneration of the lockfile. since the lockfile should really only ever be modified by npm, i would rather treat the lockfile as binary in git and regenerate it from the this option might not handle all use cases, but it would cover mine pretty well and allow marking the lockfile as binary in git. |
|
Can just enter in here, the package-lock.json just like yarn.lock are banned from our projects, as they create more problems than they actually solve. As these problems actually only exits b/c with the new autogenerated lockfiles in place, they do break any and every workflow. and merge requests in general, this feature is somehow necessary. You only need to have two developers making in two merge requests two different changes to the package.json which are legitimate and entering their new version of package-lock.json. At this point the best option would be to actually throw the package-lock.json away rather than really wasting time on merging these changes together. To solve this either a proper way to merge them easily is needed or to question and revert the per default generation of this file on every npm install, just like it was before. The reason for this is simply that it feels like package-lock.json is rather a replacement for package.json than an extension. If I would wanted to have my packages locked down I could always have specified a locked in version instead of a selector. But now these selectors actually mutated from automatically getting the latest version depending on these versions to being a helper when explicitly upgrading packages, which destroys somehow the original purpose. Instead I would want to lock down versions by intention and not by accident and really only if I go to production with them. So maybe going this way per default is just the wrong way, but maybe my opinion is just plainly wrong. I'm eager to hear your opinion and your explanation to that. |
|
@travi Regenerating the lockfile from the |
|
@jacob-hd as i mentioned, regenerating doesnt handle all use cases, but could solve some valuable ones if it were simpler. however, it doesnt necessarily defeat the purpose of having a lockfile. i specify exact versions in my the biggest risk that the lockfile solves for me is those non-direct dependencies releasing an update that is in-range of my direct dependency that is breaking, which gets deployed without any commit happening. i'm far less worried about those versions updating as a result of regenerating a lockfile in a way that results in a commit that has a chance to be verified before moving forward. |
|
Merge conflicts appear to be an inevitable, and largely unforeseen consequence of working with lockfiles. Yarn seems to have been quick to address this issue, and NPM needs to do the same. In fact, I would argue that it is more important for NPM to address this issue because its lockfiles are significantly larger -- and therefore significantly more unwieldy -- than Yarn's. Regenerating the lockfile is not a viable long-term solution because it is destructive. I would rather refer to this option as "resetting the lockfile", as regenerating connotes that a lockfile is somehow a deterministic function of the contents of As someone who is trying to convince a team of engineers to begin using lockfiles, this is a pain-point that is hindering adoption and will make compliance an issue going forward. TL;DR Without automatic merge conflict resolution, the negative impact on developer experience makes working with lockfiles an unreasonable ask for teams. |
|
I like the distinction you made between conflict resolution and resetting the lockfile. I do think there are cases where resetting would be useful and have been frustrated by the lack of being able to do so easily. however, you are completely correct that it is a separate need from repairing a lockfile that you want to maintain w/o resetting. |
|
Just recently ran into this... FWIW, this is how we've started dealing with it... We generally have a "more stable" (i.e. It is possible for the Still not perfect because it has to be manually done each time a lock-file change goes into the more stable branch and I'd love to see something added to |
|
@crussell52 You seem to be implying that you're editing a lock file by hand, or letting git merge the lock files (which constitutes an edit). However, lock files should never be edited by anything other than the npm process. |
|
I'm thinking the easiest and semi-decent way to handle this is to use a .gitattributes file and mark the lock file as a binary. That way it should just choose a version rather than try to merge the internals right? But I agree, npm should address this properly. |
|
@jacob-hd while i agree with you that only the npm process should touch this file, it does not appear that the npm team agrees. @russelltrafford i mentioned above that i think it should be marked as binary, but that has proven to be more of a pain than it is worth. this ends up with the file having a conflict any time it changes from two different sources. while i agree that this is at least somewhat desired, it results in almost every PR that includes a package change needing to have conflicts resolved if not pulled in immediately. i've decided to stop marking as binary and let git merge as best as it can unless the npm team can find a way to enable truly letting the npm cli be the only thing that modifies the lockfile |
|
@jacob-hd I agree that a built-in handling is the way to go here. I'm just sharing my current process to (maybe) help others and maybe spark some ideas within the npm team.... or maybe I'll find out that what I'm doing is a terrible idea... I am, after all, relatively new to the To clarify, I am not making any manual entries into the lock file -- instead, I'm basically abandoning changes made in the This can absolutely introduce new risk into the |
|
We've been using an approach like @crussell52 's. A partial solution could be a build script (or even small npm module) that does the following:
|
|
It appears this is fixed with e27674c |
|
From the commit mentioned above,
|
What's the feature?
package-lock.jsonconflicts are difficult to manually resolve and regenerating thepackage-lockopts into often unwanted upgrades of dependencies and their children.npmshould be able to detect conflicts in thepackage-lock.jsonand correct them.What problem is the feature intended to solve?
Large teams can very often run into merge conflicts of
package-lock.jsonwhen dependencies are added, upgraded, or removed in branches. These conflicts can be incredibly difficult to resolve manually, the often suggested solution is to remove and re-generatepackage-lock.json, this often opts you into unwanted upgrades of packages and children (npm5 is now deterministic, but not idempotent from only a package.json`)Is the absence of this feature blocking you or your team? If so, how?
Currently my team manually merges the
package-lock.jsonand attempts to re-runnpm iand add any modifications topackage-lock.jsonto the merge/rebase. This is prone to error.Is this feature similar to an existing feature in another tool?
Yes. It was recently added in yarn. yarnpkg/yarn#3544
Is this a feature you're prepared to implement, with support from the npm CLI team?
Assist in, but I don't believe I'm best suited to implement.
The text was updated successfully, but these errors were encountered: