filter-dependent
TypeScript icon, indicating that this package has built-in type declarations

2.2.3 • Public • Published

Filters a list of files, leaving only those which transitively dependent on any of the files from the second list.

Why this package was written?

Because I can! But also, because I failed to find anything like that, except jest-resolve-dependencies, which is not exactly what I need, and also have not very good algorithmic complexity (btw mine is O(n), where n is a number of nodes in a dependency graph fragment between sources and targers).

What problem it solves?

Similiar to changedSince – it allows you to find all files dependent from other files. And, therefore, skip other files.

For example, you can:

  1. Find all test files, which affected by git changeset, and should be running.
  2. Find all affected .stories.js files to build storybook only with affected components.

By doing that, you skip non-affected files and speed up your CI/build.

Features

  1. Supports js, jsx, ts, tsx.
  2. Fast.
  3. Resolves all symlinks to real filenames.
  4. Skip node_modules by default.

Example

Lets say we have four files:

  1. a.js depends on b.js and c.js
  2. b.js depends on d.js

Then:

import filterDependent from 'filter-dependent'

const filteredFiles = filterDependent([
    './a.js',
    './b.js',
    './c.js',
    './d.js',
], [
    'a.js',
    'c.js',
])

// → ['/abs/path/to/a.js', '/abs/path/to/b.js', '/abs/path/to/c.js']
// because `d.js` does not depend on `c.js` nor `a.js`

API

import filterDependent from 'filter-dependent'

const filteredFiles = filterDependent(sources, targets, options)

Where

sources – an array of file paths to be filtered. targets – an array of file paths to be used for filtering out sources. options.filter – function, which will be called on each found file (including sources and targers) to filter out some. (f: string) => f.indexOf('node_modules') === -1 && !f.endsWith('.css') by default. options.onMiss – function, which will be called instead of throwing an error. Arguments are: filename and dep – absolute path of processing file and unresolved dependendy in it

note: filter-dependent fails on first unresolved dependency (by default).

Readme

Keywords

none

Package Sidebar

Install

npm i filter-dependent

Weekly Downloads

89

Version

2.2.3

License

MIT

Unpacked Size

34.7 kB

Total Files

16

Last publish

Collaborators

  • diokuz