Socket
Socket
Sign inDemoInstall

is-affected

Package Overview
Dependencies
176
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    is-affected

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


Version published
Maintainers
1
Created

Readme

Source

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.

FAQs

Last updated on 30 Aug 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc