Function for reading file content from absolute file path. Uses fs.readFileSync to read with decoding utf8 by default.
Options provided by @babel/parser
. Allow customize babel parser options while parsing file content to AST.
Customised resolver function to resolve a module import path to absolute file path. If this options is used, resolverOptions
will be ignored.
enhanced-resolver options
Get a file's dependency map
Absolute file path
Find a list of module exports affected by given module exports in given list of files. Example:
huntAffected(
['a.js', 'b.js', 'c.js'],
[{ source: 'a.js', name: 'default' }]
);
Avaiable options:
((base: string, target: string) => Promise<string | void>) | undefined
Loader | undefined
Source file absolute paths
A list of entry objects with source file absolute path, and export declaration name
Options
A promise resolves to a key, value pair, key is an absolute path of a module, value is a Set of declaration names
Extract the dependency map of a list of source files.
A list of absolute source file paths
Walk through the dependency map from given entries to find out what are affected.
Generated using TypeDoc
hunt-affected
Detect where your file exports are used and potentially afffected by it's changes.
Quick start
Intalling via npm:
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'; } } );