-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: local dependencies correct bump from release to prerelease (#34)
- Loading branch information
1 parent
3bfed38
commit 6481a59
Showing
9 changed files
with
415 additions
and
10,829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const execa = require("execa"); | ||
|
||
/** | ||
* Get all the tags for a given branch. | ||
* | ||
* @param {String} branch The branch for which to retrieve the tags. | ||
* @param {Object} [execaOptions] Options to pass to `execa`. | ||
* @param {Array<String>} filters List of prefixes/sufixes to be checked inside tags. | ||
* | ||
* @return {Array<String>} List of git tags. | ||
* @throws {Error} If the `git` command fails. | ||
* @internal | ||
*/ | ||
function getTags(branch, execaOptions, filters) { | ||
let tags = execa.sync("git", ["tag", "--merged", branch], execaOptions).stdout; | ||
tags = tags | ||
.split("\n") | ||
.map((tag) => tag.trim()) | ||
.filter(Boolean); | ||
|
||
if (!filters || !filters.length) return tags; | ||
|
||
const validateSubstr = (t, f) => !!f.find((v) => t.includes(v)); | ||
|
||
return tags.filter((tag) => validateSubstr(tag, filters)); | ||
} | ||
|
||
module.exports = { | ||
getTags, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Lifted and tweaked from semantic-release because we follow how they bump their packages/dependencies. | ||
* https://github.com/semantic-release/semantic-release/blob/master/lib/utils.js | ||
*/ | ||
|
||
const { gt, lt, prerelease, rcompare } = require("semver"); | ||
|
||
/** | ||
* Get tag objects and convert them to a list of stringified versions. | ||
* @param {array} tags Tags as object list. | ||
* @returns {array} Tags as string list. | ||
* @internal | ||
*/ | ||
function tagsToVersions(tags) { | ||
if (!tags) return []; | ||
return tags.map(({ version }) => version); | ||
} | ||
|
||
/** | ||
* HOC that applies highest/lowest semver function. | ||
* @param {Function} predicate High order function to be called. | ||
* @param {string|undefined} version1 Version 1 to be compared with. | ||
* @param {string|undefined} version2 Version 2 to be compared with. | ||
* @returns {string|undefined} Highest or lowest version. | ||
* @internal | ||
*/ | ||
const _selectVersionBy = (predicate, version1, version2) => { | ||
if (predicate && version1 && version2) { | ||
return predicate(version1, version2) ? version1 : version2; | ||
} | ||
return version1 || version2; | ||
}; | ||
|
||
/** | ||
* Gets highest semver function binding gt to the HOC selectVersionBy. | ||
*/ | ||
const getHighestVersion = _selectVersionBy.bind(null, gt); | ||
|
||
/** | ||
* Gets lowest semver function binding gt to the HOC selectVersionBy. | ||
*/ | ||
const getLowestVersion = _selectVersionBy.bind(null, lt); | ||
|
||
/** | ||
* Retrieve the latest version from a list of versions. | ||
* @param {array} versions Versions as string list. | ||
* @param {bool|undefined} withPrerelease Prerelease flag. | ||
* @returns {string|undefined} Latest version. | ||
* @internal | ||
*/ | ||
function getLatestVersion(versions, withPrerelease) { | ||
return versions.filter((version) => withPrerelease || !prerelease(version)).sort(rcompare)[0]; | ||
} | ||
|
||
module.exports = { | ||
tagsToVersions, | ||
getHighestVersion, | ||
getLowestVersion, | ||
getLatestVersion, | ||
}; |
Oops, something went wrong.