@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
package/src/release.js
CHANGED
|
@@ -1,204 +1,115 @@
|
|
|
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, } 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
|
-
|
|
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
|
+
});
|
|
116
29
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? branch : undefined);
|
|
122
|
-
process.exit(EXIT_CODES.ERROR);
|
|
123
|
-
}
|
|
124
|
-
let otp = '';
|
|
125
|
-
if (!isDryRun) {
|
|
126
|
-
try {
|
|
127
|
-
await exec(`npm whoami --registry ${registry}`);
|
|
30
|
+
validateTagIncrementCombination(tag, versionIncrement);
|
|
31
|
+
const distTags = await getDistTags(packageName);
|
|
32
|
+
if (!skipVersionCheck) {
|
|
33
|
+
validateVersionSync({ isExperimental, isPrevious, localVersion, distTags });
|
|
128
34
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
35
|
+
const newVersion = computeNewVersion({
|
|
36
|
+
tag,
|
|
37
|
+
versionIncrement,
|
|
38
|
+
isExperimental,
|
|
39
|
+
distTags,
|
|
40
|
+
localVersion,
|
|
41
|
+
});
|
|
42
|
+
const tempBranch = `v${newVersion}-publish`;
|
|
43
|
+
const currentVersion = isExperimental ? distTags.experimental : localVersion;
|
|
44
|
+
const onTempBranch = (branch === resolvedMainBranch || branch === previousBranch) && !isDryRun;
|
|
45
|
+
await confirmRelease({
|
|
46
|
+
isDryRun,
|
|
47
|
+
currentVersion,
|
|
48
|
+
newVersion,
|
|
49
|
+
tag,
|
|
50
|
+
localVersion,
|
|
51
|
+
versionIncrement,
|
|
52
|
+
});
|
|
53
|
+
await createTempBranch(branch, resolvedMainBranch, previousBranch, isDryRun, tempBranch);
|
|
54
|
+
await bumpVersion(newVersion, isExperimental);
|
|
55
|
+
await tryBuild({
|
|
56
|
+
build,
|
|
57
|
+
newVersion,
|
|
58
|
+
isExperimental,
|
|
59
|
+
onTempBranch,
|
|
60
|
+
tempBranch,
|
|
61
|
+
originalBranch: branch,
|
|
62
|
+
});
|
|
63
|
+
await ensureNpmAuth(isDryRun, registry);
|
|
64
|
+
await tryPublish({
|
|
65
|
+
tag,
|
|
66
|
+
isDryRun,
|
|
67
|
+
ignoreScripts: ignoreScripts || false,
|
|
68
|
+
registry,
|
|
69
|
+
newVersion,
|
|
70
|
+
isExperimental,
|
|
71
|
+
onTempBranch,
|
|
72
|
+
tempBranch,
|
|
73
|
+
originalBranch: branch,
|
|
74
|
+
});
|
|
75
|
+
await updateDistTagsForLatest({
|
|
76
|
+
tag,
|
|
77
|
+
versionIncrement,
|
|
78
|
+
packageName,
|
|
79
|
+
newVersion,
|
|
80
|
+
currentLatestTag: distTags.latest,
|
|
81
|
+
isDryRun,
|
|
82
|
+
registry,
|
|
83
|
+
tempBranch,
|
|
84
|
+
});
|
|
85
|
+
await finalizeRelease({
|
|
86
|
+
isDryRun,
|
|
87
|
+
isExperimental,
|
|
88
|
+
newVersion,
|
|
89
|
+
localVersion,
|
|
90
|
+
tempBranch,
|
|
91
|
+
isPrevious,
|
|
92
|
+
previousBranch,
|
|
93
|
+
mainBranch: resolvedMainBranch,
|
|
94
|
+
repositoryUrl,
|
|
95
|
+
});
|
|
96
|
+
await logReleaseSuccess({
|
|
97
|
+
packageName,
|
|
98
|
+
newVersion,
|
|
99
|
+
tag,
|
|
100
|
+
repositoryUrl,
|
|
101
|
+
isDryRun,
|
|
102
|
+
postLatestRelease,
|
|
140
103
|
});
|
|
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
104
|
}
|
|
148
105
|
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}`);
|
|
106
|
+
if (e instanceof ReleaseError) {
|
|
107
|
+
if (e.message) {
|
|
108
|
+
logger.error(e.message);
|
|
171
109
|
}
|
|
110
|
+
process.exit(e.exitCode);
|
|
172
111
|
}
|
|
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
|
-
}
|
|
112
|
+
throw e;
|
|
202
113
|
}
|
|
203
114
|
};
|
|
204
115
|
}
|
|
@@ -56,11 +56,11 @@ describe('git', () => {
|
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
describe('gitCleanup', () => {
|
|
59
|
-
it('should
|
|
59
|
+
it('should only checkout files when deleteTag is false', async () => {
|
|
60
60
|
mockedExec.mockImplementation(() => Promise.resolve({ stdout: '', stderr: '' }));
|
|
61
61
|
await gitCleanup('1.0.0', false);
|
|
62
|
-
expect(mockedExec).toHaveBeenCalledWith('git reset HEAD~');
|
|
63
62
|
expect(mockedExec).toHaveBeenCalledWith('git checkout .');
|
|
63
|
+
expect(mockedExec).not.toHaveBeenCalledWith('git reset HEAD~');
|
|
64
64
|
expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git tag -d'));
|
|
65
65
|
});
|
|
66
66
|
it('should reset HEAD, checkout files, and delete tag when deleteTag is true', async () => {
|
|
@@ -79,9 +79,10 @@ describe('git', () => {
|
|
|
79
79
|
expect(mockedExec).toHaveBeenCalledWith('git checkout master');
|
|
80
80
|
expect(mockedExec).toHaveBeenCalledWith('git branch -D v1.0.0-publish');
|
|
81
81
|
});
|
|
82
|
-
it('should not perform branch cleanup when
|
|
82
|
+
it('should not perform branch cleanup or reset when deleteTag is false and no branches provided', async () => {
|
|
83
83
|
mockedExec.mockImplementation(() => Promise.resolve({ stdout: '', stderr: '' }));
|
|
84
84
|
await gitCleanup('1.0.0', false);
|
|
85
|
+
expect(mockedExec).not.toHaveBeenCalledWith('git reset HEAD~');
|
|
85
86
|
expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git checkout master'));
|
|
86
87
|
expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git branch -D'));
|
|
87
88
|
});
|
|
@@ -68,16 +68,8 @@ describe('npm', () => {
|
|
|
68
68
|
}),
|
|
69
69
|
};
|
|
70
70
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
71
|
-
await publish(TAG.LATEST,
|
|
72
|
-
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
73
|
-
'publish',
|
|
74
|
-
'--tag',
|
|
75
|
-
TAG.LATEST,
|
|
76
|
-
'--registry',
|
|
77
|
-
'https://registry.npmjs.org/',
|
|
78
|
-
'--otp',
|
|
79
|
-
'123456',
|
|
80
|
-
], {
|
|
71
|
+
await publish(TAG.LATEST, false, false, 'https://registry.npmjs.org/');
|
|
72
|
+
expect(mockedSpawn).toHaveBeenCalledWith('npm', ['publish', '--tag', TAG.LATEST, '--registry', 'https://registry.npmjs.org/'], {
|
|
81
73
|
stdio: 'inherit',
|
|
82
74
|
cwd: './dist',
|
|
83
75
|
});
|
|
@@ -92,15 +84,13 @@ describe('npm', () => {
|
|
|
92
84
|
}),
|
|
93
85
|
};
|
|
94
86
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
95
|
-
await publish(TAG.NEXT,
|
|
87
|
+
await publish(TAG.NEXT, true, false, 'https://registry.npmjs.org/');
|
|
96
88
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
97
89
|
'publish',
|
|
98
90
|
'--tag',
|
|
99
91
|
TAG.NEXT,
|
|
100
92
|
'--registry',
|
|
101
93
|
'https://registry.npmjs.org/',
|
|
102
|
-
'--otp',
|
|
103
|
-
'123456',
|
|
104
94
|
'--dry-run',
|
|
105
95
|
], {
|
|
106
96
|
stdio: 'inherit',
|
|
@@ -117,15 +107,13 @@ describe('npm', () => {
|
|
|
117
107
|
}),
|
|
118
108
|
};
|
|
119
109
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
120
|
-
await publish(TAG.LATEST,
|
|
110
|
+
await publish(TAG.LATEST, false, true, 'https://registry.npmjs.org/');
|
|
121
111
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
122
112
|
'publish',
|
|
123
113
|
'--tag',
|
|
124
114
|
TAG.LATEST,
|
|
125
115
|
'--registry',
|
|
126
116
|
'https://registry.npmjs.org/',
|
|
127
|
-
'--otp',
|
|
128
|
-
'123456',
|
|
129
117
|
'--ignore-scripts',
|
|
130
118
|
], {
|
|
131
119
|
stdio: 'inherit',
|
|
@@ -142,15 +130,13 @@ describe('npm', () => {
|
|
|
142
130
|
}),
|
|
143
131
|
};
|
|
144
132
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
145
|
-
await publish(TAG.LATEST,
|
|
133
|
+
await publish(TAG.LATEST, true, true, 'https://registry.npmjs.org/');
|
|
146
134
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
147
135
|
'publish',
|
|
148
136
|
'--tag',
|
|
149
137
|
TAG.LATEST,
|
|
150
138
|
'--registry',
|
|
151
139
|
'https://registry.npmjs.org/',
|
|
152
|
-
'--otp',
|
|
153
|
-
'123456',
|
|
154
140
|
'--dry-run',
|
|
155
141
|
'--ignore-scripts',
|
|
156
142
|
], {
|
|
@@ -168,7 +154,7 @@ describe('npm', () => {
|
|
|
168
154
|
}),
|
|
169
155
|
};
|
|
170
156
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
171
|
-
await expect(publish(TAG.LATEST,
|
|
157
|
+
await expect(publish(TAG.LATEST, false, false, 'https://registry.npmjs.org/')).rejects.toThrow('npm publish failed with exit code 1');
|
|
172
158
|
});
|
|
173
159
|
});
|
|
174
160
|
describe('updateDistTag', () => {
|
|
@@ -182,7 +168,7 @@ describe('npm', () => {
|
|
|
182
168
|
}),
|
|
183
169
|
};
|
|
184
170
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
185
|
-
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag',
|
|
171
|
+
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', false, 'https://registry.npmjs.org/');
|
|
186
172
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
187
173
|
'dist-tag',
|
|
188
174
|
'add',
|
|
@@ -190,13 +176,11 @@ describe('npm', () => {
|
|
|
190
176
|
'custom-tag',
|
|
191
177
|
'--registry',
|
|
192
178
|
'https://registry.npmjs.org/',
|
|
193
|
-
'--otp',
|
|
194
|
-
'123456',
|
|
195
179
|
], { stdio: 'inherit' });
|
|
196
180
|
expect(vi.mocked(logger.success)).toHaveBeenCalledWith('custom-tag tag updated successfully');
|
|
197
181
|
});
|
|
198
182
|
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',
|
|
183
|
+
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', true, 'https://registry.npmjs.org/');
|
|
200
184
|
expect(mockedSpawn).not.toHaveBeenCalled();
|
|
201
185
|
expect(vi.mocked(logger.log)).toHaveBeenCalledWith(expect.stringContaining('Dry run: skipping run of'));
|
|
202
186
|
});
|
|
@@ -210,7 +194,7 @@ describe('npm', () => {
|
|
|
210
194
|
}),
|
|
211
195
|
};
|
|
212
196
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
213
|
-
await expect(updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag',
|
|
197
|
+
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
198
|
});
|
|
215
199
|
});
|
|
216
200
|
describe('updateNextTag', () => {
|
|
@@ -224,7 +208,7 @@ describe('npm', () => {
|
|
|
224
208
|
}),
|
|
225
209
|
};
|
|
226
210
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
227
|
-
await updateNextTag('@hubspot/test-package', '1.0.0',
|
|
211
|
+
await updateNextTag('@hubspot/test-package', '1.0.0', false, 'https://registry.npmjs.org/');
|
|
228
212
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
229
213
|
'dist-tag',
|
|
230
214
|
'add',
|
|
@@ -232,8 +216,6 @@ describe('npm', () => {
|
|
|
232
216
|
TAG.NEXT,
|
|
233
217
|
'--registry',
|
|
234
218
|
'https://registry.npmjs.org/',
|
|
235
|
-
'--otp',
|
|
236
|
-
'123456',
|
|
237
219
|
], { stdio: 'inherit' });
|
|
238
220
|
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(`${TAG.NEXT} tag updated successfully`);
|
|
239
221
|
});
|
|
@@ -249,7 +231,7 @@ describe('npm', () => {
|
|
|
249
231
|
}),
|
|
250
232
|
};
|
|
251
233
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
252
|
-
await updatePreviousTag('@hubspot/test-package', '8.3.6',
|
|
234
|
+
await updatePreviousTag('@hubspot/test-package', '8.3.6', false, 'https://registry.npmjs.org/');
|
|
253
235
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
254
236
|
'dist-tag',
|
|
255
237
|
'add',
|
|
@@ -257,8 +239,6 @@ describe('npm', () => {
|
|
|
257
239
|
TAG.PREVIOUS,
|
|
258
240
|
'--registry',
|
|
259
241
|
'https://registry.npmjs.org/',
|
|
260
|
-
'--otp',
|
|
261
|
-
'123456',
|
|
262
242
|
], { stdio: 'inherit' });
|
|
263
243
|
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(`${TAG.PREVIOUS} tag updated successfully`);
|
|
264
244
|
});
|
package/src/utils/git.js
CHANGED
|
@@ -17,11 +17,11 @@ export async function getCurrentGitBranch() {
|
|
|
17
17
|
return stdout.trim();
|
|
18
18
|
}
|
|
19
19
|
export async function gitCleanup(newVersion, deleteTag, tempBranch, originalBranch) {
|
|
20
|
-
await exec(`git reset HEAD~`);
|
|
21
|
-
await exec(`git checkout .`);
|
|
22
20
|
if (deleteTag) {
|
|
21
|
+
await exec(`git reset HEAD~`);
|
|
23
22
|
await exec(`git tag -d v${newVersion}`);
|
|
24
23
|
}
|
|
24
|
+
await exec(`git checkout .`);
|
|
25
25
|
if (tempBranch && originalBranch) {
|
|
26
26
|
try {
|
|
27
27
|
await exec(`git checkout ${originalBranch}`);
|
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
|
}
|