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

@hkdobrev/run-if-changed

v0.6.3

Published

Run a command if a file changes via Git hooks

Downloads

19,092

Readme

🔃 run-if-changed npm version

Run a command if a file changes via Git hooks. Useful for lock files or build systems to keep dependencies and generated files up to date when changing branches, pulling or commiting.

Inspired by lint-staged and recommended to be used with husky.

State of the project

run-if-changed is functional as-is, but it's still quite basic and rough as it has just been published. So issues, feature requests and pull requests are most welcome!

Installation and setup

Set up Git hooks

Why

The use case for run-if-changed is mostly for a team working on a project and push and pull code in different branches. When you share dependencies, database migrations or compilable code in the shared Git repository often some commands need to be run when a file or folder gets updated.

Check out the common use cases.

Configuration

  • run-if-changed object in your package.json
  • .run-if-changedrc file in JSON or YML format
  • run-if-changed.config.js file in JS format

See cosmiconfig for more details on what formats are supported.

Configuration should be an object where each key is a file or directory match pattern and the value is either a single command or an array of commands to run if the file have changed since the last Git operation.

What commands are supported?

Supported are any executables installed locally or globally via npm or Yarn as well as any executable from your $PATH.

Using globally installed scripts is discouraged, since run-if-changed may not work for someone who doesn't have it installed.

run-if-changed is using execa to locate locally installed scripts and run them. So in your .run-if-changedrc you can just write and it would use the local version:

Sequences of commands are supported. Pass an array of commands instead of a single one and they will run sequentially.

Use cases

Install or update dependencies when lock file changes

If you use a dependency manager with a lock file like npm, Yarn, Composer, Bundler or others, you would usually add a dependency and the dependency manager would install it and add it to the lock file in a single run. However, when someone else has updated a dependency and you pull new code or checkout their branch you need to manually run the install command of your dependency manager.

Here's example configuration of run-if-changed:

package.json

.run-if-changedrc

package.json

.run-if-changedrc

package.json

package.json

Run database migrations if there are new migrations

If you keep database migrations in your repository, you'd usually want to run them when you check out a branch or pull from master.

package.json

Compile sources in a build folder after pulling new code.

package.json