Socket
Book a DemoInstallSign in
Socket

resolve-modules

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resolve-modules

Resolves local and global npm modules that match specified patterns, and returns a configuration object for each resolved module.

Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
25
47.06%
Maintainers
1
Weekly downloads
 
Created
Source

resolve-modules NPM version

Resolves local and global npm modules that match specified patterns, and returns a configuration object for each resolved module.

This is a WIP.

Install

Install with npm

$ npm i resolve-modules --save

Usage

var Resolver = require('resolve-modules');
var resolver = new Resolver({
  module: 'generate'
});

resolver.resolve({
  cwd: process.cwd(),
  pattern: 'generate-*/generate.js'
});

Events

When the search pattern finds a match, a config event is emitted:

resolver.on('config', function(config) {
  // do stuff with "config"
});

The config object that is emitted looks something like this:

{
  options:
   { realpath: true,
     cwd: '/usr/local/lib/node_modules',
     module: 'generate',
     pattern: 'generate-*/generator.js',
     configCwd: '/usr/local/lib/node_modules/generate-foo',
     context: {} },
  cache:
   { name: 'generate-foo',
     dirname: '/usr/local/lib/node_modules/generate-foo',
     root: '/usr/local/lib/node_modules/generate-foo',
     filename: 'generator.js',
     cwd: '/usr/local/lib/node_modules/generate-foo',
     pkg: '/usr/local/lib/node_modules/generate-foo/package.json',
     relative: '',
     alias: 'foo' },
  path: '/usr/local/lib/node_modules/generate-foo/generator.js',
  fn: [Getter/Setter],
  filename: [Getter/Setter],
  realpath: [Getter],
  cwd: [Getter/Setter],
  root: [Getter/Setter],
  dirname: [Getter/Setter],
  relative: [Getter/Setter],
  name: [Getter/Setter],
  alias: [Getter/Setter],
  pkg: [Getter/Setter],
  main: [Getter/Setter],
  module:
   Mod {
     name: 'generate',
     configCwd: undefined,
     path: '/usr/local/lib/node_modules/generate/index.js',
     realpath: [Getter],
     pkg: [Getter],
     fn: [Getter] } }

API

Resolver

Resolver

Create an instance of Resolver with options. The only required option is module, which is the name of the module that will be used for creating instances for config files by the resolve method.

For example, [generate][], the project generator, would be the "module", and individual generators (generator.js files) would be the "config" files.

Params

  • options {Object}

Example

var resolver = new Resolver({
  module: 'generate'
});

.resolve

Searches for config files that match the given glob patterns and, when found, emits config with details about the module and environment, such as absolute path, cwd, path to parent module, etc.

Params

  • patterns {String|Array|Object}: Glob pattern(s) or options object. If options, the pattern property must be defined with a glob pattern.
  • options {Object}
  • returns {Object}: Returns the resolver instance, for chaining.

Example

var resolver = new Resolver({
  module: 'generate'
});

resolver.on('config', function(config, mod) {
  // `config` is an object with fully resolved file paths.
  // Config also has a `fn` getter that returns the contents of
  // the config file. Using the "generate" analogy above, this would
  // be a "generator.js" config file

  // `mod` (module) is a similar object, but for the "parent"
  // module. Using the generate analogy above, this would be an installation
  // "generate", either installed locally to the generator, or as a global
  // npm module
});

resolver
  .resolve('generator.js', {cwd: 'foo'})
  .resolve('generator.js', {cwd: 'bar'})
  .resolve('generator.js', {cwd: 'baz'});

Config

Module

Mod

Create a new Mod with the given options

Params

  • options {Object}

Example

var mod = new Mod(options);

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.

This file was generated by verb-cli on December 03, 2015.

Keywords

config

FAQs

Package last updated on 05 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts