List package dependencies.
var pkgDeps = require( '@stdlib/_tools/modules/pkg-deps' );Asynchronously lists package dependencies.
pkgDeps( __filename, clbk );
function clbk( error, results ) {
if ( error ) {
throw error;
}
console.dir( results );
}The first argument may be either a file path string (either relative or absolute) or an array of file paths. If provided a relative file path, the path is resolved relative to the current working directory.
pkgDeps( [ __filename, __filename ], clbk );
function clbk( error, results ) {
if ( error ) {
throw error;
}
console.dir( results );
}Each file is represented by an object having the following fields:
- file: file name.
- deps: an
arrayof package dependencies.
The function accepts the following options:
- builtins:
booleanindicating whether to include built-in package dependencies. Default:true. - walk:
booleanindicating whether to walk relative module dependencies. Default:true. - aliases:
objectmapping relative module dependency identifiers to other module identifiers (e.g., mapping non-browser-compatible modules to browser-compatible modules). When a module identifier resolves to the same path as an object key, the associated object value is substituted for the original identifier, and the function walks the substituted module in place of the original module. Relative module identifiers are resolved relative to the provided file paths.
By default, the function walks relative module dependencies to resolve both primary and secondary package dependencies. To only resolve a file's direct package dependencies, set the walk option to false.
var opts = {
'walk': false
};
pkgDeps( __filename, opts, clbk );
function clbk( error, results ) {
if ( error ) {
throw error;
}
console.dir( results );
}Synchronously lists package dependencies.
var results = pkgDeps.sync( __filename );
// returns [...]The function accepts the same options as pkgDeps() above.
var join = require( 'path' ).join;
var pkgDeps = require( '@stdlib/_tools/modules/pkg-deps' );
var file = join( __dirname, 'lib', 'index.js' );
pkgDeps( file, clbk );
function clbk( error, results ) {
if ( error ) {
throw error;
}
console.dir( results );
}Usage: module-pkg-deps [options] [<file> <file> <file> ...]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--no-builtins Do not include built-ins.
--no-walk Do not walk relative module dependencies.
--split sep Separator for standard input data. Default: '/\r?\n/'.
-
If the split separator is a regular expression, ensure that the
splitoption is properly escaped.# Not escaped... $ echo -n $'file1\nfile2\n' | module-pkg-deps --split /\r?\n/ # Escaped... $ echo -n $'file1\nfile2\n' | module-pkg-deps --split /\\r?\\n/
-
Results are printed to
stdoutas newline-delimited JSON (NDJSON).
$ module-pkg-deps /foo/bar/baz
{...}$ echo -n $'/foo/bar/baz\n/beep/boop/bop\n' | module-pkg-deps --split /\\r?\\n/
{...}
{...}