@hubspot/npm-scripts 0.3.1 → 0.3.3-beta.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 +9 -5
- package/src/release/__tests__/steps.test.d.ts +1 -0
- package/src/release/__tests__/steps.test.js +407 -0
- package/src/release/__tests__/validate.test.d.ts +1 -0
- package/src/release/__tests__/validate.test.js +276 -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 +158 -0
- package/src/release/types.d.ts +86 -0
- package/src/release/types.js +1 -0
- package/src/release/validate.d.ts +7 -0
- package/src/release/validate.js +82 -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 +112 -187
- package/src/utils/__tests__/npm.test.js +10 -24
- package/src/utils/npm.d.ts +4 -4
- package/src/utils/npm.js +7 -17
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { validatePreviousBranchConfigured, validateBranchForTag, validateTagIncrementCombination, validateVersionSync, validateNextReleaseIsNotOverIncrement, } from '../validate.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/validate', () => {
|
|
12
|
+
describe('validatePreviousBranchConfigured', () => {
|
|
13
|
+
it('should not throw when isPrevious is false', () => {
|
|
14
|
+
expect(() => validatePreviousBranchConfigured(false)).not.toThrow();
|
|
15
|
+
});
|
|
16
|
+
it('should not throw when isPrevious is true and previousBranch is provided', () => {
|
|
17
|
+
expect(() => validatePreviousBranchConfigured(true, 'previous-branch')).not.toThrow();
|
|
18
|
+
});
|
|
19
|
+
it('should throw ReleaseError with message containing previousBranch is not configured when isPrevious is true and no branch is provided', () => {
|
|
20
|
+
expect(() => validatePreviousBranchConfigured(true)).toThrow(ReleaseError);
|
|
21
|
+
expect(() => validatePreviousBranchConfigured(true)).toThrow('previousBranch is not configured');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('validateBranchForTag', () => {
|
|
25
|
+
it('should not throw for experimental release from a feature branch', () => {
|
|
26
|
+
expect(() => validateBranchForTag({
|
|
27
|
+
isExperimental: true,
|
|
28
|
+
isPrevious: false,
|
|
29
|
+
branch: 'feature-branch',
|
|
30
|
+
mainBranch: 'master',
|
|
31
|
+
previousBranch: 'previous-branch',
|
|
32
|
+
})).not.toThrow();
|
|
33
|
+
});
|
|
34
|
+
it('should throw for experimental release from the main branch', () => {
|
|
35
|
+
expect(() => validateBranchForTag({
|
|
36
|
+
isExperimental: true,
|
|
37
|
+
isPrevious: false,
|
|
38
|
+
branch: 'master',
|
|
39
|
+
mainBranch: 'master',
|
|
40
|
+
previousBranch: 'previous-branch',
|
|
41
|
+
})).toThrow(ReleaseError);
|
|
42
|
+
});
|
|
43
|
+
it('should throw for experimental release from the previous branch', () => {
|
|
44
|
+
expect(() => validateBranchForTag({
|
|
45
|
+
isExperimental: true,
|
|
46
|
+
isPrevious: false,
|
|
47
|
+
branch: 'previous-branch',
|
|
48
|
+
mainBranch: 'master',
|
|
49
|
+
previousBranch: 'previous-branch',
|
|
50
|
+
})).toThrow(ReleaseError);
|
|
51
|
+
});
|
|
52
|
+
it('should throw for previous release from the wrong branch', () => {
|
|
53
|
+
expect(() => validateBranchForTag({
|
|
54
|
+
isExperimental: false,
|
|
55
|
+
isPrevious: true,
|
|
56
|
+
branch: 'master',
|
|
57
|
+
mainBranch: 'master',
|
|
58
|
+
previousBranch: 'previous-branch',
|
|
59
|
+
})).toThrow(ReleaseError);
|
|
60
|
+
});
|
|
61
|
+
it('should not throw for previous release from the correct previous branch', () => {
|
|
62
|
+
expect(() => validateBranchForTag({
|
|
63
|
+
isExperimental: false,
|
|
64
|
+
isPrevious: true,
|
|
65
|
+
branch: 'previous-branch',
|
|
66
|
+
mainBranch: 'master',
|
|
67
|
+
previousBranch: 'previous-branch',
|
|
68
|
+
})).not.toThrow();
|
|
69
|
+
});
|
|
70
|
+
it('should throw for latest/next release from a non-main branch', () => {
|
|
71
|
+
expect(() => validateBranchForTag({
|
|
72
|
+
isExperimental: false,
|
|
73
|
+
isPrevious: false,
|
|
74
|
+
branch: 'feature-branch',
|
|
75
|
+
mainBranch: 'master',
|
|
76
|
+
previousBranch: 'previous-branch',
|
|
77
|
+
})).toThrow(ReleaseError);
|
|
78
|
+
});
|
|
79
|
+
it('should not throw for latest/next release from the main branch', () => {
|
|
80
|
+
expect(() => validateBranchForTag({
|
|
81
|
+
isExperimental: false,
|
|
82
|
+
isPrevious: false,
|
|
83
|
+
branch: 'master',
|
|
84
|
+
mainBranch: 'master',
|
|
85
|
+
previousBranch: 'previous-branch',
|
|
86
|
+
})).not.toThrow();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('validateTagIncrementCombination', () => {
|
|
90
|
+
it('should throw for latest tag with prerelease increment', () => {
|
|
91
|
+
expect(() => validateTagIncrementCombination(TAG.LATEST, INCREMENT.PRERELEASE)).toThrow(ReleaseError);
|
|
92
|
+
});
|
|
93
|
+
it('should throw for previous tag with prerelease increment', () => {
|
|
94
|
+
expect(() => validateTagIncrementCombination(TAG.PREVIOUS, INCREMENT.PRERELEASE)).toThrow(ReleaseError);
|
|
95
|
+
});
|
|
96
|
+
it('should not throw for next tag with prerelease increment', () => {
|
|
97
|
+
expect(() => validateTagIncrementCombination(TAG.NEXT, INCREMENT.PRERELEASE)).not.toThrow();
|
|
98
|
+
});
|
|
99
|
+
it('should not throw for experimental tag with prerelease increment', () => {
|
|
100
|
+
expect(() => validateTagIncrementCombination(TAG.EXPERIMENTAL, INCREMENT.PRERELEASE)).not.toThrow();
|
|
101
|
+
});
|
|
102
|
+
it('should not throw for latest tag with patch increment', () => {
|
|
103
|
+
expect(() => validateTagIncrementCombination(TAG.LATEST, INCREMENT.PATCH)).not.toThrow();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('validateVersionSync', () => {
|
|
107
|
+
it('should not throw when next tag version matches local version', () => {
|
|
108
|
+
expect(() => validateVersionSync({
|
|
109
|
+
isExperimental: false,
|
|
110
|
+
isPrevious: false,
|
|
111
|
+
localVersion: '1.0.0-beta.1',
|
|
112
|
+
distTags: DIST_TAGS,
|
|
113
|
+
})).not.toThrow();
|
|
114
|
+
});
|
|
115
|
+
it('should throw with out of sync message when next tag version does not match local version', () => {
|
|
116
|
+
expect(() => validateVersionSync({
|
|
117
|
+
isExperimental: false,
|
|
118
|
+
isPrevious: false,
|
|
119
|
+
localVersion: '1.0.0-beta.2',
|
|
120
|
+
distTags: DIST_TAGS,
|
|
121
|
+
})).toThrow('out of sync');
|
|
122
|
+
});
|
|
123
|
+
it('should not throw for experimental regardless of version mismatch', () => {
|
|
124
|
+
expect(() => validateVersionSync({
|
|
125
|
+
isExperimental: true,
|
|
126
|
+
isPrevious: false,
|
|
127
|
+
localVersion: 'anything',
|
|
128
|
+
distTags: DIST_TAGS,
|
|
129
|
+
})).not.toThrow();
|
|
130
|
+
});
|
|
131
|
+
it('should not throw when previous version matches local version', () => {
|
|
132
|
+
expect(() => validateVersionSync({
|
|
133
|
+
isExperimental: false,
|
|
134
|
+
isPrevious: true,
|
|
135
|
+
localVersion: '0.9.0',
|
|
136
|
+
distTags: DIST_TAGS,
|
|
137
|
+
})).not.toThrow();
|
|
138
|
+
});
|
|
139
|
+
it('should throw when previous version does not match local version', () => {
|
|
140
|
+
expect(() => validateVersionSync({
|
|
141
|
+
isExperimental: false,
|
|
142
|
+
isPrevious: true,
|
|
143
|
+
localVersion: '0.8.0',
|
|
144
|
+
distTags: DIST_TAGS,
|
|
145
|
+
})).toThrow('out of sync');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('validateNextReleaseIsNotOverIncrement', () => {
|
|
149
|
+
const distTagsWithMinorBeta = {
|
|
150
|
+
latest: '8.10.0',
|
|
151
|
+
next: '8.11.0-beta.0',
|
|
152
|
+
experimental: '8.10.0-experimental.1',
|
|
153
|
+
previous: '7.0.0',
|
|
154
|
+
};
|
|
155
|
+
const distTagsWithPatchBeta = {
|
|
156
|
+
latest: '8.10.0',
|
|
157
|
+
next: '8.10.1-beta.0',
|
|
158
|
+
experimental: '8.10.0-experimental.1',
|
|
159
|
+
previous: '7.0.0',
|
|
160
|
+
};
|
|
161
|
+
const distTagsWithMajorBeta = {
|
|
162
|
+
latest: '8.10.0',
|
|
163
|
+
next: '9.0.0-beta.0',
|
|
164
|
+
experimental: '8.10.0-experimental.1',
|
|
165
|
+
previous: '7.0.0',
|
|
166
|
+
};
|
|
167
|
+
it('should not throw when not on next tag', () => {
|
|
168
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
169
|
+
tag: TAG.LATEST,
|
|
170
|
+
versionIncrement: INCREMENT.MINOR,
|
|
171
|
+
localVersion: '8.11.0-beta.0',
|
|
172
|
+
distTags: distTagsWithMinorBeta,
|
|
173
|
+
})).not.toThrow();
|
|
174
|
+
});
|
|
175
|
+
it('should not throw when using prerelease increment on next tag', () => {
|
|
176
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
177
|
+
tag: TAG.NEXT,
|
|
178
|
+
versionIncrement: INCREMENT.PRERELEASE,
|
|
179
|
+
localVersion: '8.11.0-beta.0',
|
|
180
|
+
distTags: distTagsWithMinorBeta,
|
|
181
|
+
})).not.toThrow();
|
|
182
|
+
});
|
|
183
|
+
it('should not throw when local version is not a beta (first next release)', () => {
|
|
184
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
185
|
+
tag: TAG.NEXT,
|
|
186
|
+
versionIncrement: INCREMENT.MINOR,
|
|
187
|
+
localVersion: '8.10.0',
|
|
188
|
+
distTags: distTagsWithMinorBeta,
|
|
189
|
+
})).not.toThrow();
|
|
190
|
+
});
|
|
191
|
+
it('should throw when using minor increment on top of a minor beta', () => {
|
|
192
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
193
|
+
tag: TAG.NEXT,
|
|
194
|
+
versionIncrement: INCREMENT.MINOR,
|
|
195
|
+
localVersion: '8.11.0-beta.0',
|
|
196
|
+
distTags: distTagsWithMinorBeta,
|
|
197
|
+
})).toThrow(ReleaseError);
|
|
198
|
+
});
|
|
199
|
+
it('should throw when using patch increment on top of a minor beta', () => {
|
|
200
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
201
|
+
tag: TAG.NEXT,
|
|
202
|
+
versionIncrement: INCREMENT.PATCH,
|
|
203
|
+
localVersion: '8.11.0-beta.0',
|
|
204
|
+
distTags: distTagsWithMinorBeta,
|
|
205
|
+
})).toThrow(ReleaseError);
|
|
206
|
+
});
|
|
207
|
+
it('should not throw when using major increment on top of a minor beta', () => {
|
|
208
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
209
|
+
tag: TAG.NEXT,
|
|
210
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
211
|
+
localVersion: '8.11.0-beta.0',
|
|
212
|
+
distTags: distTagsWithMinorBeta,
|
|
213
|
+
})).not.toThrow();
|
|
214
|
+
});
|
|
215
|
+
it('should throw when using patch increment on top of a patch beta', () => {
|
|
216
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
217
|
+
tag: TAG.NEXT,
|
|
218
|
+
versionIncrement: INCREMENT.PATCH,
|
|
219
|
+
localVersion: '8.10.1-beta.0',
|
|
220
|
+
distTags: distTagsWithPatchBeta,
|
|
221
|
+
})).toThrow(ReleaseError);
|
|
222
|
+
});
|
|
223
|
+
it('should not throw when using minor increment on top of a patch beta', () => {
|
|
224
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
225
|
+
tag: TAG.NEXT,
|
|
226
|
+
versionIncrement: INCREMENT.MINOR,
|
|
227
|
+
localVersion: '8.10.1-beta.0',
|
|
228
|
+
distTags: distTagsWithPatchBeta,
|
|
229
|
+
})).not.toThrow();
|
|
230
|
+
});
|
|
231
|
+
it('should not throw when using major increment on top of a patch beta', () => {
|
|
232
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
233
|
+
tag: TAG.NEXT,
|
|
234
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
235
|
+
localVersion: '8.10.1-beta.0',
|
|
236
|
+
distTags: distTagsWithPatchBeta,
|
|
237
|
+
})).not.toThrow();
|
|
238
|
+
});
|
|
239
|
+
it('should not throw for any non-prerelease increment on top of a major beta', () => {
|
|
240
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
241
|
+
tag: TAG.NEXT,
|
|
242
|
+
versionIncrement: INCREMENT.PATCH,
|
|
243
|
+
localVersion: '9.0.0-beta.0',
|
|
244
|
+
distTags: distTagsWithMajorBeta,
|
|
245
|
+
})).not.toThrow();
|
|
246
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
247
|
+
tag: TAG.NEXT,
|
|
248
|
+
versionIncrement: INCREMENT.MINOR,
|
|
249
|
+
localVersion: '9.0.0-beta.0',
|
|
250
|
+
distTags: distTagsWithMajorBeta,
|
|
251
|
+
})).not.toThrow();
|
|
252
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
253
|
+
tag: TAG.NEXT,
|
|
254
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
255
|
+
localVersion: '9.0.0-beta.0',
|
|
256
|
+
distTags: distTagsWithMajorBeta,
|
|
257
|
+
})).not.toThrow();
|
|
258
|
+
});
|
|
259
|
+
it('should include the skipped version in the error message', () => {
|
|
260
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
261
|
+
tag: TAG.NEXT,
|
|
262
|
+
versionIncrement: INCREMENT.MINOR,
|
|
263
|
+
localVersion: '8.11.0-beta.0',
|
|
264
|
+
distTags: distTagsWithMinorBeta,
|
|
265
|
+
})).toThrow('8.11.0');
|
|
266
|
+
});
|
|
267
|
+
it('should mention prerelease as the correct increment in the error message', () => {
|
|
268
|
+
expect(() => validateNextReleaseIsNotOverIncrement({
|
|
269
|
+
tag: TAG.NEXT,
|
|
270
|
+
versionIncrement: INCREMENT.MINOR,
|
|
271
|
+
localVersion: '8.11.0-beta.0',
|
|
272
|
+
distTags: distTagsWithMinorBeta,
|
|
273
|
+
})).toThrow('prerelease');
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,158 @@
|
|
|
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 || localVersion.includes(PRERELEASE_IDENTIFIER.NEXT)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const proceed = await confirm({
|
|
28
|
+
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?`,
|
|
29
|
+
default: false,
|
|
30
|
+
});
|
|
31
|
+
if (!proceed) {
|
|
32
|
+
logger.log(`\nTo release your changes on the next tag, run \`yarn release -v=${versionIncrement} -t=next\``);
|
|
33
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function runBuild(build) {
|
|
37
|
+
if (build && typeof build === 'function') {
|
|
38
|
+
await build();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
logger.log('Installing dependencies...');
|
|
42
|
+
await exec('yarn');
|
|
43
|
+
logger.log('Building...');
|
|
44
|
+
await exec('yarn build');
|
|
45
|
+
}
|
|
46
|
+
export async function createTempBranch(branch, mainBranch, previousBranch, isDryRun, tempBranch) {
|
|
47
|
+
if ((branch !== mainBranch && branch !== previousBranch) || isDryRun) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
|
|
51
|
+
await exec(`git checkout -b ${tempBranch}`);
|
|
52
|
+
}
|
|
53
|
+
export async function bumpVersion(newVersion, isExperimental) {
|
|
54
|
+
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
55
|
+
if (isExperimental) {
|
|
56
|
+
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
await exec(`yarn version --new-version ${newVersion}`);
|
|
60
|
+
}
|
|
61
|
+
logger.success('Version updated successfully \n');
|
|
62
|
+
}
|
|
63
|
+
export async function tryBuild({ build, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }) {
|
|
64
|
+
try {
|
|
65
|
+
await runBuild(build);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
logger.error(e);
|
|
69
|
+
logger.error('Build failed. Cleaning up...');
|
|
70
|
+
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? originalBranch : undefined);
|
|
71
|
+
throw new ReleaseError('');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function ensureNpmAuth(isDryRun, registry) {
|
|
75
|
+
if (isDryRun) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
await exec(`npm whoami --registry ${registry}`);
|
|
80
|
+
}
|
|
81
|
+
catch (_err) {
|
|
82
|
+
try {
|
|
83
|
+
execSync(`npm adduser --registry ${registry}`, { stdio: 'inherit' });
|
|
84
|
+
}
|
|
85
|
+
catch (_authErr) {
|
|
86
|
+
throw new ReleaseError('Failed to authenticate with npm');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function tryPublish({ tag, isDryRun, ignoreScripts, registry, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }) {
|
|
91
|
+
try {
|
|
92
|
+
await publish(tag, isDryRun, ignoreScripts, registry);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
logger.error(e);
|
|
96
|
+
logger.error('An error occurred while releasing this package. Correct the error and re-run `yarn build`.');
|
|
97
|
+
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? originalBranch : undefined);
|
|
98
|
+
// already logged above — throw with empty message so the handler doesn't double-log
|
|
99
|
+
throw new ReleaseError('');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export async function updateDistTagsForLatest({ tag, versionIncrement, packageName, newVersion, currentLatestTag, isDryRun, registry, tempBranch, }) {
|
|
103
|
+
if (tag !== TAG.LATEST) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
107
|
+
try {
|
|
108
|
+
await updateNextTag(packageName, newVersion, isDryRun, registry);
|
|
109
|
+
}
|
|
110
|
+
catch (_e) {
|
|
111
|
+
logger.error(`An error occurred while updating the ${TAG.NEXT} tag. To finish this release, run the following commands:`);
|
|
112
|
+
logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
|
|
113
|
+
logger.log(gitCommand);
|
|
114
|
+
}
|
|
115
|
+
if (versionIncrement !== INCREMENT.MAJOR) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
await updatePreviousTag(packageName, currentLatestTag, isDryRun, registry);
|
|
120
|
+
}
|
|
121
|
+
catch (_e) {
|
|
122
|
+
logger.error(`An error occurred while updating the ${TAG.PREVIOUS} tag. To finish this release, run the following command:`);
|
|
123
|
+
logger.log(`npm dist-tag add ${packageName}@${currentLatestTag} ${TAG.PREVIOUS}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export async function finalizeRelease({ isDryRun, isExperimental, newVersion, localVersion, tempBranch, isPrevious, previousBranch, mainBranch, repositoryUrl, }) {
|
|
127
|
+
if (isDryRun) {
|
|
128
|
+
await gitCleanup(newVersion, !isExperimental);
|
|
129
|
+
logger.log(`\nDry run: skipping push to Github`);
|
|
130
|
+
logger.log('Dry run release finished successfully');
|
|
131
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
132
|
+
}
|
|
133
|
+
if (isExperimental) {
|
|
134
|
+
logger.log(`\nExperimental release: Skipping push to Github`);
|
|
135
|
+
await exec(`yarn version --no-git-tag-version --new-version ${localVersion}`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
139
|
+
logger.log(`\nPushing changes to Github...`);
|
|
140
|
+
await exec(gitCommand);
|
|
141
|
+
logger.log(`Changes pushed successfully`);
|
|
142
|
+
const baseBranch = isPrevious ? previousBranch : mainBranch;
|
|
143
|
+
await open(`${repositoryUrl}/compare/${baseBranch}...${tempBranch}`);
|
|
144
|
+
}
|
|
145
|
+
export async function logReleaseSuccess({ packageName, newVersion, tag, repositoryUrl, isDryRun, postLatestRelease, }) {
|
|
146
|
+
logger.success(`${packageName} version ${newVersion} published successfully`);
|
|
147
|
+
logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
|
|
148
|
+
if (tag !== TAG.LATEST && tag !== TAG.PREVIOUS) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
logger.log(`\nRemember to create a new release on Github!`);
|
|
152
|
+
await open(`${repositoryUrl}/releases/new`);
|
|
153
|
+
if (tag === TAG.LATEST &&
|
|
154
|
+
postLatestRelease &&
|
|
155
|
+
typeof postLatestRelease === 'function') {
|
|
156
|
+
await postLatestRelease({ newVersion, dryRun: isDryRun });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { DistTags, Tag } from '../types.js';
|
|
2
|
+
export type NextReleaseIncrementOptions = {
|
|
3
|
+
tag: Tag;
|
|
4
|
+
versionIncrement: string;
|
|
5
|
+
localVersion: string;
|
|
6
|
+
distTags: DistTags;
|
|
7
|
+
};
|
|
8
|
+
export type BranchValidationOptions = {
|
|
9
|
+
isExperimental: boolean;
|
|
10
|
+
isPrevious: boolean;
|
|
11
|
+
branch: string;
|
|
12
|
+
mainBranch: string;
|
|
13
|
+
previousBranch?: string;
|
|
14
|
+
};
|
|
15
|
+
export type VersionSyncOptions = {
|
|
16
|
+
isExperimental: boolean;
|
|
17
|
+
isPrevious: boolean;
|
|
18
|
+
localVersion: string;
|
|
19
|
+
distTags: DistTags;
|
|
20
|
+
};
|
|
21
|
+
export type ComputeNewVersionOptions = {
|
|
22
|
+
tag: Tag;
|
|
23
|
+
versionIncrement: string;
|
|
24
|
+
isExperimental: boolean;
|
|
25
|
+
distTags: DistTags;
|
|
26
|
+
localVersion: string;
|
|
27
|
+
};
|
|
28
|
+
export type ConfirmReleaseOptions = {
|
|
29
|
+
isDryRun: boolean;
|
|
30
|
+
currentVersion: string;
|
|
31
|
+
newVersion: string;
|
|
32
|
+
tag: Tag;
|
|
33
|
+
localVersion: string;
|
|
34
|
+
versionIncrement: string;
|
|
35
|
+
};
|
|
36
|
+
export type TryBuildOptions = {
|
|
37
|
+
build?: () => Promise<void> | void;
|
|
38
|
+
newVersion: string;
|
|
39
|
+
isExperimental: boolean;
|
|
40
|
+
onTempBranch: boolean;
|
|
41
|
+
tempBranch: string;
|
|
42
|
+
originalBranch: string;
|
|
43
|
+
};
|
|
44
|
+
export type TryPublishOptions = {
|
|
45
|
+
tag: Tag;
|
|
46
|
+
isDryRun: boolean;
|
|
47
|
+
ignoreScripts: boolean;
|
|
48
|
+
registry: string;
|
|
49
|
+
newVersion: string;
|
|
50
|
+
isExperimental: boolean;
|
|
51
|
+
onTempBranch: boolean;
|
|
52
|
+
tempBranch: string;
|
|
53
|
+
originalBranch: string;
|
|
54
|
+
};
|
|
55
|
+
export type UpdateDistTagsOptions = {
|
|
56
|
+
tag: Tag;
|
|
57
|
+
versionIncrement: string;
|
|
58
|
+
packageName: string;
|
|
59
|
+
newVersion: string;
|
|
60
|
+
currentLatestTag: string;
|
|
61
|
+
isDryRun: boolean;
|
|
62
|
+
registry: string;
|
|
63
|
+
tempBranch: string;
|
|
64
|
+
};
|
|
65
|
+
export type FinalizeReleaseOptions = {
|
|
66
|
+
isDryRun: boolean;
|
|
67
|
+
isExperimental: boolean;
|
|
68
|
+
newVersion: string;
|
|
69
|
+
localVersion: string;
|
|
70
|
+
tempBranch: string;
|
|
71
|
+
isPrevious: boolean;
|
|
72
|
+
previousBranch?: string;
|
|
73
|
+
mainBranch: string;
|
|
74
|
+
repositoryUrl: string;
|
|
75
|
+
};
|
|
76
|
+
export type LogReleaseSuccessOptions = {
|
|
77
|
+
packageName: string;
|
|
78
|
+
newVersion: string;
|
|
79
|
+
tag: Tag;
|
|
80
|
+
repositoryUrl: string;
|
|
81
|
+
isDryRun: boolean;
|
|
82
|
+
postLatestRelease?: (options: {
|
|
83
|
+
newVersion: string;
|
|
84
|
+
dryRun: boolean;
|
|
85
|
+
}) => Promise<void> | void;
|
|
86
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Tag } from '../types.js';
|
|
2
|
+
import type { BranchValidationOptions, NextReleaseIncrementOptions, 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;
|
|
7
|
+
export declare function validateNextReleaseIsNotOverIncrement({ tag, versionIncrement, localVersion, distTags, }: NextReleaseIncrementOptions): void;
|