Entry Points

Resolve package entry points.

Usage

var entryPoints = require( '@stdlib/_tools/pkgs/entry-points' );

entryPoints( pkgs, [options,] clbk )

Asynchronously resolves package entry points.

var pkgs = [ 'tape', 'browserify' ];

entryPoints( pkgs, onEntries );

function onEntries( error, entries ) {
    if ( error ) {
        throw error;
    }
    console.dir( entries );
}

Each package is represented by an object having the following fields:

  • id: package identifier.
  • pkg: package name, as specified in pkgs.
  • dir: package directory.
  • entries: an array of package entry points.

The function accepts the following options:

  • dir: root directory from which to resolve packages. May be either an absolute path or a path relative to the current working directory.

By default, the function resolves packages relative to the current working directory. To resolve relative to an alternative directory, set the dir option.

var opts = {
    'dir': '/foo/bar/baz'
};

var pkgs = [ 'tape', 'browserify' ];

entryPoints( pkgs, opts, onEntries );

function onEntries( error, entries ) {
    if ( error ) {
        throw error;
    }
    console.dir( entries );
}

entryPoints.sync( pkgs[, options] )

Synchronously resolves package entry points.

var pkgs = [ 'tape', 'browserify' ];

var entries = entryPoints.sync( pkgs );
// returns [...]

The function accepts the same options as entryPoints() above.

Examples

var resolve = require( 'path' ).resolve;
var entryPoints = require( '@stdlib/_tools/pkgs/entry-points' );

var pkg = resolve( __dirname, '../' );
var pkgs = [ pkg, 'tape' ];

entryPoints( pkgs, onEntries );

function onEntries( error, results ) {
    if ( error ) {
        throw error;
    }
    console.dir( results );
}

CLI

Usage

Usage: pkg-entry-points [options] [<pkg> <pkg> <pkg> ...]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --dir dir             Base directory.
         --split sep           Separator for stdin data. Default: '/\r?\n/'.

Notes

  • If the split separator is a regular expression, ensure that the split option is properly escaped.

    # Not escaped...
    $ echo -n $'tape\nbrowserify\n' | pkg-entry-points --split /\r?\n/
    
    # Escaped...
    $ echo -n $'tape\nbrowserify\n' | pkg-entry-points --split /\\r?\\n/
    
  • Results are printed to stdout as newline-delimited JSON (NDJSON).

Examples

$ pkg-entry-points tape browserify
{...}
{...}
$ echo -n $'tape\nbrowserify\n' | pkg-entry-points --split /\\r?\\n/
{...}
{...}