resolve-dep

Return an array of resolved filepaths for require-able local or named npm modules. Wildcard (glob) patterns may be used.

resolve-dep

Return an array of resolved filepaths for require-able local or named npm modules. Wildcard (glob) patterns may be used.

Similar in concept to matchdep and load-grunt-tasks, but returns an array of fully resolved file paths to any local modules or npm modules listed in package.json dependencies.

Install with npm:

npm i resolve-dep --save-dev
var resolve = require('resolve-dep');
resolve( patterns, options )

###resolveDep

Resolve both npm packages and local modules by:

  • patterns {Array|String}: Glob patterns for files or npm modules.

  • options {Object}

  • returns: {Array}

    1. Attempting to expand glob patterns to local modules, then
    2. Attempting to match glob patterns to deps in package.json

Examples:

// file path 
resolve('foo/bar.js');
// glob patterns 
resolve('foo/*.js');
// named npm module (installed in node_modules) 
resolve('chai');
// combination 
resolve(['chai', 'foo/*.js']);

###.npm

Resolve npm packages in node_modules by matching glob patterns to deps in package.json. NPM modules will only be resolved if they are defined in one of the "dependencies" fields in package.json.

  • patterns {Array|String}
  • options {Object}
  • returns: {Array}
// resolve npm modules only 
resolve.npm(['chai', 'lodash']);

###.local

Resolve local modules by expanding glob patterns to file paths.

  • patterns {Array|String}
  • options {Object}
  • returns: {Array}
// resolve local modules only 
resolve.local(['a/*.js', 'b/*.json']);

Type: object

The options object supports any globby options, as well as the following:

Type: string|array

The file path, glob pattern, or name of the npm module to resolve.

File paths

resolve('templates/*.hbs')
resolve(['a/*.hbs', 'b/*.hbs'])

NPM modules

resolve('*')
resolve(['grunt-*', 'gulp-*'])
resolve(['grunt-*', 'gulp-*'], {type: 'devDependencies'})
resolve(['lodash', 'assemble']);

Type: Object Default value: package.json

Pass an explicit config object to use instead of package.json.

Type: String|Array

Default value: all

Valid values: all|dependencies|devDepencies|peerDependencies

Any valid npm dependency field that can be used in package.json is a valid value for this option.

Examples:

// resolve chai and mocha, if in devDependencies, otherwise an empty array 
resolve(['chai', 'mocha'], {type: 'devDependencies'});
// resolve lodash if in dependencies, otherwise an empty array 
resolve(['lodash'], {type: 'dependencies'});
// all dependencies 
resolve(['*'], {type: 'dependencies'});
// all dependencies, devDependencies and peerDependencies 
resolve('*');

Jon Schlinkert

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on August 22, 2014.