npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

compare-git-tag-and-package-version

v1.0.10

Published

Package for compare latest Git Tag and version in package.json

Downloads

6

Readme

Package to compare tags in package.json and in repository branch

The main reason for creating this package is forgetting to add a new tag after updating the version in package.json

Install package

yarn add -D "compare-git-tag-and-package-version"
npm i -D "compare-git-tag-and-package-version"

Create tags-compare-config.js in the project root directory.

/* 
* Since version 1.0.8 this step can be skipped.
* Default is to use package.json to get package name and version.
* But if you want to beautify the output, you can create this configuration file.
*/
const appName = "AppName";
const { version: appVersion } = require("./package.json");

module.exports = {
    appName,
    appVersion
}

Add new command to package.json in script section

{
  "scripts" : {
    "compare-tags": "compare-tags",
    "bump": "npm version patch -m 'AppName version updated to v%s'",
    "bump:minor": "npm version minor -m 'AppName version updated to v%s'",
    "bump:major": "npm version major -m 'AppName version updated to v%s'"
  }
}

Output examples

INFO: Application name: AppName
INFO: Application version: v1.0.4
INFO: Tag comparison test passed successfully!
INFO: Application name: AppName
INFO: Application version: v1.0.4
ERROR: 
  The version in the package v1.0.4 doesn't match the last tag v1.0.3
  HOW TO FIX:
  1. Rebase to the release or master branch, and try again.
  2. Add the tag with "git tag -a v1.0.4 -m 'AppName version bump v1.0.4'" command
  3. Launch following scripts to add version automatically:
    a) yarn bump - to upgrade the patch version,
    b) yarn bump:minor - to upgrade the minor version,
    c) yarn bump:major - to upgrade the major version        

How to use

First of all install husky package and follow all setup instructions.

More information about husky setup

Create 'pre-push' hook

npx husky add .husky/pre-push "compare-tags"

In the next step, you can modify the hook for more information, as in the following example.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn compare-tags ||
(
    echo "❌❌ The version in the package.json doesn't match the latest tag! ❌❌";
    echo "❌❌ Push command terminated! See the information above how to solve this problem! ❌❌";
    false;
)

# If everything passes... Now we can push
echo '✅✅✅✅ You win this time... I am committing this now. ✅✅✅✅'