Skip to content

feat: conditionally format target JSON file after updating version - #27

Open
jorenbroekema wants to merge 1 commit into
hvdb:masterfrom
jorenbroekema:feat/conditionally-format
Open

feat: conditionally format target JSON file after updating version#27
jorenbroekema wants to merge 1 commit into
hvdb:masterfrom
jorenbroekema:feat/conditionally-format

Conversation

@jorenbroekema

Copy link
Copy Markdown

We noticed a user had failing pipelines because simple-versioner is setting the version of their package.json, and later in the same pipeline they run a linting step that verifies that files are prettier formatted.

In simple-versioner, the JSON file is set with JSON.stringify() and 4 spaces indentation, but depending on the user's prettier settings, they may use tabs or different amount of spaces.

I've added a feature that identifies whether the user has a prettier installation and a prettier config is available for the target JSON file that simple-versioner adjusts the version field of. If this is the case, it adds a prettier format command afterwards, to ensure it's formatted according to the user's preferences. This way, pipeline happy :).

Comment thread src/index.spec.ts
delete process.env.BUILD_REASON;
delete process.env.BUILD_SOURCEBRANCH;
delete process.env.BUILD_SOURCEVERSION;
process.argv = [];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we weren't cleaning this up properly so my added test was failing at the end of the file but succeeding if I put it at the top of the file.

Comment thread src/index.spec.ts
setup('Ci Individual', 'refs/heads/master', '1c2abf44a3b28c5f4385d95b9f3fe83a1af94397', '0.0.1');

try {
const result = simpleVersioner();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Comment thread src/index.ts
jsonFile.version = version;
fs.writeFileSync(filePath, JSON.stringify(jsonFile, null, 4));
if (shouldRunPrettier(filePath)) {
// log it, actually useful if the user is aware that prettier was ran on the file that we updated

@jorenbroekema jorenbroekema Jul 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not just that, also makes it easy to verify in a test with a mock that prettier was ran 😅 without actually running prettier, by spying on the log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant