Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Lockfile should be updated when merge conflcits are resolved #4195

Merged
merged 3 commits into from
Aug 18, 2017

Conversation

BYK
Copy link
Member

@BYK BYK commented Aug 17, 2017

Summary

Follow up to #3544. Currently, yarn happily keeps moving if it
detects merge conflicts and is able to resolve them in the lockfile.
That said it doesn't persist the resolution by saving the lockfile
to disk again. This patch ensures writing the lockfile if it is
"dirty".

This patch also causes yarn to throw an error if there are merge
conflicts in the file and --frozen-lockfile option is true.

Test plan

Existing unit tests. Also try running yarn install with the following
files:
package.json

{
  "name": "yarnlock-auto-merge",
  "version": "1.0.0",
  "main": "index.js",
  "author": "Burak Yigit Kaya <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "left-pad": "^1.1.3",
    "right-pad": "^1.0.1"
  }
}

yarn.lock


<<<<<<< HEAD
left-pad@^1.1.3:
  version "1.1.3"
  resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
=======
right-pad@^1.0.1:
  version "1.0.1"
  resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
>>>>>>> right-pad

Without the patch, yarn won't update the lockfile. With the patch,
the lockfile is replaced with the merged version.

**Summary**

Follow up to #3544. Currently, `yarn` happily keeps moving if it
detects merge conflicts and is able to resolve them in the lockfile.
That said it doesn't persist the resolution by saving the lockfile
to disk again. This patch ensures writing the lockfile if it is
"dirty".

This patch also causes `yarn` to throw an error if there are merge
conflicts in the file and `--frozen-lockfile` option is true.

**Test plan**

Existing unit tests. Also try running `yarn install` with the following
files:
`package.json`

```
{
  "name": "yarnlock-auto-merge",
  "version": "1.0.0",
  "main": "index.js",
  "author": "Burak Yigit Kaya <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "left-pad": "^1.1.3",
    "right-pad": "^1.0.1"
  }
}
```

`yarn.lock`

```

<<<<<<< HEAD
left-pad@^1.1.3:
  version "1.1.3"
  resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
=======
right-pad@^1.0.1:
  version "1.0.1"
  resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
>>>>>>> right-pad
```

Without the patch, `yarn` won't update the lockfile. With the patch,
the lockfile is replaced with the merged version.
@BYK BYK requested a review from arcanis August 17, 2017 16:36
@@ -38,7 +38,7 @@ export async function createLockfile(dir: string): Promise<Lockfile> {
lockfile = parse(rawLockfile).object;
}

return new Lockfile(lockfile);
return new Lockfile(lockfile, undefined, 'success');
Copy link
Member

@arcanis arcanis Aug 17, 2017

Choose a reason for hiding this comment

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

Shouldn't the third parameter be an optional object that takes a parseResult key?

Copy link
Member Author

Choose a reason for hiding this comment

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

The third parameter is just the parse result type, not the parse result itself. May be I should rename the variable to make that clear?

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah I see, yep, probably. But my point was more about avoiding unnamed arguments (new Lockfile(..., { parseResultType: 'success' })).

} else {
if (reporter) {
reporter.info(reporter.lang('noLockfileFound'));
}
}

return new Lockfile(lockfile, rawLockfile);
return new Lockfile(lockfile, rawLockfile, parseResult && parseResult.type);
Copy link
Member

@arcanis arcanis Aug 17, 2017

Choose a reason for hiding this comment

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

I think a ternary would better convey the semantic, wdyt? The && behavior kinda obfuscates the fact that the return value is parseResult.type rather than a boolean.

Copy link
Member Author

Choose a reason for hiding this comment

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

x && x.y is a pattern that I see used in many places to protect against "potentially null x" situations but if you strongly think that a ternary would be better, I'll change it.

@BYK
Copy link
Member Author

BYK commented Aug 17, 2017

@arcanis updated to use named arguments. Looks much better, thanks!

@BYK BYK merged commit 70ca32c into master Aug 18, 2017
@BYK BYK deleted the dirty-lockfile branch August 18, 2017 15:10
@danReynolds
Copy link

danReynolds commented Aug 19, 2017

So does this mean that the functionality of doing yarn to resolve merge conflicts as outlined in #3544 is not working without this change since the resolved yarn.lock is not written to disk and wouldn't be commited?

@BYK
Copy link
Member Author

BYK commented Aug 19, 2017

The functionality is working since yarn resolves the conflict in memory and happily moves on. Also in most cases, node_modules is not up to date which triggers rewriting the lock file. This applies to situations where there's a lockfile with conflicts but node_modules is somehow up to date, already reflecting the resolved state.

This patch just makes sure the file is written if merge conflicts are detected. It also causes an error in frozen lockfile mode though since the lockfile needs an update.

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.

3 participants