Skip to content

Commit 7447005

Browse files
authored
Clarify internal validation logic + don't check for change needed in bump command (#1023)
clarify change needed logic
1 parent e554dc4 commit 7447005

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "bump command shouldn't check if change files are needed (+ clarify internal validation options)",
4+
"packageName": "beachball",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

src/__e2e__/validate.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('validate', () => {
4141
repo = repositoryFactory.cloneRepository();
4242
repo.checkout('-b', 'test');
4343

44-
const result = validate(getOptions());
44+
const result = validate(getOptions(), { checkChangeNeeded: true });
4545

4646
expect(result.isChangeNeeded).toBe(false);
4747
expect(logs.mocks.error).not.toHaveBeenCalled();
@@ -53,17 +53,17 @@ describe('validate', () => {
5353
repo.checkout('-b', 'test');
5454
repo.stageChange('packages/foo/test.js');
5555

56-
expect(() => validate(getOptions())).toThrowError(/process\.exit/);
56+
expect(() => validate(getOptions(), { checkChangeNeeded: true })).toThrowError(/process\.exit/);
5757
expect(processExit).toHaveBeenCalledWith(1);
5858
expect(logs.mocks.error).toHaveBeenCalledWith('ERROR: Change files are needed!');
5959
});
6060

61-
it('returns an error if change files are needed and allowMissingChangeFiles is true', () => {
61+
it('returns and does not log an error if change files are needed and allowMissingChangeFiles is true', () => {
6262
repo = repositoryFactory.cloneRepository();
6363
repo.checkout('-b', 'test');
6464
repo.stageChange('packages/foo/test.js');
6565

66-
const result = validate(getOptions(), { allowMissingChangeFiles: true });
66+
const result = validate(getOptions(), { checkChangeNeeded: true, allowMissingChangeFiles: true });
6767
expect(result.isChangeNeeded).toBe(true);
6868
expect(logs.mocks.error).not.toHaveBeenCalled();
6969
});

src/cli.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ import { validate } from './validation/validate';
2525
// Run the commands
2626
switch (options.command) {
2727
case 'check':
28-
validate(options);
28+
validate(options, { checkChangeNeeded: true, checkDependencies: true });
2929
console.log('No change files are needed');
3030
break;
3131

3232
case 'publish':
33-
validate(options, { allowFetching: false });
33+
validate(options, { checkDependencies: true });
3434

3535
// set a default publish message
3636
options.message = options.message || 'applying package updates';
3737
await publish(options);
3838
break;
3939

4040
case 'bump':
41-
validate(options);
41+
validate(options, { checkDependencies: true });
4242
await bump(options);
4343
break;
4444

4545
case 'canary':
46-
validate(options, { allowFetching: false });
46+
validate(options, { checkDependencies: true });
4747
await canary(options);
4848
break;
4949

@@ -56,7 +56,7 @@ import { validate } from './validation/validate';
5656
break;
5757

5858
case 'change': {
59-
const { isChangeNeeded } = validate(options, { allowMissingChangeFiles: true });
59+
const { isChangeNeeded } = validate(options, { checkChangeNeeded: true, allowMissingChangeFiles: true });
6060

6161
if (!isChangeNeeded && !options.package) {
6262
console.log('No change files are needed');

src/types/BeachballOptions.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface CliOptions
1414
| 'bumpDeps'
1515
| 'changehint'
1616
| 'changeDir'
17+
| 'concurrency'
1718
| 'depth'
1819
| 'disallowedChangeTypes'
1920
| 'fetch'
@@ -34,7 +35,6 @@ export interface CliOptions
3435
canaryName?: string | undefined;
3536
command: string;
3637
commit?: boolean;
37-
concurrency: number;
3838
configPath?: string;
3939
dependentChangeType?: ChangeType;
4040
disallowDeletedChangeFiles?: boolean;
@@ -104,6 +104,12 @@ export interface RepoOptions {
104104
changeDir: string;
105105
/** Options for customizing changelog rendering */
106106
changelog?: ChangelogOptions;
107+
/**
108+
* Maximum concurrency.
109+
* As of writing, concurrency only applies for calling hooks and publishing to npm.
110+
* @default 1
111+
*/
112+
concurrency: number;
107113
/**
108114
* The default dist-tag used for npm publish
109115
* @default 'latest'

src/validation/validate.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ import { env } from '../env';
1919

2020
type ValidationOptions = {
2121
/**
22-
* Defaults to true. If false, skip fetching the latest from the remote and don't check whether
23-
* changes files are needed (or whether change files are deleted).
22+
* If true, check whether change files are needed (and whether change files are deleted).
2423
*/
25-
allowFetching?: boolean;
24+
checkChangeNeeded?: boolean;
2625
/**
27-
* If true, skip checking whether change files are needed. Ignored if `allowFetching` is false.
26+
* If true, don't error if change files are needed (just return isChangeNeeded true).
2827
*/
2928
allowMissingChangeFiles?: boolean;
29+
/**
30+
* If true, validate that the dependencies of any packages with change files are valid
31+
* (not private).
32+
*/
33+
checkDependencies?: boolean;
3034
};
3135

32-
export function validate(
33-
options: BeachballOptions,
34-
validateOptions?: Partial<ValidationOptions>
35-
): { isChangeNeeded: boolean } {
36-
const { allowMissingChangeFiles = false, allowFetching = true } = validateOptions || {};
36+
export function validate(options: BeachballOptions, validateOptions?: ValidationOptions): { isChangeNeeded: boolean } {
37+
const { allowMissingChangeFiles, checkChangeNeeded, checkDependencies } = validateOptions || {};
3738

3839
console.log('\nValidating options and change files...');
3940

@@ -145,8 +146,7 @@ export function validate(
145146

146147
let isChangeNeeded = false;
147148

148-
if (allowFetching) {
149-
// This has the side effect of fetching, so call it even if !allowMissingChangeFiles for now
149+
if (checkChangeNeeded) {
150150
isChangeNeeded = isChangeFileNeeded(options, packageInfos);
151151

152152
if (isChangeNeeded && !allowMissingChangeFiles) {
@@ -161,7 +161,7 @@ export function validate(
161161
}
162162
}
163163

164-
if (!isChangeNeeded) {
164+
if (!isChangeNeeded && checkDependencies && changeSet.length) {
165165
console.log('\nValidating package dependencies...');
166166
// TODO: It would be preferable if this could be done without getting the full bump info,
167167
// or at least if the bump info could be passed back out to other methods which currently

0 commit comments

Comments
 (0)