Find Packages

Find packages.

Usage

var findPkgs = require( '@stdlib/_tools/pkgs/find' );

findPkgs( [options,] clbk )

Asynchronously search for packages.

findPkgs( onPkgs );

function onPkgs( error, pkgs ) {
    if ( error ) {
        throw error;
    }
    console.log( pkgs.join( '\n' ) );
}

The function accepts the following options:

  • dir: root directory from which to search for packages. May be either an absolute path or a path relative to the current working directory. Default: current working directory.
  • pattern: glob pattern used to find packages. Default: '**/package.json'.
  • ignore: list of glob patterns used to exclude matches.

To search from an alternative directory, set the dir option.

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

findPkgs( opts, onPkgs );

function onPkgs( error, pkgs ) {
    if ( error ) {
        throw error;
    }
    console.log( pkgs.join( '\n' ) );
}

By default, the implementation searches for packages by finding package.json files. To provide an alternative include filter, set the pattern option.

var opts = {
    'pattern': '**/foo/**/package.json'
};

findPkgs( opts, onPkgs );

function onPkgs( error, pkgs ) {
    if ( error ) {
        throw error;
    }
    console.log( pkgs.join( '\n' ) );
}

To exclude matches, set the ignore option.

var opts = {
    'ignore': [
        'node_modules/**',
        'build/**',
        'reports/**'
    ]
};

findPkgs( opts, onPkgs );

function onPkgs( error, pkgs ) {
    if ( error ) {
        throw error;
    }
    console.log( pkgs.join( '\n' ) );
}

findPkgs.sync( [options] )

Synchronously searches for packages.

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

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

Examples

var findPkgs = require( '@stdlib/_tools/pkgs/find' );

findPkgs( onPkgs );

function onPkgs( error, pkgs ) {
    if ( error ) {
        throw error;
    }
    console.log( pkgs.join( '\n' ) );
}

CLI

Usage

Usage: find-pkgs [options] [<dir>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --pattern pattern     Inclusion glob pattern.
         --ignore pattern      Exclusion glob pattern.

Notes

  • If not provided a dir argument, the current working directory is the search directory.

  • To provide multiple exclusion glob patterns, set multiple --ignore option arguments.

    $ find-pkgs --ignore=node_modules/** --ignore=build/** --ignore=reports/**
    

Examples

$ find-pkgs
<package_path>
<package_path>
...