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

is-affected

v1.0.2

Published

Build optimisation tool to run commands on feature branches only if they affect files matching a given glob.

Downloads

11

Readme

is-affected

Build optimisation tool to run commands on feature branches only if they affect files matching a given glob.

Cloud Build

CLI

Usage: is-affected [options]

runs command only if the git diff since the fork point from master branch contains files matching glob

Options:
  -V, --version           output the version number
  --pattern [pattern...]  provide one or more patterns to check file paths from git diff against
  --repo <repo>           git directory (default: "./")
  --cmd <cmd>             the command to be run if diff matches glob
  --cwd <cwd>             working directory to be used to run command
  --main <mainBranch>     name of the main branch of your repo, used when no --since is provided to find the merge base commit (default: "origin/master")
  --since <since>         commit to diff with
  -h, --help              display help for command

Example

To run npm run build only if the git diff between your current branch head and the base commit on the master branch contains files matching glob app/client/**.

npx is-affected app/client/** --cmd "npm run build" --cwd "app/client"

Javascript API

const { isAffected, exec } = require("is-affected");

const build = async () => {
	const shouldBuild = await isAffected(
		"app/client/**",
	);

	if (shouldBuild) {
		await exec("npm run build", "app/client");
	}
};

build();

or with options object (using defaults here):

const shouldBuild = await isAffected(
		"app/client/**", // see match patterns below
		{
			repo: "./",
			cmd: "npm run build",
			cwd: process.cwd(),
			mainBranch: "origin/master",
			since: undefined,
		},
	);

Match patterns

A match means that the git diff contains paths that match the pattern and your code is 'affected'.

Negated pattern

You can use a negated pattern: !src/scripts

This will ignore changes in the src/scripts folder. If your diff contains only changes in src/scripts then your code will not be marked as 'affected'.

Multiple patterns

A normal pattern (aka non negated) will add paths to the match list. Negated patterns will remove paths from the list. Your code is 'affected' when the list is not empty after the last pattern has been evaluated.

const shouldBuild = await isAffected([
    	'src/**',
    	'!src/tests/**',
]);

or using cli:

npx is-affected src/** !src/tests/**

Note that if your shell is automatically expanding glob patterns you should escape the asterix:

npx is-affected src/\** !src/tests/\**

The above example will monitor all paths in the src folder except for those in the tests subfolder.