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

affected-files

v4.2.2

Published

Retrieves all files which affected in current git branch

Downloads

15

Readme

Returns a list of js/ts(x) files, which affected in current branch compared to mergeBase (origin/master by default).

CLI

$ npm run afiles
// or
$ yarn afiles

Affected files: (modified, **affected only**)

  **__tests__/common.spec.ts**
  affected-files.config.js
  bin/cli.js
  src/index.ts
  src/options.ts
  src/types.ts

total: 6

Done in 0.82s.

Explanation

Lets say you have a repo with files

a.js
dependent-from-a.js
dependent-from--dependent-from-a.js
not-dependent-from-a.js

If a.js was modified in your merge request, files dependent-from-a.js and dependent-from--dependent-from-a.js also affected. So, affected-files will return

[ 'a.js', 'dependent-from-a.js', 'dependent-from--dependent-from-a.js' ]

Extensions

.js, .jsx, .ts, .tsx are supported. Other extensions – not yet.

Configuration

import getAffected from 'affected-files'
// import { getAffectedSync } from 'affected-files'

const affected = await getAffected(options)

All options are optional.

| Option | default | description | | ------------- |:------------- |:----- | | mergeBase | origin/master | Branch or revision which will be used to take a git diff. | | cwd | process.cwd() | Absolute path of cwd folder, where to find files. | | missing | [] | An array of strings, which should not be resolved. For example, in most cases there is no need to resolve react. Used for perfprmance optimization. Also, it could be used in tuple form filename.js ≥≥≥ ../dependency, which disables ../dependency resolving only in filename.js. | | pattern | **/* | Glob pattern of your source files. | | modified | git diff ... | An array of modified files paths. By default it is evaluated from git ls-files relative to mergeBase, but you could define custom modified array. | | usink | [] | An array of glob patterns of files, which considered as universal sink in dependency graph. That means, every tracked file in your repo is dependent from every usink file. For example, you need to build full storybook every time you have affected something in ./.storybook. Then just use getAffected(pattern, { usink: '.storybook/*' }). Note: every usink must match pattern | | tracked | git ls-tree ... | An array of files, which would be used for dependency tree building. E.g. files in node_modules are not participating in dependency traversing. Note: by default untracked but non-ignored files are included. | | absolute | false | If true, returns absolute paths of affected files, relative to options.cwd otherwise. | | dot | false | If true, includes folders and files, starts with dot. | | pmodified | [] | Permanently modified files. An array of filenames, which must be considered as modified. Note: files, dependent from pmodified-files, will be also considered as affected permanently. Also, pmodified-files are taken only from tracked-files. |

affected-files.config.js

Place this file in the project root folder (cwd), and export your options.

Get all dependent files from single file

yarn afiles src/options.ts

custom modified: src/options.ts
affected files (modified, **affected only**):

  **__tests__/common.spec.ts**
  src/index.ts
  src/options.ts

total: 3

Using in CI

  1. affected-files uses git, so, be sure, git is available in docker image
  2. affected-files uses origin/master revision to compare, so, be sure a) origin/master is exists on runner b) origin/master is up to date.

git fetch && git rev-parse origin/master – that cmd resolves all problems, or fail otherwise. Use it before using affected-files.

If git is not available only on some docker images, you could save affected list to file and use it everywhere in CI via artifacts.