@hubspot/npm-scripts 0.0.6 → 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 +72 -2
- package/package.json +8 -4
- package/src/__tests__/release.test.d.ts +1 -0
- package/src/__tests__/release.test.js +494 -0
- package/src/constants/release.d.ts +2 -1
- package/src/constants/release.js +7 -1
- package/src/constants/repo-sync.d.ts +5 -0
- package/src/constants/repo-sync.js +5 -0
- 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 +112 -146
- package/src/repo-sync.d.ts +5 -0
- package/src/repo-sync.js +141 -0
- package/src/types.d.ts +18 -0
- package/src/utils/__tests__/filesystem.test.d.ts +1 -0
- package/src/utils/__tests__/filesystem.test.js +154 -0
- package/src/utils/__tests__/git.test.d.ts +1 -0
- package/src/utils/__tests__/git.test.js +292 -0
- package/src/utils/__tests__/logging.test.d.ts +1 -0
- package/src/utils/__tests__/logging.test.js +64 -0
- package/src/utils/__tests__/npm.test.d.ts +1 -0
- package/src/utils/__tests__/npm.test.js +246 -0
- package/src/utils/__tests__/process.test.d.ts +1 -0
- package/src/utils/__tests__/process.test.js +12 -0
- package/src/utils/__tests__/prompting.test.d.ts +1 -0
- package/src/utils/__tests__/prompting.test.js +100 -0
- package/src/utils/filesystem.d.ts +1 -0
- package/src/utils/filesystem.js +72 -0
- package/src/utils/git.d.ts +7 -1
- package/src/utils/git.js +112 -3
- package/src/utils/logging.js +2 -2
- package/src/utils/npm.d.ts +4 -2
- package/src/utils/npm.js +18 -19
|
@@ -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,159 @@
|
|
|
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 ||
|
|
25
|
+
localVersion.includes(PRERELEASE_IDENTIFIER.NEXT)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const proceed = await confirm({
|
|
29
|
+
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?`,
|
|
30
|
+
default: false,
|
|
31
|
+
});
|
|
32
|
+
if (!proceed) {
|
|
33
|
+
logger.log(`\nTo release your changes on the next tag, run \`yarn release -v=${versionIncrement} -t=next\``);
|
|
34
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function runBuild(build) {
|
|
38
|
+
if (build && typeof build === 'function') {
|
|
39
|
+
await build();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
logger.log('Installing dependencies...');
|
|
43
|
+
await exec('yarn');
|
|
44
|
+
logger.log('Building...');
|
|
45
|
+
await exec('yarn build');
|
|
46
|
+
}
|
|
47
|
+
export async function createTempBranch(branch, mainBranch, previousBranch, isDryRun, tempBranch) {
|
|
48
|
+
if ((branch !== mainBranch && branch !== previousBranch) || isDryRun) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
|
|
52
|
+
await exec(`git checkout -b ${tempBranch}`);
|
|
53
|
+
}
|
|
54
|
+
export async function bumpVersion(newVersion, isExperimental) {
|
|
55
|
+
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
56
|
+
if (isExperimental) {
|
|
57
|
+
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await exec(`yarn version --new-version ${newVersion}`);
|
|
61
|
+
}
|
|
62
|
+
logger.success('Version updated successfully \n');
|
|
63
|
+
}
|
|
64
|
+
export async function tryBuild({ build, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }) {
|
|
65
|
+
try {
|
|
66
|
+
await runBuild(build);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
logger.error(e);
|
|
70
|
+
logger.error('Build failed. Cleaning up...');
|
|
71
|
+
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? originalBranch : undefined);
|
|
72
|
+
throw new ReleaseError('');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function ensureNpmAuth(isDryRun, registry) {
|
|
76
|
+
if (isDryRun) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await exec(`npm whoami --registry ${registry}`);
|
|
81
|
+
}
|
|
82
|
+
catch (_err) {
|
|
83
|
+
try {
|
|
84
|
+
execSync(`npm adduser --registry ${registry}`, { stdio: 'inherit' });
|
|
85
|
+
}
|
|
86
|
+
catch (_authErr) {
|
|
87
|
+
throw new ReleaseError('Failed to authenticate with npm');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export async function tryPublish({ tag, isDryRun, ignoreScripts, registry, newVersion, isExperimental, onTempBranch, tempBranch, originalBranch, }) {
|
|
92
|
+
try {
|
|
93
|
+
await publish(tag, isDryRun, ignoreScripts, registry);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
logger.error(e);
|
|
97
|
+
logger.error('An error occurred while releasing this package. Correct the error and re-run `yarn build`.');
|
|
98
|
+
await gitCleanup(newVersion, !isExperimental, onTempBranch ? tempBranch : undefined, onTempBranch ? originalBranch : undefined);
|
|
99
|
+
// already logged above — throw with empty message so the handler doesn't double-log
|
|
100
|
+
throw new ReleaseError('');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export async function updateDistTagsForLatest({ tag, versionIncrement, packageName, newVersion, currentLatestTag, isDryRun, registry, tempBranch, }) {
|
|
104
|
+
if (tag !== TAG.LATEST) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
108
|
+
try {
|
|
109
|
+
await updateNextTag(packageName, newVersion, isDryRun, registry);
|
|
110
|
+
}
|
|
111
|
+
catch (_e) {
|
|
112
|
+
logger.error(`An error occurred while updating the ${TAG.NEXT} tag. To finish this release, run the following commands:`);
|
|
113
|
+
logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
|
|
114
|
+
logger.log(gitCommand);
|
|
115
|
+
}
|
|
116
|
+
if (versionIncrement !== INCREMENT.MAJOR) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await updatePreviousTag(packageName, currentLatestTag, isDryRun, registry);
|
|
121
|
+
}
|
|
122
|
+
catch (_e) {
|
|
123
|
+
logger.error(`An error occurred while updating the ${TAG.PREVIOUS} tag. To finish this release, run the following command:`);
|
|
124
|
+
logger.log(`npm dist-tag add ${packageName}@${currentLatestTag} ${TAG.PREVIOUS}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function finalizeRelease({ isDryRun, isExperimental, newVersion, localVersion, tempBranch, isPrevious, previousBranch, mainBranch, repositoryUrl, }) {
|
|
128
|
+
if (isDryRun) {
|
|
129
|
+
await gitCleanup(newVersion, !isExperimental);
|
|
130
|
+
logger.log(`\nDry run: skipping push to Github`);
|
|
131
|
+
logger.log('Dry run release finished successfully');
|
|
132
|
+
throw new ReleaseError('', EXIT_CODES.SUCCESS);
|
|
133
|
+
}
|
|
134
|
+
if (isExperimental) {
|
|
135
|
+
logger.log(`\nExperimental release: Skipping push to Github`);
|
|
136
|
+
await exec(`yarn version --no-git-tag-version --new-version ${localVersion}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
140
|
+
logger.log(`\nPushing changes to Github...`);
|
|
141
|
+
await exec(gitCommand);
|
|
142
|
+
logger.log(`Changes pushed successfully`);
|
|
143
|
+
const baseBranch = isPrevious ? previousBranch : mainBranch;
|
|
144
|
+
await open(`${repositoryUrl}/compare/${baseBranch}...${tempBranch}`);
|
|
145
|
+
}
|
|
146
|
+
export async function logReleaseSuccess({ packageName, newVersion, tag, repositoryUrl, isDryRun, postLatestRelease, }) {
|
|
147
|
+
logger.success(`${packageName} version ${newVersion} published successfully`);
|
|
148
|
+
logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
|
|
149
|
+
if (tag !== TAG.LATEST && tag !== TAG.PREVIOUS) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
logger.log(`\nRemember to create a new release on Github!`);
|
|
153
|
+
await open(`${repositoryUrl}/releases/new`);
|
|
154
|
+
if (tag === TAG.LATEST &&
|
|
155
|
+
postLatestRelease &&
|
|
156
|
+
typeof postLatestRelease === 'function') {
|
|
157
|
+
await postLatestRelease({ newVersion, dryRun: isDryRun });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DistTags, Tag } from '../types.js';
|
|
2
|
+
export type BranchValidationOptions = {
|
|
3
|
+
isExperimental: boolean;
|
|
4
|
+
isPrevious: boolean;
|
|
5
|
+
branch: string;
|
|
6
|
+
mainBranch: string;
|
|
7
|
+
previousBranch?: string;
|
|
8
|
+
};
|
|
9
|
+
export type VersionSyncOptions = {
|
|
10
|
+
isExperimental: boolean;
|
|
11
|
+
isPrevious: boolean;
|
|
12
|
+
localVersion: string;
|
|
13
|
+
distTags: DistTags;
|
|
14
|
+
};
|
|
15
|
+
export type ComputeNewVersionOptions = {
|
|
16
|
+
tag: Tag;
|
|
17
|
+
versionIncrement: string;
|
|
18
|
+
isExperimental: boolean;
|
|
19
|
+
distTags: DistTags;
|
|
20
|
+
localVersion: string;
|
|
21
|
+
};
|
|
22
|
+
export type ConfirmReleaseOptions = {
|
|
23
|
+
isDryRun: boolean;
|
|
24
|
+
currentVersion: string;
|
|
25
|
+
newVersion: string;
|
|
26
|
+
tag: Tag;
|
|
27
|
+
localVersion: string;
|
|
28
|
+
versionIncrement: string;
|
|
29
|
+
};
|
|
30
|
+
export type TryBuildOptions = {
|
|
31
|
+
build?: () => Promise<void> | void;
|
|
32
|
+
newVersion: string;
|
|
33
|
+
isExperimental: boolean;
|
|
34
|
+
onTempBranch: boolean;
|
|
35
|
+
tempBranch: string;
|
|
36
|
+
originalBranch: string;
|
|
37
|
+
};
|
|
38
|
+
export type TryPublishOptions = {
|
|
39
|
+
tag: Tag;
|
|
40
|
+
isDryRun: boolean;
|
|
41
|
+
ignoreScripts: boolean;
|
|
42
|
+
registry: string;
|
|
43
|
+
newVersion: string;
|
|
44
|
+
isExperimental: boolean;
|
|
45
|
+
onTempBranch: boolean;
|
|
46
|
+
tempBranch: string;
|
|
47
|
+
originalBranch: string;
|
|
48
|
+
};
|
|
49
|
+
export type UpdateDistTagsOptions = {
|
|
50
|
+
tag: Tag;
|
|
51
|
+
versionIncrement: string;
|
|
52
|
+
packageName: string;
|
|
53
|
+
newVersion: string;
|
|
54
|
+
currentLatestTag: string;
|
|
55
|
+
isDryRun: boolean;
|
|
56
|
+
registry: string;
|
|
57
|
+
tempBranch: string;
|
|
58
|
+
};
|
|
59
|
+
export type FinalizeReleaseOptions = {
|
|
60
|
+
isDryRun: boolean;
|
|
61
|
+
isExperimental: boolean;
|
|
62
|
+
newVersion: string;
|
|
63
|
+
localVersion: string;
|
|
64
|
+
tempBranch: string;
|
|
65
|
+
isPrevious: boolean;
|
|
66
|
+
previousBranch?: string;
|
|
67
|
+
mainBranch: string;
|
|
68
|
+
repositoryUrl: string;
|
|
69
|
+
};
|
|
70
|
+
export type LogReleaseSuccessOptions = {
|
|
71
|
+
packageName: string;
|
|
72
|
+
newVersion: string;
|
|
73
|
+
tag: Tag;
|
|
74
|
+
repositoryUrl: string;
|
|
75
|
+
isDryRun: boolean;
|
|
76
|
+
postLatestRelease?: (options: {
|
|
77
|
+
newVersion: string;
|
|
78
|
+
dryRun: boolean;
|
|
79
|
+
}) => Promise<void> | void;
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Tag } from '../types.js';
|
|
2
|
+
import type { BranchValidationOptions, 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;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TAG, INCREMENT } from '../constants/release.js';
|
|
2
|
+
import { ReleaseError } from './errors.js';
|
|
3
|
+
export function validatePreviousBranchConfigured(isPrevious, previousBranch) {
|
|
4
|
+
if (!isPrevious || previousBranch) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
throw new ReleaseError('Cannot release to previous tag: previousBranch is not configured');
|
|
8
|
+
}
|
|
9
|
+
export function validateBranchForTag({ isExperimental, isPrevious, branch, mainBranch, previousBranch, }) {
|
|
10
|
+
if (isExperimental && (branch === mainBranch || branch === previousBranch)) {
|
|
11
|
+
throw new ReleaseError(`Releases to experimental tag cannot be published from the ${branch} branch`);
|
|
12
|
+
}
|
|
13
|
+
else if (isPrevious && branch !== previousBranch) {
|
|
14
|
+
throw new ReleaseError(`Releases to previous tag can only be published from the ${previousBranch} branch`);
|
|
15
|
+
}
|
|
16
|
+
else if (!isExperimental && !isPrevious && branch !== mainBranch) {
|
|
17
|
+
throw new ReleaseError(`Releases to latest and next tags can only be published from the ${mainBranch} branch`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function validateTagIncrementCombination(tag, versionIncrement) {
|
|
21
|
+
if ((tag === TAG.LATEST || tag === TAG.PREVIOUS) &&
|
|
22
|
+
versionIncrement === INCREMENT.PRERELEASE) {
|
|
23
|
+
throw new ReleaseError(`Invalid release: cannot increment prerelease number on ${tag} tag.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function validateVersionSync({ isExperimental, isPrevious, localVersion, distTags, }) {
|
|
27
|
+
if (!isExperimental && !isPrevious && distTags.next !== localVersion) {
|
|
28
|
+
throw new ReleaseError(`Local package.json version ${localVersion} is out of sync with published version ${distTags.next}`);
|
|
29
|
+
}
|
|
30
|
+
if (isPrevious && distTags.previous !== localVersion) {
|
|
31
|
+
throw new ReleaseError(`Local package.json version ${localVersion} is out of sync with published version ${distTags.previous}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -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,159 +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 {
|
|
11
|
-
import { getDistTags
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentNextTag}`);
|
|
34
|
-
process.exit(EXIT_CODES.ERROR);
|
|
35
|
-
}
|
|
36
|
-
const currentVersion = isExperimental
|
|
37
|
-
? currentExperimentalTag
|
|
38
|
-
: localVersion;
|
|
39
|
-
const prereleaseIdentifier = isExperimental
|
|
40
|
-
? PRERELEASE_IDENTIFIER.EXPERIMENTAL
|
|
41
|
-
: PRERELEASE_IDENTIFIER.NEXT;
|
|
42
|
-
const incrementType = tag === TAG.LATEST || versionIncrement === INCREMENT.PRERELEASE
|
|
43
|
-
? versionIncrement
|
|
44
|
-
: `pre${versionIncrement}`;
|
|
45
|
-
const newVersion = semver.inc(currentVersion, incrementType, prereleaseIdentifier);
|
|
46
|
-
const tempBranch = `v${newVersion}-publish`;
|
|
47
|
-
if (!newVersion) {
|
|
48
|
-
logger.error('Error incrementing version.');
|
|
49
|
-
process.exit(EXIT_CODES.ERROR);
|
|
50
|
-
}
|
|
51
|
-
if (dryRun) {
|
|
52
|
-
logger.log('\nDRY RUN');
|
|
53
|
-
}
|
|
54
|
-
logger.log(`\nCurrent version: ${currentVersion}`);
|
|
55
|
-
logger.log(`New version to release: ${newVersion}`);
|
|
56
|
-
const shouldRelease = await confirm({
|
|
57
|
-
message: `Release version ${newVersion} on tag ${tag}?`,
|
|
58
|
-
});
|
|
59
|
-
if (!shouldRelease) {
|
|
60
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
61
|
-
}
|
|
62
|
-
if (branch === mainBranch && !dryRun) {
|
|
63
|
-
logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
|
|
64
|
-
await exec(`git checkout -b ${tempBranch}`);
|
|
65
|
-
}
|
|
66
|
-
if (tag === TAG.LATEST &&
|
|
67
|
-
!localVersion.includes(PRERELEASE_IDENTIFIER.NEXT)) {
|
|
68
|
-
const proceedWithoutBetaRelease = await confirm({
|
|
69
|
-
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?`,
|
|
70
|
-
default: false,
|
|
71
|
-
});
|
|
72
|
-
if (!proceedWithoutBetaRelease) {
|
|
73
|
-
logger.log(`\nTo release your changes on the next tag, run \`yarn release -v=${versionIncrement} -t=next\``);
|
|
74
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
78
|
-
if (isExperimental) {
|
|
79
|
-
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
await exec(`yarn version --new-version ${newVersion}`);
|
|
83
|
-
}
|
|
84
|
-
logger.success('Version updated successfully \n');
|
|
85
|
-
if (build && typeof build === 'function') {
|
|
86
|
-
await build();
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
await exec(`yarn build`);
|
|
90
|
-
}
|
|
91
|
-
let otp = '';
|
|
92
|
-
if (!isDryRun) {
|
|
93
|
-
try {
|
|
94
|
-
await exec(`npm whoami --registry ${registry}`);
|
|
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';
|
|
12
|
+
function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, previousBranch, ignoreScripts, }) {
|
|
13
|
+
return async function handler({ versionIncrement, tag, dryRun, skipBranchValidation, skipVersionCheck, }) {
|
|
14
|
+
try {
|
|
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
|
+
});
|
|
95
29
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
catch (authErr) {
|
|
101
|
-
logger.error('Failed to authenticate with npm');
|
|
102
|
-
process.exit(EXIT_CODES.ERROR);
|
|
103
|
-
}
|
|
30
|
+
validateTagIncrementCombination(tag, versionIncrement);
|
|
31
|
+
const distTags = await getDistTags(packageName);
|
|
32
|
+
if (!skipVersionCheck) {
|
|
33
|
+
validateVersionSync({ isExperimental, isPrevious, localVersion, distTags });
|
|
104
34
|
}
|
|
105
|
-
|
|
106
|
-
|
|
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,
|
|
107
103
|
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
logger.log('\nDry run: skipping one-time password entry');
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
await publish(tag, otp, isDryRun, registry);
|
|
114
104
|
}
|
|
115
105
|
catch (e) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
|
|
122
|
-
if (tag === TAG.LATEST) {
|
|
123
|
-
try {
|
|
124
|
-
await updateNextTag(packageName, newVersion, otp, isDryRun, registry);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
logger.error(`An error occurred while updating the ${TAG.NEXT} tag. To finish this release, run the following commands:`);
|
|
128
|
-
logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
|
|
129
|
-
logger.log(gitCommand);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (isDryRun) {
|
|
133
|
-
await gitCleanup(newVersion, !isExperimental);
|
|
134
|
-
logger.log(`\nDry run: skipping push to Github`);
|
|
135
|
-
logger.log('Dry run release finished successfully');
|
|
136
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
137
|
-
}
|
|
138
|
-
if (isExperimental) {
|
|
139
|
-
logger.log(`\nExperimental release: Skipping push to Github`);
|
|
140
|
-
// Reset the version back to the local version
|
|
141
|
-
await exec(`yarn version --no-git-tag-version --new-version ${localVersion}`);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
logger.log(`\nPushing changes to Github...`);
|
|
145
|
-
await exec(gitCommand);
|
|
146
|
-
logger.log(`Changes pushed successfully`);
|
|
147
|
-
await open(`${repositoryUrl}/compare/${mainBranch}...${tempBranch}`);
|
|
148
|
-
}
|
|
149
|
-
logger.success(`${packageName} version ${newVersion} published successfully`);
|
|
150
|
-
logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
|
|
151
|
-
if (tag === TAG.LATEST) {
|
|
152
|
-
logger.log(`\nRemember to create a new release on Github!`);
|
|
153
|
-
await open(`${repositoryUrl}/releases/new`);
|
|
154
|
-
if (postLatestRelease && typeof postLatestRelease === 'function') {
|
|
155
|
-
await postLatestRelease({ newVersion, dryRun });
|
|
106
|
+
if (e instanceof ReleaseError) {
|
|
107
|
+
if (e.message) {
|
|
108
|
+
logger.error(e.message);
|
|
109
|
+
}
|
|
110
|
+
process.exit(e.exitCode);
|
|
156
111
|
}
|
|
112
|
+
throw e;
|
|
157
113
|
}
|
|
158
114
|
};
|
|
159
115
|
}
|
|
@@ -177,6 +133,16 @@ async function builder(yargs) {
|
|
|
177
133
|
default: false,
|
|
178
134
|
type: 'boolean',
|
|
179
135
|
},
|
|
136
|
+
skipBranchValidation: {
|
|
137
|
+
describe: 'Bypass the branch validation check',
|
|
138
|
+
default: false,
|
|
139
|
+
type: 'boolean',
|
|
140
|
+
},
|
|
141
|
+
skipVersionCheck: {
|
|
142
|
+
describe: 'Bypass checking that the local version matches the published version',
|
|
143
|
+
default: false,
|
|
144
|
+
type: 'boolean',
|
|
145
|
+
},
|
|
180
146
|
});
|
|
181
147
|
}
|
|
182
148
|
export function buildReleaseScript({ packageJsonLocation, buildHandlerOptions, }) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BuildRepoSyncScriptOptions, RepoSyncArguments } from './types.js';
|
|
2
|
+
export declare function handleRepoSync({ sourceDirectory, targetRepositoryUrl, excludePatterns, buildCommitMessage, internalMainBranch, externalMainBranch, version, dryRun, sshKeyPath, }: BuildRepoSyncScriptOptions & RepoSyncArguments): Promise<void>;
|
|
3
|
+
export declare function buildRepoSyncScript({ buildHandlerOptions, }: {
|
|
4
|
+
buildHandlerOptions: BuildRepoSyncScriptOptions;
|
|
5
|
+
}): void;
|