Skip to content

Commit

Permalink
fix(upgrade) Fix basicSemverOperatorRegex (#7080)
Browse files Browse the repository at this point in the history
**Summary**

Fix bug #7079 of `basicSemverOperatorRegex`. It doesn't match the range operator correctly if the dependency range is specified with `>=`. For example, when running `yarn upgrade --latest`, if a dependency is specified with `>=`, the matched result will be `>`, which is not correct. 

This is because the regular expression engine looks for alternations one-by-one. We can fix it by putting `>=` before `>`.

fixes #7079
  • Loading branch information
shilcare authored and rally25rs committed Mar 5, 2019
1 parent aebe9e9 commit 82d5891
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Fixes yarn `upgrade --latest` for dependencies using `>` or `>=` range specifier

[#7080](https://github.com/yarnpkg/yarn/pull/7080) - [**Xukai Wu**](https://github.com/shilcare)

- Fixes `--modules-folder` handling in several places (ex: `yarn check` now respects `--modules-folder`)

[#6850](https://github.com/yarnpkg/yarn/pull/6850) - [**Jeff Valore**](https://twitter.com/codingwithspike)
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/upgrade.js
Expand Up @@ -12,7 +12,7 @@ import {Install} from './install.js';

// used to detect whether a semver range is simple enough to preserve when doing a --latest upgrade.
// when not matched, the upgraded version range will default to `^` the same as the `add` command would.
const basicSemverOperatorRegex = new RegExp('^(\\^|~|>|<=|>=)?[^ |&,]+$');
const basicSemverOperatorRegex = new RegExp('^(\\^|~|>=|<=)?[^ |&,]+$');

// used to detect if a passed parameter is a scope or a package name.
const validScopeRegex = /^@[a-zA-Z0-9-][a-zA-Z0-9_.-]*\/$/;
Expand Down Expand Up @@ -74,7 +74,7 @@ function setUserRequestedPackageVersions(
}

// this function attempts to determine the range operator on the semver range.
// this will only handle the simple cases of a semver starting with '^', '~', '>', '>=', '<=', or an exact version.
// this will only handle the simple cases of a semver starting with '^', '~', '>=', '<=', or an exact version.
// "exotic" semver ranges will not be handled.
function getRangeOperator(version): string {
const result = basicSemverOperatorRegex.exec(version);
Expand Down

0 comments on commit 82d5891

Please sign in to comment.