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

@bob-obringer/conventional-changesets

v0.5.0

Published

Automate the creation of changesets from conventional commits

Downloads

97

Readme

conventional-changesets

This package helps to automate the process of independently bumping semantic versions of multiple packages within a monorepo.

It generates markdown files which can be consumed by the changesets tool. Once the files have been created, changesets can be used to automate the version bumping process.

Features

Automated Changeset Creation

conventional-changesets eliminates the manual effort required to create changesets for each version bump commit. It automatically analyzes the commit messages and generates changeset files in markdown format.

Conventional Commit Support

By following a conventional commit format, conventional-changesets can accurately determine the type of changes made in each commit, such as features, bug fixes, or breaking changes.

Upgrade Type Detection

conventional-changesets intelligently detects the appropriate upgrade type (major, minor, or patch) based on the commit type and the presence of breaking changes. This ensures that the generated changesets accurately reflect the impact of each commit on the project's version.

Multi-Package Support

conventional-changesets was designed for monorepos containing multiple publishable packages. It identifies the specific packages affected by each commit, allowing granular control over the versioning and release process of individual packages within a monorepo setup.

How it works

  • First we collect all the commits between our main and development branches.
  • Parse each commit message using conventional commits to determine the type of change, and we identify which packages were updated in that commit.
  • Generate a changesets markdown file for each commit, listing each package that was updated, the type of semantic version bump required, and the commit message to use as the changelog.

Installation

pnpm install @bob-obringer/conventional-changesets
npm install @bob-obringer/conventional-changesets
yarn add @bob-obringer/conventional-changesets

Usage

This is intended to be run as part of a CI/CD pipeline, but can be run locally or via a script.

This package provides both a CLI and a programmatic interface which take two optional parameters, productionBranch and integrationBranch. The default values are main and develop respectively.

The output is a collection of changeset markdown files sent to a .changeset folder in the root of the repository.

For an example of how it's used, see the .github/workflows/generate-changeset.yml file in this repository.

CLI

npx conventional-changeset -p main -i develop

Typescript

import { generateChangesets } from "@bob-obringer/conventional-changesets";

function generateChangesetsAndDoOtherThings() {
  generateChangesets({
    productionBranch: "main",
    integrationBranch: "develop",
  });
}

Then What?

Once you have the generated changesets files, you can use the changeset CLI to consume them. The CLI will automate the following tasks:

  • Read the changesets files to bump the version for all updated packages
  • Update the changelog for impacted packages
  • Create a PR into your production branch

Once the PR is approved and merged, changeset can be run again to automates another set of tasks:

  • Determines which packages have upgraded versions compared to the latest published version
  • Deploys each of the packages to npm
  • Tags the release version for each package in github

Taking this a step further, you can easily integrate this with your CI/CD pipeline.

Conventional Commit / Semantic Version Mapping

There's currently a hardcoded mapping between conventional commit type and semantic version bump type:

levels = {
  patch: "patch",
  fix: "patch",
  perf: "patch",
  refactor: "patch",
  feat: "minor",
  docs: null,
  test: null,
  ci: null,
  chore: null,
};

Example

Our example assumes a monorepo with 4 packages, A, B, C, and D, all at version 0.0.1

New commits We have a pull request from our integration branch to our production branch that includes the following commits:

| Commit | Changed Packages | Commit Message | | :----: | :--------------: | :---------------------------------------- | | 1 | A | fix: sint occaecat mollit proident | | 2 | B | fix: ad duis quis duis | | 3 | A, C | feat: sunt lorem ex voluptate | | 4 | C, D | docs: non nisi officia ipsum | | 5 | C | feat: aliqua est BREAKING CHANGE: lorem |

New published versions after production release

After running conventional-changesets, releasing to production, and bumping and publishsing with changeset, the packages will have the following versions:

| Package | Version | Why | | :-----: | :-----: | :----------------------------------------------------------------- | | A | 0.1.0 | fix and feat commits, largest bump being feat (minor bump) | | B | 0.0.2 | fix commit (patch bump) | | C | 1.0.0 | feat and docs commit, but with breaking changes (major) | | D | 0.0.1 | docs commit (no version bump) |

Motivation

Over the past few years, monorepo tooling (like Turborepo and nx) have made it feasable to use monorepos for anything beyond the most basic project.

For my own personal needs, one of the remaining holes was the ability to smartly bump versions and publish in a low friction way. changesets solved the smart bumping and publishing part, but it still requires a manual process. I wanted to just use conventional commits and have the rest of the process automated.

When I went looking for a solution, I found that I wasn't the only one.

So I built this package, wired it up to github actions, and stopped worrying about bumping versions and deploying.

Hopefully someday this process could be built directly into our monorepo tools, but for now this solves my existing needs.

TODO:

  • Customizable Configuration: Provide a flexible configuration system that allows you to define the mapping between conventional commit types and upgrade types.