@hubspot/npm-scripts 0.0.6-experimental.0 → 0.0.7-experimental.0
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 +5 -0
- package/package.json +1 -1
- package/src/__tests__/release.test.js +2 -2
- package/src/release/__tests__/steps.test.d.ts +1 -0
- package/src/release/__tests__/steps.test.js +382 -0
- package/src/release/__tests__/validate.test.d.ts +1 -0
- package/src/release/__tests__/validate.test.js +148 -0
- package/src/release/__tests__/version.test.d.ts +1 -0
- package/src/release/__tests__/version.test.js +104 -0
- package/src/release/errors.d.ts +4 -0
- package/src/release/errors.js +9 -0
- package/src/release/steps.d.ts +11 -0
- package/src/release/steps.js +159 -0
- package/src/release/types.d.ts +80 -0
- package/src/release/types.js +1 -0
- package/src/release/validate.d.ts +6 -0
- package/src/release/validate.js +33 -0
- package/src/release/version.d.ts +2 -0
- package/src/release/version.js +23 -0
- package/src/release.d.ts +1 -1
- package/src/release.js +98 -187
- package/src/utils/__tests__/git.test.js +4 -3
- package/src/utils/__tests__/npm.test.js +11 -31
- package/src/utils/git.js +2 -2
- package/src/utils/npm.d.ts +4 -4
- package/src/utils/npm.js +7 -17
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { computeNewVersion } from '../version.js';
|
|
3
|
+
import { ReleaseError } from '../errors.js';
|
|
4
|
+
import { TAG, INCREMENT } from '../../constants/release.js';
|
|
5
|
+
const DIST_TAGS = {
|
|
6
|
+
latest: '1.0.0',
|
|
7
|
+
next: '1.0.0-beta.1',
|
|
8
|
+
experimental: '1.0.0-experimental.1',
|
|
9
|
+
previous: '0.9.0',
|
|
10
|
+
};
|
|
11
|
+
describe('release/version', () => {
|
|
12
|
+
describe('computeNewVersion', () => {
|
|
13
|
+
it('should return 1.0.1-beta.0 for next tag with patch increment', () => {
|
|
14
|
+
expect(computeNewVersion({
|
|
15
|
+
tag: TAG.NEXT,
|
|
16
|
+
versionIncrement: INCREMENT.PATCH,
|
|
17
|
+
isExperimental: false,
|
|
18
|
+
distTags: DIST_TAGS,
|
|
19
|
+
localVersion: '1.0.0-beta.1',
|
|
20
|
+
})).toBe('1.0.1-beta.0');
|
|
21
|
+
});
|
|
22
|
+
it('should return 1.1.0-beta.0 for next tag with minor increment', () => {
|
|
23
|
+
expect(computeNewVersion({
|
|
24
|
+
tag: TAG.NEXT,
|
|
25
|
+
versionIncrement: INCREMENT.MINOR,
|
|
26
|
+
isExperimental: false,
|
|
27
|
+
distTags: DIST_TAGS,
|
|
28
|
+
localVersion: '1.0.0-beta.1',
|
|
29
|
+
})).toBe('1.1.0-beta.0');
|
|
30
|
+
});
|
|
31
|
+
it('should return 2.0.0-beta.0 for next tag with major increment', () => {
|
|
32
|
+
expect(computeNewVersion({
|
|
33
|
+
tag: TAG.NEXT,
|
|
34
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
35
|
+
isExperimental: false,
|
|
36
|
+
distTags: DIST_TAGS,
|
|
37
|
+
localVersion: '1.0.0-beta.1',
|
|
38
|
+
})).toBe('2.0.0-beta.0');
|
|
39
|
+
});
|
|
40
|
+
it('should return 1.0.0-beta.2 for next tag with prerelease increment', () => {
|
|
41
|
+
expect(computeNewVersion({
|
|
42
|
+
tag: TAG.NEXT,
|
|
43
|
+
versionIncrement: INCREMENT.PRERELEASE,
|
|
44
|
+
isExperimental: false,
|
|
45
|
+
distTags: DIST_TAGS,
|
|
46
|
+
localVersion: '1.0.0-beta.1',
|
|
47
|
+
})).toBe('1.0.0-beta.2');
|
|
48
|
+
});
|
|
49
|
+
it('should return 1.0.1 for latest tag with patch increment', () => {
|
|
50
|
+
expect(computeNewVersion({
|
|
51
|
+
tag: TAG.LATEST,
|
|
52
|
+
versionIncrement: INCREMENT.PATCH,
|
|
53
|
+
isExperimental: false,
|
|
54
|
+
distTags: DIST_TAGS,
|
|
55
|
+
localVersion: '1.0.0',
|
|
56
|
+
})).toBe('1.0.1');
|
|
57
|
+
});
|
|
58
|
+
it('should return 1.1.0 for latest tag with minor increment', () => {
|
|
59
|
+
expect(computeNewVersion({
|
|
60
|
+
tag: TAG.LATEST,
|
|
61
|
+
versionIncrement: INCREMENT.MINOR,
|
|
62
|
+
isExperimental: false,
|
|
63
|
+
distTags: DIST_TAGS,
|
|
64
|
+
localVersion: '1.0.0',
|
|
65
|
+
})).toBe('1.1.0');
|
|
66
|
+
});
|
|
67
|
+
it('should return 2.0.0 for latest tag with major increment', () => {
|
|
68
|
+
expect(computeNewVersion({
|
|
69
|
+
tag: TAG.LATEST,
|
|
70
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
71
|
+
isExperimental: false,
|
|
72
|
+
distTags: DIST_TAGS,
|
|
73
|
+
localVersion: '1.0.0',
|
|
74
|
+
})).toBe('2.0.0');
|
|
75
|
+
});
|
|
76
|
+
it('should return 0.9.1 for previous tag with patch increment', () => {
|
|
77
|
+
expect(computeNewVersion({
|
|
78
|
+
tag: TAG.PREVIOUS,
|
|
79
|
+
versionIncrement: INCREMENT.PATCH,
|
|
80
|
+
isExperimental: false,
|
|
81
|
+
distTags: DIST_TAGS,
|
|
82
|
+
localVersion: '0.9.0',
|
|
83
|
+
})).toBe('0.9.1');
|
|
84
|
+
});
|
|
85
|
+
it('should return 1.0.0-experimental.2 for experimental tag with prerelease increment', () => {
|
|
86
|
+
expect(computeNewVersion({
|
|
87
|
+
tag: TAG.EXPERIMENTAL,
|
|
88
|
+
versionIncrement: INCREMENT.PRERELEASE,
|
|
89
|
+
isExperimental: true,
|
|
90
|
+
distTags: DIST_TAGS,
|
|
91
|
+
localVersion: '1.0.0-beta.1',
|
|
92
|
+
})).toBe('1.0.0-experimental.2');
|
|
93
|
+
});
|
|
94
|
+
it('should throw ReleaseError when semver cannot parse the version', () => {
|
|
95
|
+
expect(() => computeNewVersion({
|
|
96
|
+
tag: TAG.LATEST,
|
|
97
|
+
versionIncrement: INCREMENT.PATCH,
|
|
98
|
+
isExperimental: false,
|
|
99
|
+
distTags: DIST_TAGS,
|
|
100
|
+
localVersion: 'not-a-version',
|
|
101
|
+
})).toThrow(ReleaseError);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ConfirmReleaseOptions, TryBuildOptions, TryPublishOptions, UpdateDistTagsOptions, FinalizeReleaseOptions, LogReleaseSuccessOptions } from './types.js';
|
|
2
|
+
export declare function confirmRelease({ isDryRun, currentVersion, newVersion, tag, localVersion, versionIncrement, }: ConfirmReleaseOptions): Promise<void>;
|
|
3
|
+
export declare function runBuild(build?: () => Promise<void> | void): Promise<void>;
|
|
4
|
+
export declare function createTempBranch(branch: string, mainBranch: string, previousBranch: string | undefined, isDryRun: boolean, tempBranch: string): Promise<void>;
|
|
5
|
+
export declare function bumpVersion(newVersion: string, isExperimental: boolean): Promise<void>;
|
|
6
|
+
export declare function tryBuild({ build, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }: TryBuildOptions): Promise<void>;
|
|
7
|
+
export declare function ensureNpmAuth(isDryRun: boolean, registry: string): Promise<void>;
|
|
8
|
+
export declare function tryPublish({ tag, isDryRun, ignoreScripts, registry, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }: TryPublishOptions): Promise<void>;
|
|
9
|
+
export declare function updateDistTagsForLatest({ tag, versionIncrement, packageName, newVersion, currentLatestTag, isDryRun, registry, tempBranch, }: UpdateDistTagsOptions): Promise<void>;
|
|
10
|
+
export declare function finalizeRelease({ isDryRun, isExperimental, newVersion, localVersion, tempBranch, isPrevious, previousBranch, mainBranch, repositoryUrl, }: FinalizeReleaseOptions): Promise<void>;
|
|
11
|
+
export declare function logReleaseSuccess({ packageName, newVersion, tag, repositoryUrl, isDryRun, postLatestRelease, }: LogReleaseSuccessOptions): Promise<void>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { exec as _exec, execSync } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import open from 'open';
|
|
4
|
+
import { logger } from '../utils/logging.js';
|
|
5
|
+
import { EXIT_CODES } from '../utils/process.js';
|
|
6
|
+
import { gitCleanup } from '../utils/git.js';
|
|
7
|
+
import { publish, updateNextTag, updatePreviousTag, } from '../utils/npm.js';
|
|
8
|
+
import { confirm } from '../utils/prompting.js';
|
|
9
|
+
import { TAG, INCREMENT, PRERELEASE_IDENTIFIER } from '../constants/release.js';
|
|
10
|
+
import { ReleaseError } from './errors.js';
|
|
11
|
+
const exec = promisify(_exec);
|
|
12
|
+
export async function confirmRelease({ isDryRun, currentVersion, newVersion, tag, localVersion, versionIncrement, }) {
|
|
13
|
+
if (isDryRun) {
|
|
14
|
+
logger.log('\nDRY RUN');
|
|
15
|
+
}
|
|
16
|
+
logger.log(`\nCurrent version: ${currentVersion}`);
|
|
17
|
+
logger.log(`New version to release: ${newVersion}`);
|
|
18
|
+
const shouldRelease = await confirm({
|
|
19
|
+
message: `Release version ${newVersion} on tag ${tag}?`,
|
|
20
|
+
});
|
|
21
|
+
if (!shouldRelease) {
|
|
22
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
23
|
+
}
|
|
24
|
+
if (tag !== TAG.LATEST ||
|
|
25
|
+
localVersion.includes(PRERELEASE_IDENTIFIER.NEXT)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const proceed = await confirm({
|
|
29
|
+
message: `The current changes have not yet been released in beta. It's recommended to release and test all changes on the ${TAG.NEXT} tag before releasing them to ${TAG.LATEST}. Are you sure you want to proceed?`,
|
|
30
|
+
default: false,
|
|
31
|
+
});
|
|
32
|
+
if (!proceed) {
|
|
33
|
+
logger.log(`\nTo release your changes on the next tag, run \`yarn release -v=${versionIncrement} -t=next\``);
|
|
34
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function runBuild(build) {
|
|
38
|
+
if (build && typeof build === 'function') {
|
|
39
|
+
await build();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
logger.log('Installing dependencies...');
|
|
43
|
+
await exec('yarn');
|
|
44
|
+
logger.log('Building...');
|
|
45
|
+
await exec('yarn build');
|
|
46
|
+
}
|
|
47
|
+
export async function createTempBranch(branch, mainBranch, previousBranch, isDryRun, tempBranch) {
|
|
48
|
+
if ((branch !== mainBranch && branch !== previousBranch) || isDryRun) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
|
|
52
|
+
await exec(`git checkout -b ${tempBranch}`);
|
|
53
|
+
}
|
|
54
|
+
export async function bumpVersion(newVersion, isExperimental) {
|
|
55
|
+
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
56
|
+
if (isExperimental) {
|
|
57
|
+
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await exec(`yarn version --new-version ${newVersion}`);
|
|
61
|
+
}
|
|
62
|
+
logger.success('Version updated successfully \n');
|
|
63
|
+
}
|
|
64
|
+
export async function tryBuild({ build, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }) {
|
|
65
|
+
try {
|
|
66
|
+
await runBuild(build);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
logger.error(e);
|
|
70
|
+
logger.error('Build failed. Cleaning up...');
|
|
71
|
+
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? originalBranch : undefined);
|
|
72
|
+
throw new ReleaseError('');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function ensureNpmAuth(isDryRun, registry) {
|
|
76
|
+
if (isDryRun) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await exec(`npm whoami --registry ${registry}`);
|
|
81
|
+
}
|
|
82
|
+
catch (_err) {
|
|
83
|
+
try {
|
|
84
|
+
execSync(`npm adduser --registry ${registry}`, { stdio: 'inherit' });
|
|
85
|
+
}
|
|
86
|
+
catch (_authErr) {
|
|
87
|
+
throw new ReleaseError('Failed to authenticate with npm');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export async function tryPublish({ tag, isDryRun, ignoreScripts, registry, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }) {
|
|
92
|
+
try {
|
|
93
|
+
await publish(tag, isDryRun, ignoreScripts, registry);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
logger.error(e);
|
|
97
|
+
logger.error('An error occurred while releasing this package. Correct the error and re-run `yarn build`.');
|
|
98
|
+
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? originalBranch : undefined);
|
|
99
|
+
// already logged above — throw with empty message so the handler doesn't double-log
|
|
100
|
+
throw new ReleaseError('');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export async function updateDistTagsForLatest({ tag, versionIncrement, packageName, newVersion, currentLatestTag, isDryRun, registry, tempBranch, }) {
|
|
104
|
+
if (tag !== TAG.LATEST) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
108
|
+
try {
|
|
109
|
+
await updateNextTag(packageName, newVersion, isDryRun, registry);
|
|
110
|
+
}
|
|
111
|
+
catch (_e) {
|
|
112
|
+
logger.error(`An error occurred while updating the ${TAG.NEXT} tag. To finish this release, run the following commands:`);
|
|
113
|
+
logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
|
|
114
|
+
logger.log(gitCommand);
|
|
115
|
+
}
|
|
116
|
+
if (versionIncrement !== INCREMENT.MAJOR) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await updatePreviousTag(packageName, currentLatestTag, isDryRun, registry);
|
|
121
|
+
}
|
|
122
|
+
catch (_e) {
|
|
123
|
+
logger.error(`An error occurred while updating the ${TAG.PREVIOUS} tag. To finish this release, run the following command:`);
|
|
124
|
+
logger.log(`npm dist-tag add ${packageName}@${currentLatestTag} ${TAG.PREVIOUS}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function finalizeRelease({ isDryRun, isExperimental, newVersion, localVersion, tempBranch, isPrevious, previousBranch, mainBranch, repositoryUrl, }) {
|
|
128
|
+
if (isDryRun) {
|
|
129
|
+
await gitCleanup(newVersion, !isExperimental);
|
|
130
|
+
logger.log(`\nDry run: skipping push to Github`);
|
|
131
|
+
logger.log('Dry run release finished successfully');
|
|
132
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
133
|
+
}
|
|
134
|
+
if (isExperimental) {
|
|
135
|
+
logger.log(`\nExperimental release: Skipping push to Github`);
|
|
136
|
+
await exec(`yarn version --no-git-tag-version --new-version ${localVersion}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
140
|
+
logger.log(`\nPushing changes to Github...`);
|
|
141
|
+
await exec(gitCommand);
|
|
142
|
+
logger.log(`Changes pushed successfully`);
|
|
143
|
+
const baseBranch = isPrevious ? previousBranch : mainBranch;
|
|
144
|
+
await open(`${repositoryUrl}/compare/${baseBranch}...${tempBranch}`);
|
|
145
|
+
}
|
|
146
|
+
export async function logReleaseSuccess({ packageName, newVersion, tag, repositoryUrl, isDryRun, postLatestRelease, }) {
|
|
147
|
+
logger.success(`${packageName} version ${newVersion} published successfully`);
|
|
148
|
+
logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
|
|
149
|
+
if (tag !== TAG.LATEST && tag !== TAG.PREVIOUS) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
logger.log(`\nRemember to create a new release on Github!`);
|
|
153
|
+
await open(`${repositoryUrl}/releases/new`);
|
|
154
|
+
if (tag === TAG.LATEST &&
|
|
155
|
+
postLatestRelease &&
|
|
156
|
+
typeof postLatestRelease === 'function') {
|
|
157
|
+
await postLatestRelease({ newVersion, dryRun: isDryRun });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DistTags, Tag } from '../types.js';
|
|
2
|
+
export type BranchValidationOptions = {
|
|
3
|
+
isExperimental: boolean;
|
|
4
|
+
isPrevious: boolean;
|
|
5
|
+
branch: string;
|
|
6
|
+
mainBranch: string;
|
|
7
|
+
previousBranch?: string;
|
|
8
|
+
};
|
|
9
|
+
export type VersionSyncOptions = {
|
|
10
|
+
isExperimental: boolean;
|
|
11
|
+
isPrevious: boolean;
|
|
12
|
+
localVersion: string;
|
|
13
|
+
distTags: DistTags;
|
|
14
|
+
};
|
|
15
|
+
export type ComputeNewVersionOptions = {
|
|
16
|
+
tag: Tag;
|
|
17
|
+
versionIncrement: string;
|
|
18
|
+
isExperimental: boolean;
|
|
19
|
+
distTags: DistTags;
|
|
20
|
+
localVersion: string;
|
|
21
|
+
};
|
|
22
|
+
export type ConfirmReleaseOptions = {
|
|
23
|
+
isDryRun: boolean;
|
|
24
|
+
currentVersion: string;
|
|
25
|
+
newVersion: string;
|
|
26
|
+
tag: Tag;
|
|
27
|
+
localVersion: string;
|
|
28
|
+
versionIncrement: string;
|
|
29
|
+
};
|
|
30
|
+
export type TryBuildOptions = {
|
|
31
|
+
build?: () => Promise<void> | void;
|
|
32
|
+
newVersion: string;
|
|
33
|
+
isExperimental: boolean;
|
|
34
|
+
onTempBranch: boolean;
|
|
35
|
+
tempBranch: string;
|
|
36
|
+
originalBranch: string;
|
|
37
|
+
};
|
|
38
|
+
export type TryPublishOptions = {
|
|
39
|
+
tag: Tag;
|
|
40
|
+
isDryRun: boolean;
|
|
41
|
+
ignoreScripts: boolean;
|
|
42
|
+
registry: string;
|
|
43
|
+
newVersion: string;
|
|
44
|
+
isExperimental: boolean;
|
|
45
|
+
onTempBranch: boolean;
|
|
46
|
+
tempBranch: string;
|
|
47
|
+
originalBranch: string;
|
|
48
|
+
};
|
|
49
|
+
export type UpdateDistTagsOptions = {
|
|
50
|
+
tag: Tag;
|
|
51
|
+
versionIncrement: string;
|
|
52
|
+
packageName: string;
|
|
53
|
+
newVersion: string;
|
|
54
|
+
currentLatestTag: string;
|
|
55
|
+
isDryRun: boolean;
|
|
56
|
+
registry: string;
|
|
57
|
+
tempBranch: string;
|
|
58
|
+
};
|
|
59
|
+
export type FinalizeReleaseOptions = {
|
|
60
|
+
isDryRun: boolean;
|
|
61
|
+
isExperimental: boolean;
|
|
62
|
+
newVersion: string;
|
|
63
|
+
localVersion: string;
|
|
64
|
+
tempBranch: string;
|
|
65
|
+
isPrevious: boolean;
|
|
66
|
+
previousBranch?: string;
|
|
67
|
+
mainBranch: string;
|
|
68
|
+
repositoryUrl: string;
|
|
69
|
+
};
|
|
70
|
+
export type LogReleaseSuccessOptions = {
|
|
71
|
+
packageName: string;
|
|
72
|
+
newVersion: string;
|
|
73
|
+
tag: Tag;
|
|
74
|
+
repositoryUrl: string;
|
|
75
|
+
isDryRun: boolean;
|
|
76
|
+
postLatestRelease?: (options: {
|
|
77
|
+
newVersion: string;
|
|
78
|
+
dryRun: boolean;
|
|
79
|
+
}) => Promise<void> | void;
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Tag } from '../types.js';
|
|
2
|
+
import type { BranchValidationOptions, VersionSyncOptions } from './types.js';
|
|
3
|
+
export declare function validatePreviousBranchConfigured(isPrevious: boolean, previousBranch?: string): void;
|
|
4
|
+
export declare function validateBranchForTag({ isExperimental, isPrevious, branch, mainBranch, previousBranch, }: BranchValidationOptions): void;
|
|
5
|
+
export declare function validateTagIncrementCombination(tag: Tag, versionIncrement: string): void;
|
|
6
|
+
export declare function validateVersionSync({ isExperimental, isPrevious, localVersion, distTags, }: VersionSyncOptions): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TAG, INCREMENT } from '../constants/release.js';
|
|
2
|
+
import { ReleaseError } from './errors.js';
|
|
3
|
+
export function validatePreviousBranchConfigured(isPrevious, previousBranch) {
|
|
4
|
+
if (!isPrevious || previousBranch) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
throw new ReleaseError('Cannot release to previous tag: previousBranch is not configured');
|
|
8
|
+
}
|
|
9
|
+
export function validateBranchForTag({ isExperimental, isPrevious, branch, mainBranch, previousBranch, }) {
|
|
10
|
+
if (isExperimental && (branch === mainBranch || branch === previousBranch)) {
|
|
11
|
+
throw new ReleaseError(`Releases to experimental tag cannot be published from the ${branch} branch`);
|
|
12
|
+
}
|
|
13
|
+
else if (isPrevious && branch !== previousBranch) {
|
|
14
|
+
throw new ReleaseError(`Releases to previous tag can only be published from the ${previousBranch} branch`);
|
|
15
|
+
}
|
|
16
|
+
else if (!isExperimental && !isPrevious && branch !== mainBranch) {
|
|
17
|
+
throw new ReleaseError(`Releases to latest and next tags can only be published from the ${mainBranch} branch`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function validateTagIncrementCombination(tag, versionIncrement) {
|
|
21
|
+
if ((tag === TAG.LATEST || tag === TAG.PREVIOUS) &&
|
|
22
|
+
versionIncrement === INCREMENT.PRERELEASE) {
|
|
23
|
+
throw new ReleaseError(`Invalid release: cannot increment prerelease number on ${tag} tag.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function validateVersionSync({ isExperimental, isPrevious, localVersion, distTags, }) {
|
|
27
|
+
if (!isExperimental && !isPrevious && distTags.next !== localVersion) {
|
|
28
|
+
throw new ReleaseError(`Local package.json version ${localVersion} is out of sync with published version ${distTags.next}`);
|
|
29
|
+
}
|
|
30
|
+
if (isPrevious && distTags.previous !== localVersion) {
|
|
31
|
+
throw new ReleaseError(`Local package.json version ${localVersion} is out of sync with published version ${distTags.previous}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { TAG, INCREMENT, PRERELEASE_IDENTIFIER } from '../constants/release.js';
|
|
3
|
+
import { ReleaseError } from './errors.js';
|
|
4
|
+
function computeIncrementType(tag, versionIncrement) {
|
|
5
|
+
if (tag === TAG.LATEST ||
|
|
6
|
+
tag === TAG.PREVIOUS ||
|
|
7
|
+
versionIncrement === INCREMENT.PRERELEASE) {
|
|
8
|
+
return versionIncrement;
|
|
9
|
+
}
|
|
10
|
+
return `pre${versionIncrement}`;
|
|
11
|
+
}
|
|
12
|
+
export function computeNewVersion({ tag, versionIncrement, isExperimental, distTags, localVersion, }) {
|
|
13
|
+
const currentVersion = isExperimental ? distTags.experimental : localVersion;
|
|
14
|
+
const prereleaseIdentifier = isExperimental
|
|
15
|
+
? PRERELEASE_IDENTIFIER.EXPERIMENTAL
|
|
16
|
+
: PRERELEASE_IDENTIFIER.NEXT;
|
|
17
|
+
const incrementType = computeIncrementType(tag, versionIncrement);
|
|
18
|
+
const newVersion = semver.inc(currentVersion, incrementType, prereleaseIdentifier);
|
|
19
|
+
if (!newVersion) {
|
|
20
|
+
throw new ReleaseError('Error incrementing version.');
|
|
21
|
+
}
|
|
22
|
+
return newVersion;
|
|
23
|
+
}
|
package/src/release.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildReleaseScriptBase } from './types.js';
|
|
1
|
+
import type { BuildReleaseScriptBase } from './types.js';
|
|
2
2
|
export declare function buildReleaseScript({ packageJsonLocation, buildHandlerOptions, }: {
|
|
3
3
|
packageJsonLocation: string;
|
|
4
4
|
buildHandlerOptions: BuildReleaseScriptBase;
|