From c1841ab53c1efcfe23e006ef6411d2c5f08e4245 Mon Sep 17 00:00:00 2001 From: Tajudeen Oyindamola Tajudeen <46614028+Pterjudin@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:05:52 +0000 Subject: [PATCH] Update check-is-release.ts The refactor improves readability and maintainability by extracting process.cwd() and the package JSON path into constants to reduce repetition. Error handling is enhanced with a more descriptive error message, providing better context for debugging. The redundant if/else logic for writing "true" or "false" to Bun.stdout is streamlined into a ternary operator for conciseness. Optional chaining is introduced to safely access releasePlan.releases, preventing potential runtime errors if the object structure is undefined. Finally, a JSDoc comment is added to clearly document the function's purpose and behavior, making the code more understandable for future contributors. --- scripts/check-is-release.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/check-is-release.ts b/scripts/check-is-release.ts index 9c252fc6..c6ffd539 100644 --- a/scripts/check-is-release.ts +++ b/scripts/check-is-release.ts @@ -1,22 +1,27 @@ import getReleasePlan from '@changesets/get-release-plan'; -/** Check if a "next" / development release is necessary based on the presence of changesets */ +/** + * Checks if a "next" or development release is necessary based on the presence of changesets. + * Outputs "true" or "false" to stdout. + */ async function checkIsRelease() { - const releasePlan = await getReleasePlan(process.cwd()); + const currentDir = process.cwd(); + const packageJsonPath = `${currentDir}/cli/package.json`; try { - const packageJson = await Bun.file(process.cwd() + '/cli/package.json').json(); - const newNextVersion = releasePlan.releases.find((release) => release.name === packageJson.name)?.newVersion; + const releasePlan = await getReleasePlan(currentDir); + const packageJson = await Bun.file(packageJsonPath).json(); - if (newNextVersion == null) { - await Bun.write(Bun.stdout, 'false\n'); - } else { - await Bun.write(Bun.stdout, 'true\n'); - } + const newNextVersion = releasePlan?.releases?.find( + (release) => release.name === packageJson.name + )?.newVersion; + + await Bun.write(Bun.stdout, `${newNextVersion != null}\n`); } catch (error) { - console.log(error); + console.error('Error during release check:', error); process.exit(1); } } +// Run the release check await checkIsRelease();