hunt-affected

Detect where your file exports are used and potentially afffected by it's changes.

Usage no npm install needed!

<script type="module">
  import huntAffected from 'https://cdn.skypack.dev/hunt-affected';
</script>

README

hunt-affected

Detect where your file exports are used and potentially afffected by it's changes.

Quick start

Intalling via npm:

npm i hunt-affected

And feed the function with a list of absolute file paths you would like to check, and the entry points like this:

const huntAffected = require('hunt-affected');

huntAffected(['a.js', 'b.js', 'c.js'], [{ source: 'a.js', name: 'default' }]);

Following @babel/parser plugins are enabled on .js|.jsx|.ts|.tsx files by default:

  • dynamicImport
  • classProperties
  • flowComments
  • objectRestSpread
  • functionBind
  • jsx
  • flow (.js and .jsx only)
  • typescript (.ts and .tsx only)

Other than aboves, you will need to enable by:

huntAffected(
  ['a.js', 'b.js', 'c.js'],
  [{ source: 'a.js', name: 'default' }]
  {
    parserOptions: {
      plugins: ['jsx', 'dynamicImport']
    }
  }
);

All the options in parserOptions will be passed to @babel/parser directly. @babel/parser options can be found here.

By default, it will try to read file with NodeJs default file system and decode them with utf-8.

You may replace this behavior by passing a customised loader function:

huntAffected(
  ['a.js', 'b.js', 'c.js'],
  [{ source: 'a.js', name: 'default' }]
  {
    loader: async (path) {
      return await myWayToReadFile(path);
    }
  }
);

And when it tries to resolve file imported module paths to absolute file path, it will use Webpack's enhanced-resolve by default, and tries to resolve to real files.

You may replace this behavior by passing a customised resolver function:

huntAffected(
  ['a.js', 'b.js', 'c.js'],
  [{ source: 'a.js', name: 'default' }]
  {
    resolver: async (base: string, target: string) => {
      return 'resolved/file/path.js';
    }
  }
);