@hubspot/npm-scripts 0.2.0-beta.0 → 0.2.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.
- package/package.json +1 -1
- package/src/constants/release.d.ts +2 -1
- package/src/constants/release.js +7 -1
- package/src/release.js +55 -19
- package/src/types.d.ts +4 -0
- package/src/utils/__tests__/npm.test.js +112 -11
- package/src/utils/npm.d.ts +3 -1
- package/src/utils/npm.js +15 -6
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ export declare const TAG: {
|
|
|
3
3
|
readonly LATEST: "latest";
|
|
4
4
|
readonly NEXT: "next";
|
|
5
5
|
readonly EXPERIMENTAL: "experimental";
|
|
6
|
+
readonly PREVIOUS: "previous";
|
|
6
7
|
};
|
|
7
8
|
export declare const INCREMENT: {
|
|
8
9
|
readonly PATCH: "patch";
|
|
@@ -11,7 +12,7 @@ export declare const INCREMENT: {
|
|
|
11
12
|
readonly PRERELEASE: "prerelease";
|
|
12
13
|
};
|
|
13
14
|
export declare const VERSION_INCREMENT_OPTIONS: readonly ["patch", "minor", "major", "prerelease"];
|
|
14
|
-
export declare const TAG_OPTIONS: readonly ["latest", "next", "experimental"];
|
|
15
|
+
export declare const TAG_OPTIONS: readonly ["latest", "next", "experimental", "previous"];
|
|
15
16
|
export declare const PRERELEASE_IDENTIFIER: {
|
|
16
17
|
readonly NEXT: "beta";
|
|
17
18
|
readonly EXPERIMENTAL: "experimental";
|
package/src/constants/release.js
CHANGED
|
@@ -3,6 +3,7 @@ export const TAG = {
|
|
|
3
3
|
LATEST: 'latest',
|
|
4
4
|
NEXT: 'next',
|
|
5
5
|
EXPERIMENTAL: 'experimental',
|
|
6
|
+
PREVIOUS: 'previous',
|
|
6
7
|
};
|
|
7
8
|
export const INCREMENT = {
|
|
8
9
|
PATCH: 'patch',
|
|
@@ -16,7 +17,12 @@ export const VERSION_INCREMENT_OPTIONS = [
|
|
|
16
17
|
INCREMENT.MAJOR,
|
|
17
18
|
INCREMENT.PRERELEASE,
|
|
18
19
|
];
|
|
19
|
-
export const TAG_OPTIONS = [
|
|
20
|
+
export const TAG_OPTIONS = [
|
|
21
|
+
TAG.LATEST,
|
|
22
|
+
TAG.NEXT,
|
|
23
|
+
TAG.EXPERIMENTAL,
|
|
24
|
+
TAG.PREVIOUS,
|
|
25
|
+
];
|
|
20
26
|
export const PRERELEASE_IDENTIFIER = {
|
|
21
27
|
NEXT: 'beta',
|
|
22
28
|
EXPERIMENTAL: 'experimental',
|
package/src/release.js
CHANGED
|
@@ -8,38 +8,57 @@ import { logger } from './utils/logging.js';
|
|
|
8
8
|
import { EXIT_CODES } from './utils/process.js';
|
|
9
9
|
import { DEFAULT_MAIN_BRANCH, INCREMENT, PRERELEASE_IDENTIFIER, TAG, TAG_OPTIONS, VERSION_INCREMENT_OPTIONS, } from './constants/release.js';
|
|
10
10
|
import { gitCleanup, getCurrentGitBranch } from './utils/git.js';
|
|
11
|
-
import { getDistTags, publish, updateNextTag } from './utils/npm.js';
|
|
11
|
+
import { getDistTags, publish, updateNextTag, updatePreviousTag, } from './utils/npm.js';
|
|
12
12
|
import { confirm, input } from './utils/prompting.js';
|
|
13
13
|
const exec = promisify(_exec);
|
|
14
|
-
function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, }) {
|
|
15
|
-
return async function handler({ versionIncrement, tag, dryRun, }) {
|
|
14
|
+
function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, previousBranch, ignoreScripts, }) {
|
|
15
|
+
return async function handler({ versionIncrement, tag, dryRun, skipBranchValidation, }) {
|
|
16
16
|
const branch = await getCurrentGitBranch();
|
|
17
17
|
const isExperimental = tag === TAG.EXPERIMENTAL;
|
|
18
|
+
const isPrevious = tag === TAG.PREVIOUS;
|
|
18
19
|
const isDryRun = Boolean(dryRun);
|
|
19
|
-
if (
|
|
20
|
-
logger.error(
|
|
20
|
+
if (isPrevious && !previousBranch) {
|
|
21
|
+
logger.error('Cannot release to previous tag: previousBranch is not configured');
|
|
21
22
|
process.exit(EXIT_CODES.ERROR);
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
}
|
|
26
38
|
}
|
|
27
|
-
if (tag === TAG.LATEST
|
|
28
|
-
|
|
39
|
+
if ((tag === TAG.LATEST || tag === TAG.PREVIOUS) &&
|
|
40
|
+
versionIncrement === INCREMENT.PRERELEASE) {
|
|
41
|
+
logger.error(`Invalid release: cannot increment prerelease number on ${tag} tag.`);
|
|
29
42
|
process.exit(EXIT_CODES.ERROR);
|
|
30
43
|
}
|
|
31
|
-
const { next: currentNextTag, experimental: currentExperimentalTag } = await getDistTags(packageName);
|
|
32
|
-
if (!isExperimental && currentNextTag !== localVersion) {
|
|
44
|
+
const { latest: currentLatestTag, next: currentNextTag, experimental: currentExperimentalTag, previous: currentPreviousTag, } = await getDistTags(packageName);
|
|
45
|
+
if (!isExperimental && !isPrevious && currentNextTag !== localVersion) {
|
|
33
46
|
logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentNextTag}`);
|
|
34
47
|
process.exit(EXIT_CODES.ERROR);
|
|
35
48
|
}
|
|
49
|
+
if (isPrevious && currentPreviousTag !== localVersion) {
|
|
50
|
+
logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentPreviousTag}`);
|
|
51
|
+
process.exit(EXIT_CODES.ERROR);
|
|
52
|
+
}
|
|
36
53
|
const currentVersion = isExperimental
|
|
37
54
|
? currentExperimentalTag
|
|
38
55
|
: localVersion;
|
|
39
56
|
const prereleaseIdentifier = isExperimental
|
|
40
57
|
? PRERELEASE_IDENTIFIER.EXPERIMENTAL
|
|
41
58
|
: PRERELEASE_IDENTIFIER.NEXT;
|
|
42
|
-
const incrementType = tag === TAG.LATEST ||
|
|
59
|
+
const incrementType = tag === TAG.LATEST ||
|
|
60
|
+
tag === TAG.PREVIOUS ||
|
|
61
|
+
versionIncrement === INCREMENT.PRERELEASE
|
|
43
62
|
? versionIncrement
|
|
44
63
|
: `pre${versionIncrement}`;
|
|
45
64
|
const newVersion = semver.inc(currentVersion, incrementType, prereleaseIdentifier);
|
|
@@ -59,7 +78,7 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
|
|
|
59
78
|
if (!shouldRelease) {
|
|
60
79
|
process.exit(EXIT_CODES.SUCCESS);
|
|
61
80
|
}
|
|
62
|
-
if (branch === mainBranch && !dryRun) {
|
|
81
|
+
if ((branch === mainBranch || branch === previousBranch) && !dryRun) {
|
|
63
82
|
logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
|
|
64
83
|
await exec(`git checkout -b ${tempBranch}`);
|
|
65
84
|
}
|
|
@@ -110,11 +129,11 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
|
|
|
110
129
|
logger.log('\nDry run: skipping one-time password entry');
|
|
111
130
|
}
|
|
112
131
|
try {
|
|
113
|
-
await publish(tag, otp, isDryRun, registry);
|
|
132
|
+
await publish(tag, otp, isDryRun, ignoreScripts || false, registry);
|
|
114
133
|
}
|
|
115
134
|
catch (e) {
|
|
116
135
|
logger.error(e);
|
|
117
|
-
logger.error('An error occurred while releasing
|
|
136
|
+
logger.error('An error occurred while releasing this package. Correct the error and re-run `yarn build`.');
|
|
118
137
|
await gitCleanup(newVersion, !isExperimental);
|
|
119
138
|
process.exit(EXIT_CODES.ERROR);
|
|
120
139
|
}
|
|
@@ -128,6 +147,15 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
|
|
|
128
147
|
logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
|
|
129
148
|
logger.log(gitCommand);
|
|
130
149
|
}
|
|
150
|
+
if (versionIncrement === INCREMENT.MAJOR) {
|
|
151
|
+
try {
|
|
152
|
+
await updatePreviousTag(packageName, currentLatestTag, otp, isDryRun, registry);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
logger.error(`An error occurred while updating the ${TAG.PREVIOUS} tag. To finish this release, run the following command:`);
|
|
156
|
+
logger.log(`npm dist-tag add ${packageName}@${currentLatestTag} ${TAG.PREVIOUS}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
131
159
|
}
|
|
132
160
|
if (isDryRun) {
|
|
133
161
|
await gitCleanup(newVersion, !isExperimental);
|
|
@@ -144,14 +172,17 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
|
|
|
144
172
|
logger.log(`\nPushing changes to Github...`);
|
|
145
173
|
await exec(gitCommand);
|
|
146
174
|
logger.log(`Changes pushed successfully`);
|
|
147
|
-
|
|
175
|
+
const baseBranch = isPrevious ? previousBranch : mainBranch;
|
|
176
|
+
await open(`${repositoryUrl}/compare/${baseBranch}...${tempBranch}`);
|
|
148
177
|
}
|
|
149
178
|
logger.success(`${packageName} version ${newVersion} published successfully`);
|
|
150
179
|
logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
|
|
151
|
-
if (tag === TAG.LATEST) {
|
|
180
|
+
if (tag === TAG.LATEST || tag === TAG.PREVIOUS) {
|
|
152
181
|
logger.log(`\nRemember to create a new release on Github!`);
|
|
153
182
|
await open(`${repositoryUrl}/releases/new`);
|
|
154
|
-
if (
|
|
183
|
+
if (tag === TAG.LATEST &&
|
|
184
|
+
postLatestRelease &&
|
|
185
|
+
typeof postLatestRelease === 'function') {
|
|
155
186
|
await postLatestRelease({ newVersion, dryRun });
|
|
156
187
|
}
|
|
157
188
|
}
|
|
@@ -177,6 +208,11 @@ async function builder(yargs) {
|
|
|
177
208
|
default: false,
|
|
178
209
|
type: 'boolean',
|
|
179
210
|
},
|
|
211
|
+
skipBranchValidation: {
|
|
212
|
+
describe: 'Bypass the branch validation check',
|
|
213
|
+
default: false,
|
|
214
|
+
type: 'boolean',
|
|
215
|
+
},
|
|
180
216
|
});
|
|
181
217
|
}
|
|
182
218
|
export function buildReleaseScript({ packageJsonLocation, buildHandlerOptions, }) {
|
package/src/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type ReleaseArguments = {
|
|
|
3
3
|
versionIncrement: (typeof VERSION_INCREMENT_OPTIONS)[number];
|
|
4
4
|
tag: (typeof TAG_OPTIONS)[number];
|
|
5
5
|
dryRun: boolean;
|
|
6
|
+
skipBranchValidation: boolean;
|
|
6
7
|
};
|
|
7
8
|
export type RepoSyncArguments = {
|
|
8
9
|
version: string;
|
|
@@ -13,6 +14,7 @@ export type DistTags = {
|
|
|
13
14
|
[TAG.LATEST]: string;
|
|
14
15
|
[TAG.NEXT]: string;
|
|
15
16
|
[TAG.EXPERIMENTAL]: string;
|
|
17
|
+
[TAG.PREVIOUS]: string;
|
|
16
18
|
};
|
|
17
19
|
export type Tag = (typeof TAG_OPTIONS)[number];
|
|
18
20
|
export interface BuildReleaseScriptBase {
|
|
@@ -22,7 +24,9 @@ export interface BuildReleaseScriptBase {
|
|
|
22
24
|
dryRun: boolean;
|
|
23
25
|
}) => Promise<void> | void;
|
|
24
26
|
repositoryUrl: string;
|
|
27
|
+
ignoreScripts?: boolean;
|
|
25
28
|
mainBranch?: string;
|
|
29
|
+
previousBranch?: string;
|
|
26
30
|
}
|
|
27
31
|
export interface BuildReleaseScriptOptions extends BuildReleaseScriptBase {
|
|
28
32
|
packageName: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { getDistTags, publish, updateNextTag } from '../npm.js';
|
|
2
|
+
import { getDistTags, publish, updateDistTag, updateNextTag, updatePreviousTag, } from '../npm.js';
|
|
3
3
|
import { exec as _exec, spawn } from 'node:child_process';
|
|
4
4
|
import { logger } from '../logging.js';
|
|
5
5
|
import { EXIT_CODES } from '../process.js';
|
|
@@ -68,7 +68,7 @@ describe('npm', () => {
|
|
|
68
68
|
}),
|
|
69
69
|
};
|
|
70
70
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
71
|
-
await publish(TAG.LATEST, '123456', false, 'https://registry.npmjs.org/');
|
|
71
|
+
await publish(TAG.LATEST, '123456', false, false, 'https://registry.npmjs.org/');
|
|
72
72
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
73
73
|
'publish',
|
|
74
74
|
'--tag',
|
|
@@ -92,7 +92,7 @@ describe('npm', () => {
|
|
|
92
92
|
}),
|
|
93
93
|
};
|
|
94
94
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
95
|
-
await publish(TAG.NEXT, '123456', true, 'https://registry.npmjs.org/');
|
|
95
|
+
await publish(TAG.NEXT, '123456', true, false, 'https://registry.npmjs.org/');
|
|
96
96
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
97
97
|
'publish',
|
|
98
98
|
'--tag',
|
|
@@ -107,6 +107,57 @@ describe('npm', () => {
|
|
|
107
107
|
cwd: './dist',
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
|
+
it('should include --ignore-scripts flag when ignoreScripts is true', async () => {
|
|
111
|
+
const mockChildProcess = {
|
|
112
|
+
on: vi.fn((event, callback) => {
|
|
113
|
+
if (event === 'close') {
|
|
114
|
+
setTimeout(() => callback(EXIT_CODES.SUCCESS), 0);
|
|
115
|
+
}
|
|
116
|
+
return mockChildProcess;
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
120
|
+
await publish(TAG.LATEST, '123456', false, true, 'https://registry.npmjs.org/');
|
|
121
|
+
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
122
|
+
'publish',
|
|
123
|
+
'--tag',
|
|
124
|
+
TAG.LATEST,
|
|
125
|
+
'--registry',
|
|
126
|
+
'https://registry.npmjs.org/',
|
|
127
|
+
'--otp',
|
|
128
|
+
'123456',
|
|
129
|
+
'--ignore-scripts',
|
|
130
|
+
], {
|
|
131
|
+
stdio: 'inherit',
|
|
132
|
+
cwd: './dist',
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
it('should include both --dry-run and --ignore-scripts flags when both are true', async () => {
|
|
136
|
+
const mockChildProcess = {
|
|
137
|
+
on: vi.fn((event, callback) => {
|
|
138
|
+
if (event === 'close') {
|
|
139
|
+
setTimeout(() => callback(EXIT_CODES.SUCCESS), 0);
|
|
140
|
+
}
|
|
141
|
+
return mockChildProcess;
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
145
|
+
await publish(TAG.LATEST, '123456', true, true, 'https://registry.npmjs.org/');
|
|
146
|
+
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
147
|
+
'publish',
|
|
148
|
+
'--tag',
|
|
149
|
+
TAG.LATEST,
|
|
150
|
+
'--registry',
|
|
151
|
+
'https://registry.npmjs.org/',
|
|
152
|
+
'--otp',
|
|
153
|
+
'123456',
|
|
154
|
+
'--dry-run',
|
|
155
|
+
'--ignore-scripts',
|
|
156
|
+
], {
|
|
157
|
+
stdio: 'inherit',
|
|
158
|
+
cwd: './dist',
|
|
159
|
+
});
|
|
160
|
+
});
|
|
110
161
|
it('should reject on non-zero exit code', async () => {
|
|
111
162
|
const mockChildProcess = {
|
|
112
163
|
on: vi.fn((event, callback) => {
|
|
@@ -117,11 +168,11 @@ describe('npm', () => {
|
|
|
117
168
|
}),
|
|
118
169
|
};
|
|
119
170
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
120
|
-
await expect(publish(TAG.LATEST, '123456', false, 'https://registry.npmjs.org/')).rejects.toThrow('npm publish failed with exit code 1');
|
|
171
|
+
await expect(publish(TAG.LATEST, '123456', false, false, 'https://registry.npmjs.org/')).rejects.toThrow('npm publish failed with exit code 1');
|
|
121
172
|
});
|
|
122
173
|
});
|
|
123
|
-
describe('
|
|
124
|
-
it('should update
|
|
174
|
+
describe('updateDistTag', () => {
|
|
175
|
+
it('should update dist tag with correct arguments', async () => {
|
|
125
176
|
const mockChildProcess = {
|
|
126
177
|
on: vi.fn((event, callback) => {
|
|
127
178
|
if (event === 'close') {
|
|
@@ -131,21 +182,21 @@ describe('npm', () => {
|
|
|
131
182
|
}),
|
|
132
183
|
};
|
|
133
184
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
134
|
-
await
|
|
185
|
+
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', '123456', false, 'https://registry.npmjs.org/');
|
|
135
186
|
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
136
187
|
'dist-tag',
|
|
137
188
|
'add',
|
|
138
189
|
'@hubspot/test-package@1.0.0',
|
|
139
|
-
|
|
190
|
+
'custom-tag',
|
|
140
191
|
'--registry',
|
|
141
192
|
'https://registry.npmjs.org/',
|
|
142
193
|
'--otp',
|
|
143
194
|
'123456',
|
|
144
195
|
], { stdio: 'inherit' });
|
|
145
|
-
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(
|
|
196
|
+
expect(vi.mocked(logger.success)).toHaveBeenCalledWith('custom-tag tag updated successfully');
|
|
146
197
|
});
|
|
147
198
|
it('should skip execution and log dry run message when isDryRun is true', async () => {
|
|
148
|
-
await
|
|
199
|
+
await updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', '123456', true, 'https://registry.npmjs.org/');
|
|
149
200
|
expect(mockedSpawn).not.toHaveBeenCalled();
|
|
150
201
|
expect(vi.mocked(logger.log)).toHaveBeenCalledWith(expect.stringContaining('Dry run: skipping run of'));
|
|
151
202
|
});
|
|
@@ -159,7 +210,57 @@ describe('npm', () => {
|
|
|
159
210
|
}),
|
|
160
211
|
};
|
|
161
212
|
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
162
|
-
await expect(
|
|
213
|
+
await expect(updateDistTag('@hubspot/test-package', '1.0.0', 'custom-tag', '123456', false, 'https://registry.npmjs.org/')).rejects.toThrow('npm dist-tag add failed with exit code 1');
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
describe('updateNextTag', () => {
|
|
217
|
+
it('should call updateDistTag with TAG.NEXT', async () => {
|
|
218
|
+
const mockChildProcess = {
|
|
219
|
+
on: vi.fn((event, callback) => {
|
|
220
|
+
if (event === 'close') {
|
|
221
|
+
setTimeout(() => callback(EXIT_CODES.SUCCESS), 0);
|
|
222
|
+
}
|
|
223
|
+
return mockChildProcess;
|
|
224
|
+
}),
|
|
225
|
+
};
|
|
226
|
+
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
227
|
+
await updateNextTag('@hubspot/test-package', '1.0.0', '123456', false, 'https://registry.npmjs.org/');
|
|
228
|
+
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
229
|
+
'dist-tag',
|
|
230
|
+
'add',
|
|
231
|
+
'@hubspot/test-package@1.0.0',
|
|
232
|
+
TAG.NEXT,
|
|
233
|
+
'--registry',
|
|
234
|
+
'https://registry.npmjs.org/',
|
|
235
|
+
'--otp',
|
|
236
|
+
'123456',
|
|
237
|
+
], { stdio: 'inherit' });
|
|
238
|
+
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(`${TAG.NEXT} tag updated successfully`);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('updatePreviousTag', () => {
|
|
242
|
+
it('should call updateDistTag with TAG.PREVIOUS', async () => {
|
|
243
|
+
const mockChildProcess = {
|
|
244
|
+
on: vi.fn((event, callback) => {
|
|
245
|
+
if (event === 'close') {
|
|
246
|
+
setTimeout(() => callback(EXIT_CODES.SUCCESS), 0);
|
|
247
|
+
}
|
|
248
|
+
return mockChildProcess;
|
|
249
|
+
}),
|
|
250
|
+
};
|
|
251
|
+
mockedSpawn.mockImplementation(() => mockChildProcess);
|
|
252
|
+
await updatePreviousTag('@hubspot/test-package', '8.3.6', '123456', false, 'https://registry.npmjs.org/');
|
|
253
|
+
expect(mockedSpawn).toHaveBeenCalledWith('npm', [
|
|
254
|
+
'dist-tag',
|
|
255
|
+
'add',
|
|
256
|
+
'@hubspot/test-package@8.3.6',
|
|
257
|
+
TAG.PREVIOUS,
|
|
258
|
+
'--registry',
|
|
259
|
+
'https://registry.npmjs.org/',
|
|
260
|
+
'--otp',
|
|
261
|
+
'123456',
|
|
262
|
+
], { stdio: 'inherit' });
|
|
263
|
+
expect(vi.mocked(logger.success)).toHaveBeenCalledWith(`${TAG.PREVIOUS} tag updated successfully`);
|
|
163
264
|
});
|
|
164
265
|
});
|
|
165
266
|
});
|
package/src/utils/npm.d.ts
CHANGED
|
@@ -1,4 +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, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
3
|
+
export declare function publish(tag: Tag, otp: string, isDryRun: boolean, ignoreScripts: boolean, registry: string): Promise<void>;
|
|
4
|
+
export declare function updateDistTag(packageName: string, version: string, tag: string, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
4
5
|
export declare function updateNextTag(packageName: string, newVersion: string, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
6
|
+
export declare function updatePreviousTag(packageName: string, oldLatestVersion: string, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
package/src/utils/npm.js
CHANGED
|
@@ -9,7 +9,7 @@ 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, otp, isDryRun, registry) {
|
|
12
|
+
export async function publish(tag, otp, isDryRun, ignoreScripts, registry) {
|
|
13
13
|
logger.log(`\nPublishing to ${tag}...`);
|
|
14
14
|
logger.log('-'.repeat(50));
|
|
15
15
|
logger.log('\n');
|
|
@@ -25,6 +25,9 @@ export async function publish(tag, otp, isDryRun, registry) {
|
|
|
25
25
|
if (isDryRun) {
|
|
26
26
|
commandArgs.push('--dry-run');
|
|
27
27
|
}
|
|
28
|
+
if (ignoreScripts) {
|
|
29
|
+
commandArgs.push('--ignore-scripts');
|
|
30
|
+
}
|
|
28
31
|
return new Promise((resolve, reject) => {
|
|
29
32
|
const childProcess = spawn('npm', commandArgs, {
|
|
30
33
|
stdio: 'inherit',
|
|
@@ -40,14 +43,14 @@ export async function publish(tag, otp, isDryRun, registry) {
|
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
|
-
export async function
|
|
46
|
+
export async function updateDistTag(packageName, version, tag, otp, isDryRun, registry) {
|
|
44
47
|
logger.log();
|
|
45
|
-
logger.log(`Updating ${
|
|
48
|
+
logger.log(`Updating ${tag} tag to ${version}...`);
|
|
46
49
|
const commandArgs = [
|
|
47
50
|
'dist-tag',
|
|
48
51
|
'add',
|
|
49
|
-
`${packageName}@${
|
|
50
|
-
|
|
52
|
+
`${packageName}@${version}`,
|
|
53
|
+
tag,
|
|
51
54
|
'--registry',
|
|
52
55
|
registry,
|
|
53
56
|
'--otp',
|
|
@@ -66,10 +69,16 @@ export async function updateNextTag(packageName, newVersion, otp, isDryRun, regi
|
|
|
66
69
|
reject(new Error(`npm dist-tag add failed with exit code ${code}`));
|
|
67
70
|
}
|
|
68
71
|
else {
|
|
69
|
-
logger.success(`${
|
|
72
|
+
logger.success(`${tag} tag updated successfully`);
|
|
70
73
|
resolve();
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
78
|
}
|
|
79
|
+
export async function updateNextTag(packageName, newVersion, otp, isDryRun, registry) {
|
|
80
|
+
return updateDistTag(packageName, newVersion, TAG.NEXT, otp, isDryRun, registry);
|
|
81
|
+
}
|
|
82
|
+
export async function updatePreviousTag(packageName, oldLatestVersion, otp, isDryRun, registry) {
|
|
83
|
+
return updateDistTag(packageName, oldLatestVersion, TAG.PREVIOUS, otp, isDryRun, registry);
|
|
84
|
+
}
|