Skip to content

Commit

Permalink
Exit with an error on invalid change files (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 authored Sep 10, 2024
1 parent 70e438c commit f313e50
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
7 changes: 7 additions & 0 deletions change/beachball-d1d64636-b7a3-490c-80a1-af0e305a05ca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Exit with an error on invalid change files",
"packageName": "beachball",
"email": "[email protected]",
"dependentChangeType": "patch"
}
46 changes: 23 additions & 23 deletions src/validation/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,6 @@ export function validate(
hasError = true; // the helper logs this
}

if (hasError) {
// If any of the above basic checks failed, it doesn't make sense to check if change files are needed
process.exit(1);
}

let isChangeNeeded = false;

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

if (isChangeNeeded && !allowMissingChangeFiles) {
logValidationError('Change files are needed!');
console.log(options.changehint);
process.exit(1); // exit here (this is the main poin)
}

if (options.disallowDeletedChangeFiles && areChangeFilesDeleted(options)) {
logValidationError('Change files must not be deleted!');
process.exit(1);
}
}

const changeSet = readChangeFiles(options, packageInfos);

for (const { changeFile, change } of changeSet) {
Expand All @@ -161,6 +138,29 @@ export function validate(
}
}

if (hasError) {
// If any of the above basic checks failed, it doesn't make sense to check if change files are needed
process.exit(1);
}

let isChangeNeeded = false;

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

if (isChangeNeeded && !allowMissingChangeFiles) {
logValidationError('Change files are needed!');
console.log(options.changehint);
process.exit(1); // exit here (this is the main poin)
}

if (options.disallowDeletedChangeFiles && areChangeFilesDeleted(options)) {
logValidationError('Change files must not be deleted!');
process.exit(1);
}
}

if (!isChangeNeeded) {
console.log('\nValidating package dependencies...');
// TODO: It would be preferable if this could be done without getting the full bump info,
Expand Down

0 comments on commit f313e50

Please sign in to comment.