JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q55929F
  • License MIT

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

Package Exports

  • resolve-modules

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (resolve-modules) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

resolve-modules NPM version Build Status

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

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'});

createEnv

Return a new env (environment) object with config, module and user properties.

Params

  • fp {String}: The starting filepath for the config
  • cwd {String}: The user (process) cwd
  • options {Object}
  • returns {Object}

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 on December 13, 2015.