autorel 2.2.12 → 2.2.13-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.js +32 -18
- package/dist/lib/git.d.ts +4 -13
- package/dist/lib/git.js +12 -18
- package/dist/semver.d.ts +47 -11
- package/dist/semver.js +137 -164
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -113,11 +113,11 @@ Example: `npx autorel@^2`
|
|
|
113
113
|
|
|
114
114
|
Commit messages are parsed to determine the version bump. They must follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard specification.
|
|
115
115
|
|
|
116
|
-
Here are some examples of commit messages and the resulting [SemVer](https://semver.org) version bump (with default configuration):
|
|
116
|
+
Here are some examples of commit messages and the resulting [SemVer](https://semver.org) version bump (with the default configuration):
|
|
117
117
|
|
|
118
|
-
- `fix: fix a bug` -> `0.0.1`
|
|
119
|
-
- `feat: add new feature` -> `0.1.0`
|
|
120
|
-
- `feat!: add breaking change` -> `1.0.0`
|
|
118
|
+
- `fix: fix a bug` -> `0.0.1` (patch)
|
|
119
|
+
- `feat: add new feature` -> `0.1.0` (minor)
|
|
120
|
+
- `feat!: add breaking change` -> `1.0.0` (major)
|
|
121
121
|
|
|
122
122
|
You can find more examples in the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) documentation.
|
|
123
123
|
|
package/dist/index.js
CHANGED
|
@@ -43,9 +43,9 @@ function getPrereleaseChannel(config) {
|
|
|
43
43
|
return config.prereleaseChannel;
|
|
44
44
|
const branch = git.getCurrentBranch();
|
|
45
45
|
if (!branch)
|
|
46
|
-
throw new Error('Could not get the current branch.');
|
|
46
|
+
throw new Error('Could not get the current branch. Please make sure you are in a git repository.');
|
|
47
47
|
if (!config.branches || !config.branches.length)
|
|
48
|
-
throw new Error('Branches are not defined in the configuration.');
|
|
48
|
+
throw new Error('Branches are not defined in the configuration. See https://github.com/mhweiner/autorel?tab=readme-ov-file#configuration');
|
|
49
49
|
const matchingBranch = config.branches.find((b) => b.name === branch);
|
|
50
50
|
if (!matchingBranch)
|
|
51
51
|
return undefined;
|
|
@@ -57,13 +57,6 @@ async function autorel(args) {
|
|
|
57
57
|
if (args.dryRun) {
|
|
58
58
|
output_1.default.warn('Running in dry-run mode. No changes will be made.');
|
|
59
59
|
}
|
|
60
|
-
const commitTypeMap = new Map(args.commitTypes.map((type) => [type.type, type]));
|
|
61
|
-
// fetch latest tags
|
|
62
|
-
git.gitFetchTags();
|
|
63
|
-
const lastTag = git.getLastTag();
|
|
64
|
-
const lastProdTag = git.getLastProdTag();
|
|
65
|
-
output_1.default.log(`The last tag is: ${lastTag ? color.bold(lastTag) : color.grey('none')}`);
|
|
66
|
-
output_1.default.log(`The last production tag is: ${lastProdTag ? color.bold(lastProdTag) : color.grey('none')}`);
|
|
67
60
|
if (prereleaseChannel && !args.useVersion) {
|
|
68
61
|
const stmt = `Using prerelease channel: ${color.bold(prereleaseChannel)}`;
|
|
69
62
|
output_1.default.log(!args.useVersion ? stmt : color.strikethrough(stmt));
|
|
@@ -72,13 +65,28 @@ async function autorel(args) {
|
|
|
72
65
|
const stmt = 'This is a production release.';
|
|
73
66
|
output_1.default.log(!args.useVersion ? stmt : color.strikethrough(stmt));
|
|
74
67
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
const commitTypeMap = new Map(args.commitTypes.map((type) => [type.type, type]));
|
|
69
|
+
git.gitFetchTags(); // fetch latest tags from remote
|
|
70
|
+
const lastChannelTag = prereleaseChannel ? git.getLastChannelTag(prereleaseChannel) : undefined;
|
|
71
|
+
const lastStableTag = git.getLastStableTag();
|
|
72
|
+
const highestTag = git.getHighestTag();
|
|
73
|
+
// validate tags if they exist
|
|
74
|
+
if (lastChannelTag && !semver.isValidTag(lastChannelTag))
|
|
75
|
+
throw new Error(`Invalid last channel tag: ${lastChannelTag}`);
|
|
76
|
+
if (lastStableTag && !semver.isValidTag(lastStableTag))
|
|
77
|
+
throw new Error(`Invalid last stable tag: ${lastStableTag}`);
|
|
78
|
+
if (highestTag && !semver.isValidTag(highestTag))
|
|
79
|
+
throw new Error(`Invalid highest tag: ${highestTag}`);
|
|
80
|
+
if (lastChannelTag && !highestTag)
|
|
81
|
+
throw new Error('Last channel tag exists, but highest tag does not.');
|
|
82
|
+
const tagFromWhichToFindCommits = prereleaseChannel && lastChannelTag
|
|
83
|
+
? semver.highestVersion(semver.fromTag(lastChannelTag), semver.fromTag(lastStableTag ?? 'v0.0.0'))
|
|
84
|
+
: lastStableTag;
|
|
85
|
+
!!lastChannelTag && output_1.default.log(`The last pre-release channel version (${prereleaseChannel}) is: ${color.bold(lastChannelTag)}`);
|
|
86
|
+
output_1.default.log(`The last stable/production version is: ${lastStableTag ? color.bold(lastStableTag) : color.grey('none')}`);
|
|
87
|
+
output_1.default.log(`The current/highest version is: ${highestTag ? color.bold(highestTag) : color.grey('none')}`);
|
|
88
|
+
output_1.default.log(`Fetching commits since ${tagFromWhichToFindCommits || 'the beginning of the repository'}...`);
|
|
89
|
+
const commits = git.getCommitsSinceLastTag(prereleaseChannel ? lastChannelTag : lastStableTag);
|
|
82
90
|
output_1.default.log(`Found ${color.bold(commits.length.toString())} commit(s).`);
|
|
83
91
|
const parsedCommits = commits.map((commit) => convCom.parseConventionalCommit(commit.message, commit.hash))
|
|
84
92
|
.filter((commit) => !!commit);
|
|
@@ -96,7 +104,7 @@ async function autorel(args) {
|
|
|
96
104
|
if (args.useVersion) {
|
|
97
105
|
if (/^v(.+)$/.test(args.useVersion))
|
|
98
106
|
throw new Error('useVersion should not start with a "v".');
|
|
99
|
-
if (!semver.
|
|
107
|
+
if (!semver.isValidTag(args.useVersion))
|
|
100
108
|
throw new Error('useVersion must be a valid SemVer version');
|
|
101
109
|
if (releaseType === 'none') {
|
|
102
110
|
output_1.default.warn(`We didn't find any commmits that would create a release, but you have set 'useVersion', which will force a release as: ${color.bold(args.useVersion)}.`);
|
|
@@ -106,7 +114,13 @@ async function autorel(args) {
|
|
|
106
114
|
}
|
|
107
115
|
}
|
|
108
116
|
else {
|
|
109
|
-
nextTagCalculated = semver.
|
|
117
|
+
nextTagCalculated = semver.toTag(semver.incrVer({
|
|
118
|
+
highestVer: semver.fromTag(highestTag || 'v0.0.0'),
|
|
119
|
+
lastStableVer: semver.fromTag(lastStableTag || 'v0.0.0'),
|
|
120
|
+
releaseType,
|
|
121
|
+
prereleaseChannel,
|
|
122
|
+
lastChannelVer: lastChannelTag ? semver.fromTag(lastChannelTag) ?? undefined : undefined,
|
|
123
|
+
}));
|
|
110
124
|
output_1.default.log(`The next version is: ${color.bold(nextTagCalculated)}`);
|
|
111
125
|
}
|
|
112
126
|
const nextTag = args.useVersion ? `v${args.useVersion}` : nextTagCalculated;
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -4,21 +4,12 @@ export type Commit = {
|
|
|
4
4
|
};
|
|
5
5
|
export declare function gitFetchTags(): void;
|
|
6
6
|
export declare function createAndPushTag(tag: string): void;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* 2. Filtering out tags that are not in the format v1.2.3
|
|
11
|
-
* 3. Sorting the tags by version number by tricking the sort -V command by appending an
|
|
12
|
-
* underscore to tags that do not have a hyphen in them (i.e. they are not pre-release tags)
|
|
13
|
-
* Thanks to this StackOverflow answer: https://stackoverflow.com/questions/40390957/how-to-sort-semantic-versions-in-bash
|
|
14
|
-
* 4. Removing the underscore from the sorted tags
|
|
15
|
-
* 5. Getting the last tag
|
|
16
|
-
*/
|
|
17
|
-
export declare function getLastTag(): string;
|
|
18
|
-
export declare function getLastProdTag(): string;
|
|
7
|
+
export declare function getLastChannelTag(channel: string): string | undefined;
|
|
8
|
+
export declare function getHighestTag(): string | undefined;
|
|
9
|
+
export declare function getLastStableTag(): string | undefined;
|
|
19
10
|
export declare function getRepo(): {
|
|
20
11
|
owner: string;
|
|
21
12
|
repository: string;
|
|
22
13
|
};
|
|
23
|
-
export declare function getCommitsSinceLastTag(lastTag
|
|
14
|
+
export declare function getCommitsSinceLastTag(lastTag?: string): Commit[];
|
|
24
15
|
export declare function getCurrentBranch(): string;
|
package/dist/lib/git.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentBranch = exports.getCommitsSinceLastTag = exports.getRepo = exports.
|
|
3
|
+
exports.getCurrentBranch = exports.getCommitsSinceLastTag = exports.getRepo = exports.getLastStableTag = exports.getHighestTag = exports.getLastChannelTag = exports.createAndPushTag = exports.gitFetchTags = void 0;
|
|
4
4
|
const sh_1 = require("./sh");
|
|
5
5
|
function gitFetchTags() {
|
|
6
6
|
(0, sh_1.$) `git fetch`;
|
|
@@ -11,24 +11,18 @@ function createAndPushTag(tag) {
|
|
|
11
11
|
(0, sh_1.$) `git push origin ${tag}`;
|
|
12
12
|
}
|
|
13
13
|
exports.createAndPushTag = createAndPushTag;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* 1. Getting all tags
|
|
17
|
-
* 2. Filtering out tags that are not in the format v1.2.3
|
|
18
|
-
* 3. Sorting the tags by version number by tricking the sort -V command by appending an
|
|
19
|
-
* underscore to tags that do not have a hyphen in them (i.e. they are not pre-release tags)
|
|
20
|
-
* Thanks to this StackOverflow answer: https://stackoverflow.com/questions/40390957/how-to-sort-semantic-versions-in-bash
|
|
21
|
-
* 4. Removing the underscore from the sorted tags
|
|
22
|
-
* 5. Getting the last tag
|
|
23
|
-
*/
|
|
24
|
-
function getLastTag() {
|
|
25
|
-
return (0, sh_1.$) `git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | sed '/-/!s/$/_/' | sort -V | sed 's/_$//' | tail -n 1` || '';
|
|
14
|
+
function getLastChannelTag(channel) {
|
|
15
|
+
return (0, sh_1.$) `git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-${channel}\.[0-9]+$' | sort -V | tail -n 1` || undefined;
|
|
26
16
|
}
|
|
27
|
-
exports.
|
|
28
|
-
function
|
|
29
|
-
return (0, sh_1.$) `git tag --
|
|
17
|
+
exports.getLastChannelTag = getLastChannelTag;
|
|
18
|
+
function getHighestTag() {
|
|
19
|
+
return (0, sh_1.$) `git tag --sort=-v:refname | head -n1` || undefined;
|
|
30
20
|
}
|
|
31
|
-
exports.
|
|
21
|
+
exports.getHighestTag = getHighestTag;
|
|
22
|
+
function getLastStableTag() {
|
|
23
|
+
return (0, sh_1.$) `git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1` || undefined;
|
|
24
|
+
}
|
|
25
|
+
exports.getLastStableTag = getLastStableTag;
|
|
32
26
|
function getRepo() {
|
|
33
27
|
if (process.env.GITHUB_REPOSITORY) {
|
|
34
28
|
const [owner, repository] = process.env.GITHUB_REPOSITORY.split('/');
|
|
@@ -46,7 +40,7 @@ function getRepo() {
|
|
|
46
40
|
exports.getRepo = getRepo;
|
|
47
41
|
function getCommitsSinceLastTag(lastTag) {
|
|
48
42
|
const format = '<commit><hash>%h</hash><message>%B</message></commit>';
|
|
49
|
-
const rawLog = lastTag
|
|
43
|
+
const rawLog = lastTag
|
|
50
44
|
? (0, sh_1.$) `git log --pretty=format:"${format}" ${lastTag}..HEAD`
|
|
51
45
|
: (0, sh_1.$) `git log --pretty=format:"${format}"`;
|
|
52
46
|
const commitsXml = rawLog.match(/<commit>.*?<\/commit>/gs);
|
package/dist/semver.d.ts
CHANGED
|
@@ -1,17 +1,53 @@
|
|
|
1
|
-
type
|
|
1
|
+
export type SemVer = {
|
|
2
2
|
major: number;
|
|
3
3
|
minor: number;
|
|
4
4
|
patch: number;
|
|
5
5
|
channel?: string;
|
|
6
6
|
build?: number;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
export type ReleaseType = 'major' | 'minor' | 'patch' | 'none';
|
|
9
|
+
export declare function toTag(version: SemVer): string;
|
|
10
|
+
export declare function fromTag(tag: string): SemVer | null;
|
|
11
|
+
export declare function isVerPrerelease(version: SemVer): boolean;
|
|
12
|
+
export declare function normalize(version: SemVer): SemVer;
|
|
13
|
+
/**
|
|
14
|
+
* Compares two versions and returns:
|
|
15
|
+
* - 1 if version1 is greater than version2
|
|
16
|
+
* - -1 if version1 is less than version2
|
|
17
|
+
* - 0 if they are equal
|
|
18
|
+
*/
|
|
19
|
+
export declare function compareVersions(version1: SemVer, version2: SemVer): number;
|
|
20
|
+
export declare function rootVersion(version: SemVer): SemVer;
|
|
21
|
+
export declare function highestVersion(version1: SemVer, version2: SemVer): SemVer;
|
|
22
|
+
export declare function incrByType(version: SemVer, releaseType: ReleaseType): SemVer;
|
|
23
|
+
export declare function incrPatch(version: SemVer): SemVer;
|
|
24
|
+
export declare function incrMinor(version: SemVer): SemVer;
|
|
25
|
+
export declare function incrMajor(version: SemVer): SemVer;
|
|
26
|
+
export declare function isValidTag(ver: string): boolean;
|
|
27
|
+
export declare function isValidVersion(version: SemVer): boolean;
|
|
28
|
+
export declare const outOfOrderErr: string;
|
|
29
|
+
export declare const stableVerNotValid = "The stable version cannot be a prerelease.";
|
|
30
|
+
export declare const lastChannelVerNotSameChannel = "The last channel version must be a prerelease of the same channel.";
|
|
31
|
+
export declare const lastChannelVerTooLarge = "The last channel version cannot be greater than the highest version.";
|
|
32
|
+
/**
|
|
33
|
+
* Increments the version based on the release type. The next version must
|
|
34
|
+
* be greater than the highest/current version except for the following cases:
|
|
35
|
+
* 1. The release type is 'none'.
|
|
36
|
+
* 2. The highest version is a prerelease of a different channel. Even in this case,
|
|
37
|
+
* the next version must be greater than the last stable/production version.
|
|
38
|
+
*
|
|
39
|
+
* Parameters:
|
|
40
|
+
* - `highestVer` is typically the current version of the package and the
|
|
41
|
+
* same as `lastStableVer` if the last release was a stable/production release.
|
|
42
|
+
* - `lastStableVer` is the last stable/production release.
|
|
43
|
+
* - `releaseType` is the type of release to make.
|
|
44
|
+
* - `prereleaseChannel` is the name of the prerelease channel, if it's a prerelease.
|
|
45
|
+
* - `lastChannelVer` is the last version of the package on the same channel.
|
|
46
|
+
*/
|
|
47
|
+
export declare function incrVer(input: {
|
|
48
|
+
highestVer: SemVer;
|
|
49
|
+
lastStableVer: SemVer;
|
|
50
|
+
releaseType: ReleaseType;
|
|
51
|
+
prereleaseChannel?: string;
|
|
52
|
+
lastChannelVer?: SemVer;
|
|
53
|
+
}): SemVer;
|
package/dist/semver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidVersion = exports.
|
|
3
|
+
exports.incrVer = exports.lastChannelVerTooLarge = exports.lastChannelVerNotSameChannel = exports.stableVerNotValid = exports.outOfOrderErr = exports.isValidVersion = exports.isValidTag = exports.incrMajor = exports.incrMinor = exports.incrPatch = exports.incrByType = exports.highestVersion = exports.rootVersion = exports.compareVersions = exports.normalize = exports.isVerPrerelease = exports.fromTag = exports.toTag = void 0;
|
|
4
4
|
function toTag(version) {
|
|
5
5
|
let versionString = `${version.major}.${version.minor}.${version.patch}`;
|
|
6
6
|
if (version.channel) {
|
|
@@ -28,141 +28,91 @@ function fromTag(tag) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
exports.fromTag = fromTag;
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return toTag(lastVersion);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else if (!!channel && !!prereleaseChannel) {
|
|
92
|
-
// prerelease to prerelease
|
|
93
|
-
// ex: v1.0.1-alpha.1 -> v1.1.0-alpha.1
|
|
94
|
-
if (channel === prereleaseChannel) {
|
|
95
|
-
// same channel
|
|
96
|
-
// ex: v1.0.1-alpha.1 -> v1.0.1-alpha.2
|
|
97
|
-
if (releaseType === 'none')
|
|
98
|
-
return lastTag; // no changes
|
|
99
|
-
// increment the last production version by the release type
|
|
100
|
-
const lastProdVersionRootIncr = incrByType(lastProductionVersion, releaseType);
|
|
101
|
-
// get the base version of the last version for comparison
|
|
102
|
-
const lastVersionRoot = { major, minor, patch };
|
|
103
|
-
// take the highest version of nextVersionNaked and lastVersion
|
|
104
|
-
const nextVersionRoot = returnHighestVersion(lastProdVersionRootIncr, lastVersionRoot);
|
|
105
|
-
// if the version is the same, increment the build number
|
|
106
|
-
if (toTag(nextVersionRoot) === toTag(lastVersionRoot)) {
|
|
107
|
-
// increment build number
|
|
108
|
-
return toTag({
|
|
109
|
-
...nextVersionRoot,
|
|
110
|
-
channel,
|
|
111
|
-
build: build ? build + 1 : 1,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// it's a new version
|
|
116
|
-
return toTag({ ...nextVersionRoot, channel, build: 1 });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// different channel
|
|
121
|
-
// ex: v1.0.1-alpha.1 -> v1.0.1-beta.1
|
|
122
|
-
if (releaseType === 'none') {
|
|
123
|
-
// no changes but the channel is different
|
|
124
|
-
// ex: v1.0.1-alpha.1 -> v1.0.1-beta.1
|
|
125
|
-
return toTag({ ...lastVersion, channel: prereleaseChannel, build: 1 });
|
|
126
|
-
}
|
|
127
|
-
// increment the last production version by the release type
|
|
128
|
-
const lastProdVersionRootIncr = incrByType(lastProductionVersion, releaseType);
|
|
129
|
-
// get the base version of the last version for comparison
|
|
130
|
-
const lastVersionRoot = { major, minor, patch };
|
|
131
|
-
// take the highest version of nextVersionNaked and lastVersion
|
|
132
|
-
const nextVersionRoot = returnHighestVersion(lastProdVersionRootIncr, lastVersionRoot);
|
|
133
|
-
// if the version is the same, change channel and reset build number
|
|
134
|
-
if (toTag(nextVersionRoot) === toTag(lastVersionRoot)) {
|
|
135
|
-
return toTag({
|
|
136
|
-
...nextVersionRoot,
|
|
137
|
-
channel: prereleaseChannel,
|
|
138
|
-
build: 1,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// it's a new version
|
|
143
|
-
return toTag({ ...nextVersionRoot, channel: prereleaseChannel, build: 1 });
|
|
144
|
-
}
|
|
31
|
+
function isVerPrerelease(version) {
|
|
32
|
+
return !!version.channel;
|
|
33
|
+
}
|
|
34
|
+
exports.isVerPrerelease = isVerPrerelease;
|
|
35
|
+
function normalize(version) {
|
|
36
|
+
return {
|
|
37
|
+
major: version.major,
|
|
38
|
+
minor: version.minor,
|
|
39
|
+
patch: version.patch,
|
|
40
|
+
...(version.channel ? {
|
|
41
|
+
channel: version.channel,
|
|
42
|
+
build: version.build || 1,
|
|
43
|
+
} : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.normalize = normalize;
|
|
47
|
+
/**
|
|
48
|
+
* Compares two versions and returns:
|
|
49
|
+
* - 1 if version1 is greater than version2
|
|
50
|
+
* - -1 if version1 is less than version2
|
|
51
|
+
* - 0 if they are equal
|
|
52
|
+
*/
|
|
53
|
+
function compareVersions(version1, version2) {
|
|
54
|
+
const version1n = normalize(version1);
|
|
55
|
+
const version2n = normalize(version2);
|
|
56
|
+
if (version1n.major > version2n.major)
|
|
57
|
+
return 1;
|
|
58
|
+
if (version1n.major < version2n.major)
|
|
59
|
+
return -1;
|
|
60
|
+
if (version1n.minor > version2n.minor)
|
|
61
|
+
return 1;
|
|
62
|
+
if (version1n.minor < version2n.minor)
|
|
63
|
+
return -1;
|
|
64
|
+
if (version1n.patch > version2n.patch)
|
|
65
|
+
return 1;
|
|
66
|
+
if (version1n.patch < version2n.patch)
|
|
67
|
+
return -1;
|
|
68
|
+
if (!version1n.channel && !!version2n.channel)
|
|
69
|
+
return 1;
|
|
70
|
+
if (!!version1n.channel && !version2n.channel)
|
|
71
|
+
return -1;
|
|
72
|
+
if (!version1n.build && !!version2n.build)
|
|
73
|
+
return 1;
|
|
74
|
+
if (!!version1n.build && !version2n.build)
|
|
75
|
+
return -1;
|
|
76
|
+
// compare channel
|
|
77
|
+
if (version1n.channel && version2n.channel) {
|
|
78
|
+
if (version1n.channel > version2n.channel)
|
|
79
|
+
return 1;
|
|
80
|
+
if (version1n.channel < version2n.channel)
|
|
81
|
+
return -1;
|
|
82
|
+
// compare build
|
|
83
|
+
if (version1n.build && version2n.build) {
|
|
84
|
+
if (version1n.build > version2n.build)
|
|
85
|
+
return 1;
|
|
86
|
+
if (version1n.build < version2n.build)
|
|
87
|
+
return -1;
|
|
145
88
|
}
|
|
146
89
|
}
|
|
147
|
-
|
|
148
|
-
// prerelease to prod
|
|
149
|
-
// ex: v1.0.1-alpha.1 -> v1.0.1
|
|
150
|
-
return toTag({
|
|
151
|
-
major,
|
|
152
|
-
minor,
|
|
153
|
-
patch,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
90
|
+
return 0;
|
|
156
91
|
}
|
|
157
|
-
exports.
|
|
158
|
-
function
|
|
159
|
-
|
|
92
|
+
exports.compareVersions = compareVersions;
|
|
93
|
+
function rootVersion(version) {
|
|
94
|
+
return {
|
|
95
|
+
major: version.major,
|
|
96
|
+
minor: version.minor,
|
|
97
|
+
patch: version.patch,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.rootVersion = rootVersion;
|
|
101
|
+
function highestVersion(version1, version2) {
|
|
102
|
+
const comparison = compareVersions(version1, version2);
|
|
103
|
+
return normalize(comparison > 0 ? version1 : version2);
|
|
104
|
+
}
|
|
105
|
+
exports.highestVersion = highestVersion;
|
|
106
|
+
function incrByType(version, releaseType) {
|
|
107
|
+
switch (releaseType) {
|
|
160
108
|
case 'major':
|
|
161
109
|
return incrMajor(version);
|
|
162
110
|
case 'minor':
|
|
163
111
|
return incrMinor(version);
|
|
164
112
|
case 'patch':
|
|
165
113
|
return incrPatch(version);
|
|
114
|
+
default:
|
|
115
|
+
return version;
|
|
166
116
|
}
|
|
167
117
|
}
|
|
168
118
|
exports.incrByType = incrByType;
|
|
@@ -196,44 +146,67 @@ function incrMajor(version) {
|
|
|
196
146
|
};
|
|
197
147
|
}
|
|
198
148
|
exports.incrMajor = incrMajor;
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
return version1;
|
|
202
|
-
if (version1.major < version2.major)
|
|
203
|
-
return version2;
|
|
204
|
-
if (version1.minor > version2.minor)
|
|
205
|
-
return version1;
|
|
206
|
-
if (version1.minor < version2.minor)
|
|
207
|
-
return version2;
|
|
208
|
-
if (version1.patch > version2.patch)
|
|
209
|
-
return version1;
|
|
210
|
-
if (version1.patch < version2.patch)
|
|
211
|
-
return version2;
|
|
212
|
-
if (version1.channel && !version2.channel)
|
|
213
|
-
return version2;
|
|
214
|
-
if (!version1.channel && version2.channel)
|
|
215
|
-
return version1;
|
|
216
|
-
if (version1.channel && version2.channel) {
|
|
217
|
-
if (version1.channel > version2.channel)
|
|
218
|
-
return version1;
|
|
219
|
-
if (version1.channel < version2.channel)
|
|
220
|
-
return version2;
|
|
221
|
-
}
|
|
222
|
-
if (version1.build && !version2.build)
|
|
223
|
-
return version1;
|
|
224
|
-
if (!version1.build && version2.build)
|
|
225
|
-
return version2;
|
|
226
|
-
if (version1.build && version2.build) {
|
|
227
|
-
if (version1.build > version2.build)
|
|
228
|
-
return version1;
|
|
229
|
-
if (version1.build < version2.build)
|
|
230
|
-
return version2;
|
|
231
|
-
}
|
|
232
|
-
return version1;
|
|
149
|
+
function isValidTag(ver) {
|
|
150
|
+
return !!fromTag(ver);
|
|
233
151
|
}
|
|
234
|
-
exports.
|
|
235
|
-
function isValidVersion(
|
|
236
|
-
return !!fromTag(
|
|
152
|
+
exports.isValidTag = isValidTag;
|
|
153
|
+
function isValidVersion(version) {
|
|
154
|
+
return !!fromTag(toTag(version));
|
|
237
155
|
}
|
|
238
156
|
exports.isValidVersion = isValidVersion;
|
|
157
|
+
exports.outOfOrderErr = 'The current/highest version cannot be less than the last stable/production version (following SemVer).'
|
|
158
|
+
+ '\n\nTo fix this, we recommend using the --use-version flag to specify the version you want to use.';
|
|
159
|
+
exports.stableVerNotValid = 'The stable version cannot be a prerelease.';
|
|
160
|
+
exports.lastChannelVerNotSameChannel = 'The last channel version must be a prerelease of the same channel.';
|
|
161
|
+
exports.lastChannelVerTooLarge = 'The last channel version cannot be greater than the highest version.';
|
|
162
|
+
/**
|
|
163
|
+
* Increments the version based on the release type. The next version must
|
|
164
|
+
* be greater than the highest/current version except for the following cases:
|
|
165
|
+
* 1. The release type is 'none'.
|
|
166
|
+
* 2. The highest version is a prerelease of a different channel. Even in this case,
|
|
167
|
+
* the next version must be greater than the last stable/production version.
|
|
168
|
+
*
|
|
169
|
+
* Parameters:
|
|
170
|
+
* - `highestVer` is typically the current version of the package and the
|
|
171
|
+
* same as `lastStableVer` if the last release was a stable/production release.
|
|
172
|
+
* - `lastStableVer` is the last stable/production release.
|
|
173
|
+
* - `releaseType` is the type of release to make.
|
|
174
|
+
* - `prereleaseChannel` is the name of the prerelease channel, if it's a prerelease.
|
|
175
|
+
* - `lastChannelVer` is the last version of the package on the same channel.
|
|
176
|
+
*/
|
|
177
|
+
function incrVer(input) {
|
|
178
|
+
const { lastStableVer, highestVer, releaseType, prereleaseChannel, lastChannelVer } = input;
|
|
179
|
+
if (releaseType === 'none')
|
|
180
|
+
return highestVer;
|
|
181
|
+
if (compareVersions(highestVer, lastStableVer) < 0)
|
|
182
|
+
throw new Error(exports.outOfOrderErr);
|
|
183
|
+
if (isVerPrerelease(lastStableVer))
|
|
184
|
+
throw new Error(exports.stableVerNotValid);
|
|
185
|
+
if (prereleaseChannel && lastChannelVer && compareVersions(lastChannelVer, highestVer) > 0)
|
|
186
|
+
throw new Error(exports.lastChannelVerTooLarge);
|
|
187
|
+
if (prereleaseChannel && lastChannelVer && prereleaseChannel !== lastChannelVer.channel)
|
|
188
|
+
throw new Error(exports.lastChannelVerNotSameChannel);
|
|
189
|
+
const isPrerelease = !!prereleaseChannel;
|
|
190
|
+
const nextRootVer = highestVersion(incrByType(lastStableVer, releaseType), rootVersion(highestVer));
|
|
191
|
+
if (isPrerelease) {
|
|
192
|
+
const nextVer = {
|
|
193
|
+
...nextRootVer,
|
|
194
|
+
channel: prereleaseChannel,
|
|
195
|
+
build: 1,
|
|
196
|
+
};
|
|
197
|
+
if (!lastChannelVer || compareVersions(nextVer, lastChannelVer) > 0) {
|
|
198
|
+
return nextVer;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return {
|
|
202
|
+
...lastChannelVer,
|
|
203
|
+
build: (lastChannelVer.build || 0) + 1,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return nextRootVer;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.incrVer = incrVer;
|
|
239
212
|
//# sourceMappingURL=semver.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autorel",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.13-next.2",
|
|
4
4
|
"description": "Automate semantic releases based on conventional commits. Similar to semantic-release but much simpler.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc H. Weiner <mhweiner234@gmail.com> (https://mhweiner.com)",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"c8": "^7.10.0",
|
|
53
53
|
"cjs-mock": "^0.1.0",
|
|
54
54
|
"eslint": "^8.4.1",
|
|
55
|
-
"hoare": "
|
|
55
|
+
"hoare": "3.3.0",
|
|
56
56
|
"ts-node": "^10.4.0",
|
|
57
57
|
"typescript": "^4.5.4"
|
|
58
58
|
},
|