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

patch-commits

v0.1.6

Published

Patch all commits on a branch with given script

Downloads

6

Readme

patch-commits

Patch all commits to have desired changes in a branch

This script allows you to go to each commits on a branch and run a script on each commits to have desired changes.

Installation

npm install -g patch-commits

Usage

patch-commits --against branchName/commitHash --with "script"

Options

--against (required): branch name or commit hash against which you are planning to patch. This is used to find commit difference between a branch / commit to the latest commit on your current branch.

--with (required): script you want to run on all commits.

Getting diff files

You can get the diff files of a commit so you only run a script on only those files. You can pass a js expression which will return the diff files in the format you are expecting.

patch-commits --against master --with "eslint --fix {{committedFiles.filter(file => file.endsWith('.js')).join(' ')}}"

Inside the expression you will get committedFiles as an array, in which you can apply any transformation. You should always convert it to a string which can be used with your script. In the above example we want to filter only js files and join them with space separator. So effectively following code will run.

eslint --fix dir/file1.js dir/file2.js dir2/file3.js

The expression can be as simple as

{{committedFiles.join(' ')}}

This is very helpful when you want to rebase from a branch where you applied some codemod, and you are getting a lot of conflicts while rebase because codemod has updated same lines which you have changed on your branch.

Example

Imagine a scenario when you are working a feature on branch which is branched out from master and you have a lot of commits on your branch. You have defined some new rules in eslint and applied eslint auto fix on master branch. And now you want to rebase your branch from master. Even if you have applied eslint auto fix on your branch rebase will replay all the commits on top of master, and might give you conflicts on each commit if there is changes on the same line where eslint auto fix have updated the code.

With this script you can patch all the commits to have eslint auto fix applied, so while replaying commits it will not report conflict on auto fixed code as master's top commit and your commit have same auto fixed code.

Here's the script you will need to run before rebase

patch-commits --against master --with "git checkout master -- .eslintrc && yarn eslint --fix {{committedFiles.filter(file => file.endsWith('.js')).join(' ')}}"

In the above script for every commit we are checking out eslintrc file from master and then applying eslint -fix for all committed/changed files.

After running this you can go ahead with normal rebase. And you will get less conflicts.

git rebase master

Notes

While this script applies transformation on temporary branch and then apply the changes on current branch once everything is successfully finished, but you should make a backup branch from the current branch or push the commits on origin. Reflog will also help but as the script runs a couple of git branch it will be hard to find the correct head which you would want to reset on.

Support

  • Mention what all you can do with this script. Add some examples.
  • :star: this repo