@hubspot/npm-scripts 0.3.2 → 0.3.3-beta.1

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.
@@ -0,0 +1,82 @@
1
+ import semver from 'semver';
2
+ import { TAG, INCREMENT, PRERELEASE_IDENTIFIER, } from '../../constants/release.js';
3
+ import { ReleaseError } from './errors.js';
4
+ export function validatePreviousBranchConfigured(isPrevious, previousBranch) {
5
+ if (!isPrevious || previousBranch) {
6
+ return;
7
+ }
8
+ throw new ReleaseError('Cannot release to previous tag: previousBranch is not configured');
9
+ }
10
+ export function validateBranchForTag({ isExperimental, isPrevious, branch, mainBranch, previousBranch, }) {
11
+ if (isExperimental && (branch === mainBranch || branch === previousBranch)) {
12
+ throw new ReleaseError(`Releases to experimental tag cannot be published from the ${branch} branch`);
13
+ }
14
+ else if (isPrevious && branch !== previousBranch) {
15
+ throw new ReleaseError(`Releases to previous tag can only be published from the ${previousBranch} branch`);
16
+ }
17
+ else if (!isExperimental && !isPrevious && branch !== mainBranch) {
18
+ throw new ReleaseError(`Releases to latest and next tags can only be published from the ${mainBranch} branch`);
19
+ }
20
+ }
21
+ export function validateTagIncrementCombination(tag, versionIncrement) {
22
+ if ((tag === TAG.LATEST || tag === TAG.PREVIOUS) &&
23
+ versionIncrement === INCREMENT.PRERELEASE) {
24
+ throw new ReleaseError(`Invalid release: cannot increment prerelease number on ${tag} tag.`);
25
+ }
26
+ }
27
+ export function validateVersionSync({ isExperimental, isPrevious, localVersion, distTags, }) {
28
+ // latest and next releases must be in sync with the published next dist-tag
29
+ if (!isExperimental && !isPrevious && distTags.next !== localVersion) {
30
+ throw new ReleaseError(`Local package.json version ${localVersion} is out of sync with published version ${distTags.next}`);
31
+ }
32
+ if (isPrevious && distTags.previous !== localVersion) {
33
+ throw new ReleaseError(`Local package.json version ${localVersion} is out of sync with published version ${distTags.previous}`);
34
+ }
35
+ }
36
+ export function validateNextReleaseIsNotOverIncrement({ tag, versionIncrement, localVersion, distTags, }) {
37
+ if (tag !== TAG.NEXT) {
38
+ return;
39
+ }
40
+ if (versionIncrement === INCREMENT.PRERELEASE) {
41
+ return;
42
+ }
43
+ const parsedLatest = semver.parse(distTags.latest);
44
+ const parsedLocal = semver.parse(localVersion);
45
+ if (!parsedLatest || !parsedLocal) {
46
+ return;
47
+ }
48
+ // No risk of over-incrementing on the first next release from a stable version
49
+ if (parsedLocal.prerelease[0] !== PRERELEASE_IDENTIFIER.NEXT) {
50
+ return;
51
+ }
52
+ const isMajorBeta = parsedLocal.major > parsedLatest.major;
53
+ const isMinorBeta = parsedLocal.major === parsedLatest.major &&
54
+ parsedLocal.minor > parsedLatest.minor;
55
+ const isPatchBeta = parsedLocal.major === parsedLatest.major &&
56
+ parsedLocal.minor === parsedLatest.minor &&
57
+ parsedLocal.patch > parsedLatest.patch;
58
+ // The beta version has the same base as latest (e.g. 1.0.0-beta.1 on top of 1.0.0),
59
+ // so any non-prerelease increment is fine — it won't skip an unreleased version.
60
+ if (!isMajorBeta && !isMinorBeta && !isPatchBeta) {
61
+ return;
62
+ }
63
+ // Allow increments that are strictly higher-level than the current beta type,
64
+ // e.g. a major increment on top of a minor beta is intentional and acceptable.
65
+ if (isMajorBeta ||
66
+ (isMinorBeta && versionIncrement === INCREMENT.MAJOR) ||
67
+ (isPatchBeta &&
68
+ (versionIncrement === INCREMENT.MAJOR ||
69
+ versionIncrement === INCREMENT.MINOR))) {
70
+ return;
71
+ }
72
+ let betaType = INCREMENT.PATCH;
73
+ if (isMajorBeta) {
74
+ betaType = INCREMENT.MAJOR;
75
+ }
76
+ else if (isMinorBeta) {
77
+ betaType = INCREMENT.MINOR;
78
+ }
79
+ throw new ReleaseError(`Cannot use "${versionIncrement}" increment: the current version ${localVersion} is already a ${betaType}-level beta on top of ${distTags.latest}. ` +
80
+ `Using "${versionIncrement}" would skip ${localVersion.split('-')[0]} on the latest tag. ` +
81
+ `Use "prerelease" to continue iterating on this beta, or use a higher-level increment (e.g. "major" over a minor beta).`);
82
+ }
@@ -0,0 +1,2 @@
1
+ import type { ComputeNewVersionOptions } from './types.js';
2
+ export declare function computeNewVersion({ tag, versionIncrement, isExperimental, distTags, localVersion, }: ComputeNewVersionOptions): string;
@@ -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
+ }