rushstack
rushstack copied to clipboard
[rush] Add semver defaults to be used by `rush add`
Summary
Adds dependencyVersionDefaults to common-versions.json, to be consumed by rush add for determining a user-defined default semver style.
Details
It's sometimes desired to specify different default semver styles for various kinds of packages, or simply to define a global fallback.
To accomplish this, support for dependencyVersionDefaults has been added to CommonVersionsConfiguration (and related schema/configs), and it exposes the getDefaultSemverForPackage method to calculate the default semver for a package.
dependencyVersionDefaults consists of an array of objects containing both packageNamePattern and semverStyle. During processing, the desired package name will be compared against each packageNamePattern, and the semverStyle of the first one that matches will be used to determine the chosen semver details. If no semver default is found, then tilde will be the general fallback.
PackageJsonUpdater now exposes SemverStyle.Auto; when no semver style is declared explicitly on the command line, SemverStyle.Auto will be used. With that, if no other method for determining a version and/or semver was successful, PackageJsonUpdater knows that it should ask CommonVersionsConfiguration for the desired semver for the package.
Since there is no --tilde cli option on rush add, this dependencyVersionDefaults could potentially disallow a user from selecting tilde semvers entirely. Because of this, I've added the --tilde flag to AddAction.
One thing I wasn't entirely sure about was the desired method for sharing utilities. I wanted to use the same matchesWithStar that DeployManager uses, so I moved it from logic/deploy/Util.ts to utilities/Utilities.ts
Fixes #1468
How it was tested
- Unit tests for
CommonVersionsConfiguration.getDefaultSemverStyle() - Manually testing it against one of my rush monorepos
Test cases
- Version selection for package existing in repo matches existing
- All semver cli options for
rush addwork to explicitly set the desired semver style--caret--tilde--exact- "passthrough"
- Specific package name patterns match only that package
- Package name patterns with wildcard match correctly
- Fallback pattern (
*) provides general default for semver style - Packages that do not match any dependency version default package name patterns fall back to
tilde - Undefined or empty
dependencyVersionDefaultsresults intildesemver style
Note: PR #3337 has renamed our GitHub master branch to main. This should not affect your pull request, but we recommend to redo your git clone to avoid confusion with the old branch name.
@iclanton thanks for letting me know. I'll make sure to do that