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

semver-sync

v1.3.0

Published

Utility that keeps version numbers in sync between package.json, component.json and an optional source file.

Downloads

48

Readme

This is package is no longer maintained - check out versync for a more up-to-date replacement!

semver-sync

semver-sync is a node.js module that enables you to synchronize version numbers accross package.json, component.json and other source files of your choosing.

Build Status

Installation

You can install it via npm:

npm install -g semver-sync

How to use it

This utility uses package.json as the reference by which all other version numbers in the package are checked. If you don't have a package.json in the folder where you run it, it will give an error and break.

The utility automatically checks package.json and component.json. If you have other JavaScript sources or JSON files that hold your version number first edit the package.json, adding the versionedSources property:

{
  "name": "mypackage",
  "version": "1.2.3",
  "versionedSources": "mypackage.js"
}

Once that's done, you can check that everything's ok:

semver-sync -v
[OK] Everything is in sync, with version number 1.2.3

If you accidentally change the version number in one of the sources, or forget to update it, you'll see an error:

semver-sync -v
[ERROR] Version number is out of sync in component.json, mypackage.js.

If you want to update the version number automatically in all the files, you can do:

semver-sync -b
[OK] Version number was updated to 1.2.4 in package.json, component.json, mypackage.js.
semver-sync -b patch
[OK] Version number was updated to 1.2.5 in package.json, component.json, mypackage.js.
semver-sync -b minor
[OK] Version number was updated to 1.3.0 in package.json, component.json, mypackage.js.
semver-sync -b major
[OK] Version number was updated to 2.0.0 in package.json, component.json, mypackage.js.
semver-sync -b 3.0.0-alpha1
[OK] Version number was updated to 3.0.1-alpha1 in package.json, component.json, mypackage.js.
semver-sync -b 3.0.0-beta2
[OK] Version number was updated to 3.0.1-beta2 in package.json, component.json, mypackage.js.
semver-sync -b 3.0.0-rc1
[OK] Version number was updated to 3.0.1-rc1 in package.json, component.json, mypackage.js.

If you want to update the version number automatically in all the files, commit the changes and create a new git tag, you can do:

semver-sync -t
[OK] Version number was updated to 1.2.4 in package.json, component.json, mypackage.js.
[OK] Files have been commited and tag v1.2.4 was created.

How it works

The module uses UglifyJS 2 to create an AST of the JavaScript and JSON sources passed in. This approach is more flexible than matching strings or trying to find version numbers in source files.

The AST patterns used to find the nodes which hold the version properties are in the patterns.js source file. It should work on most types of structures, if you find one that doesn't please log an issue. The module has automated tests for this pattern matching, using some real-life libraries and it seems to work pretty well.

To check and bump the version number, the module uses the node-semver package.

The binary uses node-optimist to parse the input options. Unfortunately, there are no automated tests for it yet, so please log any issues that you encounter.

Console help

Usage: semver-sync -s [source list] -b [release type].

Options:

  • -b, --bump Bump the version number in package.json, component.json and all other specified source files. It can take one of the following values: major, minor, patch. Alternatively you can specify a custom version that is higher than the current one. If no value is specified, it defaults to patch.
  • -v, --verify Verifies that package.json, component.json and all other source files have the same version number and checks if it conforms to the semver specification.
  • -s, --sources Declare additional files in which the version number will be updated or checked. If not explicitly specified, it is read from the package.json "versionedSources" property. If it's not present in the package.json and not explicitly specified, only component.json and package.json will be synced.
  • -t, --tag Bump the version number, commit the changes to package.json, component.json and all other specified source files and create a git tag with the current version. It can take one of the following values: major, minor, patch. Alternatively you can specify a custom version that is higher than the current one. If no value is specified, it defaults to patch.

License

This package is released under the MIT License.