Skip to content

Conversation

@SinghCod3r
Copy link
Contributor

Hi! This PR adds a feature to notify users when a new version of cht-conf is available.

This resolves issue #390.

@jkuester jkuester self-requested a review August 8, 2025 17:26
@jkuester
Copy link
Contributor

jkuester commented Aug 8, 2025

I see you have committed some changes to the package-lock.json file, but no changes to the package.json. Was this on purpose?

Typically, if you are not making any changes to the package.json file, you can just build the project with the npm ci command instead of running npm install (which will automatically update the package-lock.json.

If you did need any changes package-lock.json file, please revert the changes to that file.

@SinghCod3r SinghCod3r force-pushed the feature/version-notifier branch from 9f8f797 to be74b09 Compare August 9, 2025 02:04
@SinghCod3r
Copy link
Contributor Author

"Thanks for the feedback! I've reverted the package-lock.json changes and cleaned up the commits." Please Check it again and let me know if any other issue is there still exists.

@SinghCod3r SinghCod3r force-pushed the feature/version-notifier branch from be74b09 to 0fd8520 Compare August 14, 2025 06:54
Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

This is great @SinghCod3r! It works as expected! Forgive me, but I am going to make a couple more feature requests here (seems like as long as we are going to bring this feature back, we should make it as good as possible).

In the check-for-updates library code the nonFatal option is not really being used effectively (the outcome is almost identical either way). Essentially the nonFatal option just indicates if the check is being made by the run-by-default logic (in which case nonFatal = true) or if the user explicitly specified the check-for-updates action (in which case nonFatal = undefined). My goal is that when the user requests the check-for-updates action, it guarantees that the user is running the latest version or the command should fail.

The changes I think we should make here are:

  • In the catch block, we can simplify the logic to always print a warning with the error message. Then, if the user actually requested the check-for-updates action (!options.nonFatal), we should throw the error. This will ensure that the cht command ends with a non-zero status code in this case.
  • Then we can split the current then block. We should unpack the response data before the catch. Then, after the catch we have another then block that can print the results to the console and throw an error if the user is not running the latest version AND the user requested the check-for-updates action.

Putting it all together, I think it would be something like this (have not tested this code 😅):

  return request
    .get('https://registry.npmjs.org/cht-conf')
    .then(res => {
      const json = JSON.parse(res);
      return json['dist-tags'].latest;
    })
    .catch(err => {
      warn(`Could not check NPM for updates: ${err.message}`);
      if (!options.nonFatal) {
        throw err;
      }
    })
    .then(latest => {
      if (latest !== current) {
        warn(`New version available!

      ${current} -> ${latest}

   To install:

     npm install -g cht-conf
    `);
        if (!options.nonFatal) {
          throw new Error('You are not running the latest version of cht-conf!');
        }
      } else if (!options.nonFatal) {
        info('You are already on the latest version :¬)');
      }
    });

And finally, the last thing would be to add unit tests, both for the check-for-updates lib code and the logic in the main block so that hopefully we can avoid regressing on this again in the future! 😬

@SinghCod3r SinghCod3r force-pushed the feature/version-notifier branch from 9d8b741 to 92f358c Compare August 15, 2025 05:20
@SinghCod3r
Copy link
Contributor Author

@jkuester Thanks for the feedback! I've updated the logic and added the help text as you requested. Please let me know what you think.

@SinghCod3r SinghCod3r requested a review from jkuester August 17, 2025 18:31
@SinghCod3r
Copy link
Contributor Author

@jkuester , I've added the unit tests as you requested. They are passing locally. Thanks!

Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

The implementation code is looking good here! 👍 Added some comments around the unit tests.

src/cli/usage.js Outdated
Skips checking the version running is set to the same version in the package.json
--skip-version-check
Skip the automatic check for new cht-conf versions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Skip the automatic check for new cht-conf versions.
Skips the automatic check for new cht-conf versions

Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this file should be check-for-updates.spec.js. (With the current name, this file is not getting run as part of the npm run test command.)

Copy link
Contributor

Choose a reason for hiding this comment

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

While it is fine to use AI when producing code for a contribution, this code needs to adhere to the same standards/conventions as the rest of the codebase.

For this file, please:

  • Clean-up/remove comments (most of these seem completely unnecessary)
  • Make sure we are following similar testing conventions as the other files. (e.g. the convert-forms.spec.js).
  • Make sure the tests actually pass! 😅 These tests are not passing for me. (And CI will not run them because of the invalid file name.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jkuester I've addressed all the feedback: the logic is updated, the help text is added, and the new unit tests are now passing locally. Please let me know if there's anything else!

Note - @jkuester, i have checked the test locally and it is perfect for my section of code. i request you to review the code as you got the time.
i also changed the code of check-for-updates.js file.

@SinghCod3r SinghCod3r force-pushed the feature/version-notifier branch from cc1d3ae to 3171d46 Compare August 23, 2025 03:26
@SinghCod3r SinghCod3r requested a review from jkuester August 23, 2025 03:34
@sugat009 sugat009 linked an issue Aug 27, 2025 that may be closed by this pull request
1 task
Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

Very nice! The only thing left is to fix a couple minor linting problems and add one more test. Then we can get this merged!

@mrjones-plip
Copy link
Contributor

Thanks for checking in! Great job on getting E2E tests passing \o/

I'll see if @jkuester is free to review your changes, but in the meanwhile, can you ensure CI is passing? I see there's some lint failures that need fixing.

@jkuester jkuester changed the title feat: Add notifier for new cht-conf versions fix(#390): notify user of new cht-conf versions Aug 27, 2025
@SinghCod3r SinghCod3r force-pushed the feature/version-notifier branch from e7161cf to 6fd7427 Compare August 27, 2025 19:25
@SinghCod3r SinghCod3r force-pushed the feature/version-notifier branch from 6fd7427 to 8a2bf89 Compare August 27, 2025 19:30
@SinghCod3r
Copy link
Contributor Author

SinghCod3r commented Aug 27, 2025

@mrjones-plip Thanks for the heads up! I've run the linter and pushed the fixes. i want you to review this please and make it merged . just wanna be a contributor.

Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @SinghCod3r for sticking with this!

@jkuester jkuester merged commit 9d36c21 into medic:main Aug 27, 2025
6 checks passed
@medic-ci
Copy link
Collaborator

🎉 This PR is included in version 5.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mrjones-plip
Copy link
Contributor

2nd @jkuester's comment - thanks a bunch @SinghCod3r, great to see contributions like this get merged \o/

@SinghCod3r
Copy link
Contributor Author

@jkuester , @medic-ci , @mrjones-plip , Thankyou all for guiding me to complete this. Thankyou all once again.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notify user when a newer version of cht-conf exists

4 participants