@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,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,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;
|
package/src/release.js
CHANGED
|
@@ -1,204 +1,129 @@
|
|
|
1
|
-
import { exec as _exec, execSync } from 'node:child_process';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import yargs from 'yargs';
|
|
4
|
-
import semver from 'semver';
|
|
5
|
-
import open from 'open';
|
|
6
2
|
import fs from 'fs-extra';
|
|
7
3
|
import { logger } from './utils/logging.js';
|
|
8
4
|
import { EXIT_CODES } from './utils/process.js';
|
|
9
|
-
import { DEFAULT_MAIN_BRANCH,
|
|
10
|
-
import { getCurrentGitBranch
|
|
11
|
-
import { getDistTags
|
|
12
|
-
import {
|
|
13
|
-
|
|
5
|
+
import { DEFAULT_MAIN_BRANCH, TAG, TAG_OPTIONS, VERSION_INCREMENT_OPTIONS, } from './constants/release.js';
|
|
6
|
+
import { getCurrentGitBranch } from './utils/git.js';
|
|
7
|
+
import { getDistTags } from './utils/npm.js';
|
|
8
|
+
import { ReleaseError } from './release/errors.js';
|
|
9
|
+
import { validatePreviousBranchConfigured, validateBranchForTag, validateTagIncrementCombination, validateVersionSync, validateNextReleaseIsNotOverIncrement, } from './release/validate.js';
|
|
10
|
+
import { computeNewVersion } from './release/version.js';
|
|
11
|
+
import { confirmRelease, createTempBranch, bumpVersion, tryBuild, ensureNpmAuth, tryPublish, updateDistTagsForLatest, finalizeRelease, logReleaseSuccess, } from './release/steps.js';
|
|
14
12
|
function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, previousBranch, ignoreScripts, }) {
|
|
15
13
|
return async function handler({ versionIncrement, tag, dryRun, skipBranchValidation, skipVersionCheck, }) {
|
|
16
|
-
const branch = await getCurrentGitBranch();
|
|
17
|
-
const isExperimental = tag === TAG.EXPERIMENTAL;
|
|
18
|
-
const isPrevious = tag === TAG.PREVIOUS;
|
|
19
|
-
const isDryRun = Boolean(dryRun);
|
|
20
|
-
if (isPrevious && !previousBranch) {
|
|
21
|
-
logger.error('Cannot release to previous tag: previousBranch is not configured');
|
|
22
|
-
process.exit(EXIT_CODES.ERROR);
|
|
23
|
-
}
|
|
24
|
-
if (!skipBranchValidation) {
|
|
25
|
-
if (isExperimental &&
|
|
26
|
-
(branch === mainBranch || branch === previousBranch)) {
|
|
27
|
-
logger.error(`Releases to experimental tag cannot be published from the ${branch} branch`);
|
|
28
|
-
process.exit(EXIT_CODES.ERROR);
|
|
29
|
-
}
|
|
30
|
-
else if (isPrevious && branch !== previousBranch) {
|
|
31
|
-
logger.error(`Releases to previous tag can only be published from the ${previousBranch} branch`);
|
|
32
|
-
process.exit(EXIT_CODES.ERROR);
|
|
33
|
-
}
|
|
34
|
-
else if (!isExperimental && !isPrevious && branch !== mainBranch) {
|
|
35
|
-
logger.error(`Releases to latest and next tags can only be published from the ${mainBranch} branch`);
|
|
36
|
-
process.exit(EXIT_CODES.ERROR);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if ((tag === TAG.LATEST || tag === TAG.PREVIOUS) &&
|
|
40
|
-
versionIncrement === INCREMENT.PRERELEASE) {
|
|
41
|
-
logger.error(`Invalid release: cannot increment prerelease number on ${tag} tag.`);
|
|
42
|
-
process.exit(EXIT_CODES.ERROR);
|
|
43
|
-
}
|
|
44
|
-
const { latest: currentLatestTag, next: currentNextTag, experimental: currentExperimentalTag, previous: currentPreviousTag, } = await getDistTags(packageName);
|
|
45
|
-
if (!skipVersionCheck) {
|
|
46
|
-
if (!isExperimental && !isPrevious && currentNextTag !== localVersion) {
|
|
47
|
-
logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentNextTag}`);
|
|
48
|
-
process.exit(EXIT_CODES.ERROR);
|
|
49
|
-
}
|
|
50
|
-
if (isPrevious && currentPreviousTag !== localVersion) {
|
|
51
|
-
logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentPreviousTag}`);
|
|
52
|
-
process.exit(EXIT_CODES.ERROR);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const currentVersion = isExperimental
|
|
56
|
-
? currentExperimentalTag
|
|
57
|
-
: localVersion;
|
|
58
|
-
const prereleaseIdentifier = isExperimental
|
|
59
|
-
? PRERELEASE_IDENTIFIER.EXPERIMENTAL
|
|
60
|
-
: PRERELEASE_IDENTIFIER.NEXT;
|
|
61
|
-
const incrementType = tag === TAG.LATEST ||
|
|
62
|
-
tag === TAG.PREVIOUS ||
|
|
63
|
-
versionIncrement === INCREMENT.PRERELEASE
|
|
64
|
-
? versionIncrement
|
|
65
|
-
: `pre${versionIncrement}`;
|
|
66
|
-
const newVersion = semver.inc(currentVersion, incrementType, prereleaseIdentifier);
|
|
67
|
-
const tempBranch = `v${newVersion}-publish`;
|
|
68
|
-
if (!newVersion) {
|
|
69
|
-
logger.error('Error incrementing version.');
|
|
70
|
-
process.exit(EXIT_CODES.ERROR);
|
|
71
|
-
}
|
|
72
|
-
if (dryRun) {
|
|
73
|
-
logger.log('\nDRY RUN');
|
|
74
|
-
}
|
|
75
|
-
logger.log(`\nCurrent version: ${currentVersion}`);
|
|
76
|
-
logger.log(`New version to release: ${newVersion}`);
|
|
77
|
-
const shouldRelease = await confirm({
|
|
78
|
-
message: `Release version ${newVersion} on tag ${tag}?`,
|
|
79
|
-
});
|
|
80
|
-
if (!shouldRelease) {
|
|
81
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
82
|
-
}
|
|
83
|
-
if (tag === TAG.LATEST &&
|
|
84
|
-
!localVersion.includes(PRERELEASE_IDENTIFIER.NEXT)) {
|
|
85
|
-
const proceedWithoutBetaRelease = await confirm({
|
|
86
|
-
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?`,
|
|
87
|
-
default: false,
|
|
88
|
-
});
|
|
89
|
-
if (!proceedWithoutBetaRelease) {
|
|
90
|
-
logger.log(`\nTo release your changes on the next tag, run \`yarn release -v=${versionIncrement} -t=next\``);
|
|
91
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if ((branch === mainBranch || branch === previousBranch) && !dryRun) {
|
|
95
|
-
logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
|
|
96
|
-
await exec(`git checkout -b ${tempBranch}`);
|
|
97
|
-
}
|
|
98
|
-
const onTempBranch = (branch === mainBranch || branch === previousBranch) && !isDryRun;
|
|
99
|
-
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
100
|
-
if (isExperimental) {
|
|
101
|
-
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
await exec(`yarn version --new-version ${newVersion}`);
|
|
105
|
-
}
|
|
106
|
-
logger.success('Version updated successfully \n');
|
|
107
14
|
try {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
process.exit(EXIT_CODES.ERROR);
|
|
123
|
-
}
|
|
124
|
-
let otp = '';
|
|
125
|
-
if (!isDryRun) {
|
|
126
|
-
try {
|
|
127
|
-
await exec(`npm whoami --registry ${registry}`);
|
|
15
|
+
const branch = await getCurrentGitBranch();
|
|
16
|
+
const isExperimental = tag === TAG.EXPERIMENTAL;
|
|
17
|
+
const isPrevious = tag === TAG.PREVIOUS;
|
|
18
|
+
const isDryRun = Boolean(dryRun);
|
|
19
|
+
const resolvedMainBranch = mainBranch ?? DEFAULT_MAIN_BRANCH;
|
|
20
|
+
validatePreviousBranchConfigured(isPrevious, previousBranch);
|
|
21
|
+
if (!skipBranchValidation) {
|
|
22
|
+
validateBranchForTag({
|
|
23
|
+
isExperimental,
|
|
24
|
+
isPrevious,
|
|
25
|
+
branch,
|
|
26
|
+
mainBranch: resolvedMainBranch,
|
|
27
|
+
previousBranch,
|
|
28
|
+
});
|
|
128
29
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
30
|
+
validateTagIncrementCombination(tag, versionIncrement);
|
|
31
|
+
const distTags = await getDistTags(packageName);
|
|
32
|
+
if (!skipVersionCheck) {
|
|
33
|
+
validateVersionSync({
|
|
34
|
+
isExperimental,
|
|
35
|
+
isPrevious,
|
|
36
|
+
localVersion,
|
|
37
|
+
distTags,
|
|
38
|
+
});
|
|
137
39
|
}
|
|
138
|
-
|
|
139
|
-
|
|
40
|
+
validateNextReleaseIsNotOverIncrement({
|
|
41
|
+
tag,
|
|
42
|
+
versionIncrement,
|
|
43
|
+
localVersion,
|
|
44
|
+
distTags,
|
|
45
|
+
});
|
|
46
|
+
const newVersion = computeNewVersion({
|
|
47
|
+
tag,
|
|
48
|
+
versionIncrement,
|
|
49
|
+
isExperimental,
|
|
50
|
+
distTags,
|
|
51
|
+
localVersion,
|
|
52
|
+
});
|
|
53
|
+
const tempBranch = `v${newVersion}-publish`;
|
|
54
|
+
const currentVersion = isExperimental
|
|
55
|
+
? distTags.experimental
|
|
56
|
+
: localVersion;
|
|
57
|
+
const onTempBranch = (branch === resolvedMainBranch || branch === previousBranch) &&
|
|
58
|
+
!isDryRun;
|
|
59
|
+
await confirmRelease({
|
|
60
|
+
isDryRun,
|
|
61
|
+
currentVersion,
|
|
62
|
+
newVersion,
|
|
63
|
+
tag,
|
|
64
|
+
localVersion,
|
|
65
|
+
versionIncrement,
|
|
66
|
+
});
|
|
67
|
+
await createTempBranch(branch, resolvedMainBranch, previousBranch, isDryRun, tempBranch);
|
|
68
|
+
await bumpVersion(newVersion, isExperimental);
|
|
69
|
+
await tryBuild({
|
|
70
|
+
build,
|
|
71
|
+
newVersion,
|
|
72
|
+
isExperimental,
|
|
73
|
+
onTempBranch,
|
|
74
|
+
tempBranch,
|
|
75
|
+
originalBranch: branch,
|
|
76
|
+
});
|
|
77
|
+
await ensureNpmAuth(isDryRun, registry);
|
|
78
|
+
await tryPublish({
|
|
79
|
+
tag,
|
|
80
|
+
isDryRun,
|
|
81
|
+
ignoreScripts: ignoreScripts || false,
|
|
82
|
+
registry,
|
|
83
|
+
newVersion,
|
|
84
|
+
isExperimental,
|
|
85
|
+
onTempBranch,
|
|
86
|
+
tempBranch,
|
|
87
|
+
originalBranch: branch,
|
|
88
|
+
});
|
|
89
|
+
await updateDistTagsForLatest({
|
|
90
|
+
tag,
|
|
91
|
+
versionIncrement,
|
|
92
|
+
packageName,
|
|
93
|
+
newVersion,
|
|
94
|
+
currentLatestTag: distTags.latest,
|
|
95
|
+
isDryRun,
|
|
96
|
+
registry,
|
|
97
|
+
tempBranch,
|
|
98
|
+
});
|
|
99
|
+
await finalizeRelease({
|
|
100
|
+
isDryRun,
|
|
101
|
+
isExperimental,
|
|
102
|
+
newVersion,
|
|
103
|
+
localVersion,
|
|
104
|
+
tempBranch,
|
|
105
|
+
isPrevious,
|
|
106
|
+
previousBranch,
|
|
107
|
+
mainBranch: resolvedMainBranch,
|
|
108
|
+
repositoryUrl,
|
|
109
|
+
});
|
|
110
|
+
await logReleaseSuccess({
|
|
111
|
+
packageName,
|
|
112
|
+
newVersion,
|
|
113
|
+
tag,
|
|
114
|
+
repositoryUrl,
|
|
115
|
+
isDryRun,
|
|
116
|
+
postLatestRelease,
|
|
140
117
|
});
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
logger.log('\nDry run: skipping one-time password entry');
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
await publish(tag, otp, isDryRun, ignoreScripts || false, registry);
|
|
147
118
|
}
|
|
148
119
|
catch (e) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
process.exit(EXIT_CODES.ERROR);
|
|
153
|
-
}
|
|
154
|
-
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
155
|
-
if (tag === TAG.LATEST) {
|
|
156
|
-
try {
|
|
157
|
-
await updateNextTag(packageName, newVersion, otp, isDryRun, registry);
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
logger.error(`An error occurred while updating the ${TAG.NEXT} tag. To finish this release, run the following commands:`);
|
|
161
|
-
logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
|
|
162
|
-
logger.log(gitCommand);
|
|
163
|
-
}
|
|
164
|
-
if (versionIncrement === INCREMENT.MAJOR) {
|
|
165
|
-
try {
|
|
166
|
-
await updatePreviousTag(packageName, currentLatestTag, otp, isDryRun, registry);
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
logger.error(`An error occurred while updating the ${TAG.PREVIOUS} tag. To finish this release, run the following command:`);
|
|
170
|
-
logger.log(`npm dist-tag add ${packageName}@${currentLatestTag} ${TAG.PREVIOUS}`);
|
|
120
|
+
if (e instanceof ReleaseError) {
|
|
121
|
+
if (e.message) {
|
|
122
|
+
logger.error(e.message);
|
|
171
123
|
}
|
|
124
|
+
process.exit(e.exitCode);
|
|
172
125
|
}
|
|
173
|
-
|
|
174
|
-
if (isDryRun) {
|
|
175
|
-
await gitCleanup(newVersion, !isExperimental);
|
|
176
|
-
logger.log(`\nDry run: skipping push to Github`);
|
|
177
|
-
logger.log('Dry run release finished successfully');
|
|
178
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
179
|
-
}
|
|
180
|
-
if (isExperimental) {
|
|
181
|
-
logger.log(`\nExperimental release: Skipping push to Github`);
|
|
182
|
-
// Reset the version back to the local version
|
|
183
|
-
await exec(`yarn version --no-git-tag-version --new-version ${localVersion}`);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
logger.log(`\nPushing changes to Github...`);
|
|
187
|
-
await exec(gitCommand);
|
|
188
|
-
logger.log(`Changes pushed successfully`);
|
|
189
|
-
const baseBranch = isPrevious ? previousBranch : mainBranch;
|
|
190
|
-
await open(`${repositoryUrl}/compare/${baseBranch}...${tempBranch}`);
|
|
191
|
-
}
|
|
192
|
-
logger.success(`${packageName} version ${newVersion} published successfully`);
|
|
193
|
-
logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
|
|
194
|
-
if (tag === TAG.LATEST || tag === TAG.PREVIOUS) {
|
|
195
|
-
logger.log(`\nRemember to create a new release on Github!`);
|
|
196
|
-
await open(`${repositoryUrl}/releases/new`);
|
|
197
|
-
if (tag === TAG.LATEST &&
|
|
198
|
-
postLatestRelease &&
|
|
199
|
-
typeof postLatestRelease === 'function') {
|
|
200
|
-
await postLatestRelease({ newVersion, dryRun });
|
|
201
|
-
}
|
|
126
|
+
throw e;
|
|
202
127
|
}
|
|
203
128
|
};
|
|
204
129
|
}
|
|
@@ -68,15 +68,13 @@ describe('npm', () => {
|
|
|
68
68
|
}),
|
|
69
69
|
};
|
|
70
70
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
71
|
-
await publish(TAG.LATEST,
|
|
71
|
+
await publish(TAG.LATEST, false, false, 'https://registry.npmjs.org/');
|
|
72
72
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
73
73
|
'publish',
|
|
74
74
|
'--tag',
|
|
75
75
|
TAG.LATEST,
|
|
76
76
|
'--registry',
|
|
77
77
|
'https://registry.npmjs.org/',
|
|
78
|
-
'--otp',
|
|
79
|
-
'123456',
|
|
80
78
|
], {
|
|
81
79
|
stdio: 'inherit',
|
|
82
80
|
cwd: './dist',
|
|
@@ -92,15 +90,13 @@ describe('npm', () => {
|
|
|
92
90
|
}),
|
|
93
91
|
};
|
|
94
92
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
95
|
-
await publish(TAG.NEXT,
|
|
93
|
+
await publish(TAG.NEXT, true, false, 'https://registry.npmjs.org/');
|
|
96
94
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
97
95
|
'publish',
|
|
98
96
|
'--tag',
|
|
99
97
|
TAG.NEXT,
|
|
100
98
|
'--registry',
|
|
101
99
|
'https://registry.npmjs.org/',
|
|
102
|
-
'--otp',
|
|
103
|
-
'123456',
|
|
104
100
|
'--dry-run',
|
|
105
101
|
], {
|
|
106
102
|
stdio: 'inherit',
|
|
@@ -117,15 +113,13 @@ describe('npm', () => {
|
|
|
117
113
|
}),
|
|
118
114
|
};
|
|
119
115
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
120
|
-
await publish(TAG.LATEST,
|
|
116
|
+
await publish(TAG.LATEST, false, true, 'https://registry.npmjs.org/');
|
|
121
117
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
122
118
|
'publish',
|
|
123
119
|
'--tag',
|
|
124
120
|
TAG.LATEST,
|
|
125
121
|
'--registry',
|
|
126
122
|
'https://registry.npmjs.org/',
|
|
127
|
-
'--otp',
|
|
128
|
-
'123456',
|
|
129
123
|
'--ignore-scripts',
|
|
130
124
|
], {
|
|
131
125
|
stdio: 'inherit',
|
|
@@ -142,15 +136,13 @@ describe('npm', () => {
|
|
|
142
136
|
}),
|
|
143
137
|
};
|
|
144
138
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
145
|
-
await publish(TAG.LATEST,
|
|
139
|
+
await publish(TAG.LATEST, true, true, 'https://registry.npmjs.org/');
|
|
146
140
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
147
141
|
'publish',
|
|
148
142
|
'--tag',
|
|
149
143
|
TAG.LATEST,
|
|
150
144
|
'--registry',
|
|
151
145
|
'https://registry.npmjs.org/',
|
|
152
|
-
'--otp',
|
|
153
|
-
'123456',
|
|
154
146
|
'--dry-run',
|
|
155
147
|
'--ignore-scripts',
|
|
156
148
|
], {
|
|
@@ -168,7 +160,7 @@ describe('npm', () => {
|
|
|
168
160
|
}),
|
|
169
161
|
};
|
|
170
162
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
171
|
-
await expect(publish(TAG.LATEST,
|
|
163
|
+
await expect(publish(TAG.LATEST, false, false, 'https://registry.npmjs.org/')).rejects.toThrow('npm publish failed with exit code 1');
|
|
172
164
|
});
|
|
173
165
|
});
|
|
174
166
|
describe('updateDistTag', () => {
|
|
@@ -182,7 +174,7 @@ describe('npm', () => {
|
|
|
182
174
|
}),
|
|
183
175
|
};
|
|
184
176
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
185
|
-
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag',
|
|
177
|
+
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', false, 'https://registry.npmjs.org/');
|
|
186
178
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
187
179
|
'dist-tag',
|
|
188
180
|
'add',
|
|
@@ -190,13 +182,11 @@ describe('npm', () => {
|
|
|
190
182
|
'custom-tag',
|
|
191
183
|
'--registry',
|
|
192
184
|
'https://registry.npmjs.org/',
|
|
193
|
-
'--otp',
|
|
194
|
-
'123456',
|
|
195
185
|
], { stdio: 'inherit' });
|
|
196
186
|
expect(vi.mocked(logger.success)).toHaveBeenCalledWith('custom-tag tag updated successfully');
|
|
197
187
|
});
|
|
198
188
|
it('should skip execution and log dry run message when isDryRun is true', async () => {
|
|
199
|
-
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag',
|
|
189
|
+
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', true, 'https://registry.npmjs.org/');
|
|
200
190
|
expect(mockedSpawn).not.toHaveBeenCalled();
|
|
201
191
|
expect(vi.mocked(logger.log)).toHaveBeenCalledWith(expect.stringContaining('Dry run: skipping run of'));
|
|
202
192
|
});
|
|
@@ -210,7 +200,7 @@ describe('npm', () => {
|
|
|
210
200
|
}),
|
|
211
201
|
};
|
|
212
202
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
213
|
-
await expect(updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag',
|
|
203
|
+
await expect(updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', false, 'https://registry.npmjs.org/')).rejects.toThrow('npm dist-tag add failed with exit code 1');
|
|
214
204
|
});
|
|
215
205
|
});
|
|
216
206
|
describe('updateNextTag', () => {
|
|
@@ -224,7 +214,7 @@ describe('npm', () => {
|
|
|
224
214
|
}),
|
|
225
215
|
};
|
|
226
216
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
227
|
-
await updateNextTag('@hubspot/test-package', '1.0.0',
|
|
217
|
+
await updateNextTag('@hubspot/test-package', '1.0.0', false, 'https://registry.npmjs.org/');
|
|
228
218
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
229
219
|
'dist-tag',
|
|
230
220
|
'add',
|
|
@@ -232,8 +222,6 @@ describe('npm', () => {
|
|
|
232
222
|
TAG.NEXT,
|
|
233
223
|
'--registry',
|
|
234
224
|
'https://registry.npmjs.org/',
|
|
235
|
-
'--otp',
|
|
236
|
-
'123456',
|
|
237
225
|
], { stdio: 'inherit' });
|
|
238
226
|
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(`${TAG.NEXT} tag updated successfully`);
|
|
239
227
|
});
|
|
@@ -249,7 +237,7 @@ describe('npm', () => {
|
|
|
249
237
|
}),
|
|
250
238
|
};
|
|
251
239
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
252
|
-
await updatePreviousTag('@hubspot/test-package', '8.3.6',
|
|
240
|
+
await updatePreviousTag('@hubspot/test-package', '8.3.6', false, 'https://registry.npmjs.org/');
|
|
253
241
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
254
242
|
'dist-tag',
|
|
255
243
|
'add',
|
|
@@ -257,8 +245,6 @@ describe('npm', () => {
|
|
|
257
245
|
TAG.PREVIOUS,
|
|
258
246
|
'--registry',
|
|
259
247
|
'https://registry.npmjs.org/',
|
|
260
|
-
'--otp',
|
|
261
|
-
'123456',
|
|
262
248
|
], { stdio: 'inherit' });
|
|
263
249
|
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(`${TAG.PREVIOUS} tag updated successfully`);
|
|
264
250
|
});
|
package/src/utils/npm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DistTags, Tag } from '../types.js';
|
|
2
2
|
export declare function getDistTags(packageName: string): Promise<DistTags>;
|
|
3
|
-
export declare function publish(tag: Tag,
|
|
4
|
-
export declare function updateDistTag(packageName: string, version: string, tag: string,
|
|
5
|
-
export declare function updateNextTag(packageName: string, newVersion: string,
|
|
6
|
-
export declare function updatePreviousTag(packageName: string, oldLatestVersion: string,
|
|
3
|
+
export declare function publish(tag: Tag, isDryRun: boolean, ignoreScripts: boolean, registry: string): Promise<void>;
|
|
4
|
+
export declare function updateDistTag(packageName: string, version: string, tag: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
5
|
+
export declare function updateNextTag(packageName: string, newVersion: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
6
|
+
export declare function updatePreviousTag(packageName: string, oldLatestVersion: string, isDryRun: boolean, registry: string): Promise<void>;
|
package/src/utils/npm.js
CHANGED
|
@@ -9,19 +9,11 @@ export async function getDistTags(packageName) {
|
|
|
9
9
|
const distTags = stdout.trim();
|
|
10
10
|
return JSON.parse(distTags);
|
|
11
11
|
}
|
|
12
|
-
export async function publish(tag,
|
|
12
|
+
export async function publish(tag, isDryRun, ignoreScripts, registry) {
|
|
13
13
|
logger.log(`\nPublishing to ${tag}...`);
|
|
14
14
|
logger.log('-'.repeat(50));
|
|
15
15
|
logger.log('\n');
|
|
16
|
-
const commandArgs = [
|
|
17
|
-
'publish',
|
|
18
|
-
'--tag',
|
|
19
|
-
tag,
|
|
20
|
-
'--registry',
|
|
21
|
-
registry,
|
|
22
|
-
'--otp',
|
|
23
|
-
otp,
|
|
24
|
-
];
|
|
16
|
+
const commandArgs = ['publish', '--tag', tag, '--registry', registry];
|
|
25
17
|
if (isDryRun) {
|
|
26
18
|
commandArgs.push('--dry-run');
|
|
27
19
|
}
|
|
@@ -43,7 +35,7 @@ export async function publish(tag, otp, isDryRun, ignoreScripts, registry) {
|
|
|
43
35
|
});
|
|
44
36
|
});
|
|
45
37
|
}
|
|
46
|
-
export async function updateDistTag(packageName, version, tag,
|
|
38
|
+
export async function updateDistTag(packageName, version, tag, isDryRun, registry) {
|
|
47
39
|
logger.log();
|
|
48
40
|
logger.log(`Updating ${tag} tag to ${version}...`);
|
|
49
41
|
const commandArgs = [
|
|
@@ -53,8 +45,6 @@ export async function updateDistTag(packageName, version, tag, otp, isDryRun, re
|
|
|
53
45
|
tag,
|
|
54
46
|
'--registry',
|
|
55
47
|
registry,
|
|
56
|
-
'--otp',
|
|
57
|
-
otp,
|
|
58
48
|
];
|
|
59
49
|
return new Promise((resolve, reject) => {
|
|
60
50
|
if (isDryRun) {
|
|
@@ -76,9 +66,9 @@ export async function updateDistTag(packageName, version, tag, otp, isDryRun, re
|
|
|
76
66
|
}
|
|
77
67
|
});
|
|
78
68
|
}
|
|
79
|
-
export async function updateNextTag(packageName, newVersion,
|
|
80
|
-
return updateDistTag(packageName, newVersion, TAG.NEXT,
|
|
69
|
+
export async function updateNextTag(packageName, newVersion, isDryRun, registry) {
|
|
70
|
+
return updateDistTag(packageName, newVersion, TAG.NEXT, isDryRun, registry);
|
|
81
71
|
}
|
|
82
|
-
export async function updatePreviousTag(packageName, oldLatestVersion,
|
|
83
|
-
return updateDistTag(packageName, oldLatestVersion, TAG.PREVIOUS,
|
|
72
|
+
export async function updatePreviousTag(packageName, oldLatestVersion, isDryRun, registry) {
|
|
73
|
+
return updateDistTag(packageName, oldLatestVersion, TAG.PREVIOUS, isDryRun, registry);
|
|
84
74
|
}
|