Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

filter-dependent

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter-dependent

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

latest
npmnpm
Version
2.2.3
Version published
Weekly downloads
29
-59.72%
Maintainers
1
Weekly downloads
 
Created
Source

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:

  • Find all test files, which affected by git changeset, and should be running.
  • 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

  • Supports js, jsx, ts, tsx.
  • Fast.
  • Resolves all symlinks to real filenames.
  • Skip node_modules by default.

Example

Lets say we have four files:

  • a.js depends on b.js and c.js
  • 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).

FAQs

Package last updated on 16 Jun 2021

Did you know?

Socket

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