Coder Social home page Coder Social logo

jonschlinkert / lookup-deps Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 1.0 280 KB

Simple API for getting metadata from locally installed npm packages (in `node_modules`).

License: MIT License

JavaScript 100.00%
dependencies package package-json tree deps cache

lookup-deps's Introduction

lookup-deps NPM version

Simple API for getting metadata from locally installed npm packages (in node_modules).

What does it do!?

Builds a recursive tree of all dependencies currently installed in node_modules. Allows you to easily get information from the package.json of any locally installed module.

Examples:

Get the version of the specified dependency:

deps.get('markdown-utils', 'version');
//=> '0.1.0'

Use glob patterns to get the specified property from every dependency:

deps.get('*', 'homepage')

// returns an object like this:
{ globby: 'https://github.com/sindresorhus/globby',
 'is-relative': 'https://github.com/jonschlinkert/is-relative',
 'is-absolute': 'https://github.com/jonschlinkert/is-absolute', ...}

If an object is returned with null values, this means that the package wasn't found at the given path. e.g. it was symlinked by npm.

To get around this, you can pass {findup: true} to the constructor and [findup-sync] will be used to find the nearest match. This is disabled by default since this is an exception to the rule and it considerably slows down searches.

Install

Install with npm:

npm i lookup-deps --save-dev

Run tests

npm test

Usage

var Deps = require('lookup-deps');
var deps = new Deps();

API

Create a new instance of Lookup.

  • config {Object}: Optionally pass a default config object instead of package.json For now there is no reason to do this.
  • options {Object}
var Lookup = require('lookup-deps');
var deps = new Lookup();

Get a value from the cache.

  • name {Object}: The module to get.
  • props {String}: Property paths.
  • returns: {Object}
// get an entire package.json
deps.get('markdown-utils');
//=> { pkg: { name: 'markdown-utils', version: '0.3.0', ... }

// or, get a specific value
deps.get('markdown-utils', 'version');
//=> '0.3.0'

Check to see if a module exists (or at least is on the cache).

  • name {String}: The name to check.
  • returns: {String}
deps.exists('markdown-utils');
//=> true

Get the keys for dependencies for the specified package.

  • config {Object|String}: The name of the module, or package.json config object.
  • returns: {Object}
deps.depsKeys('markdown-utils');
//=> [ 'is-absolute', 'kind-of', 'relative', ... ]
  • filepath {String}
  • returns: {String}

Find a package.json for the given module by name, starting the search at the given cwd.

Build a dependency tree by recursively reading in package.json files for projects in node_modules.

  • cwd {String}: The root directory to search from.
  • returns: {Object}
deps.tree('./');

Filter the entire cache object to have only packages with names that match the given glob patterns.

  • patterns {String|Array}: Glob patterns to use for filtering modules.
  • keyPatterns {String|Array}: Glob patterns to use for filtering the keys on each object.
  • returns {Object}: Filtered object.

You may also filter the keys on each object by passing additional glob patterns as a second argument.

deps.filter('markdown-*');
//=> {'markdown-utils': {...}}

// exclude the `readme` key from package.json objects
deps.filter('markdown-*', ['*', '!readme']);
//=> {'markdown-utils': {...}}

Returns an object of all modules that have the given module as a dependency. Glob patterns may be used for filtering.

  • patterns {String|Array}: Glob patterns to use for filtering.
  • returns {Object}: Object of parent modules.
deps.getParents('*');

Return a list of names of all resolved packages from node_modules that match the given glob patterns. If no pattern is provided the entire list is returned.

  • patterns {String|Array}: Glob patterns to use for filtering.
  • returns {Array}: Array of keys.
deps.names('markdown-*');
//=> ['markdown-utils']

Find a module or modules using glob patterns, and return an object filtered to have only the specified props. Note that package.json objects are stored on the pkg property for each module.

  • patterns {String}
  • props {String}
  • returns: {Object}

Properties are specified using object paths:

deps.find('for-*', 'pkg.repository.url');

// results in:
// { 'for-own': 'git://github.com/jonschlinkert/for-own.git',
//   'for-in': 'git://github.com/jonschlinkert/for-in.git' }

A convenience proxy for the .find() method to specifically search the pkg object of each module on the cache.

  • patterns {String}
  • props {String}
  • returns: {Object}
deps.lookup('for-*', 'repository.url');

// results in:
// { 'for-own': 'git://github.com/jonschlinkert/for-own.git',
//   'for-in': 'git://github.com/jonschlinkert/for-in.git' }

Get the path to a module or modules, relative to the current working directory. Glob patterns may be used.

  • patterns {String}
  • returns: {String}
deps.paths('*');

Get the package.json objects for the given module or modules. Glob patterns may be used.

  • patterns {String}
  • returns: {String}
deps.pkg('markdown-utils');

Get the dependencies for the given modules. Glob patterns may be used.

  • patterns {String}
  • returns: {Object}
deps.dependencies('multi*');
//=> { multimatch: { 'array-differ': '^1.0.0', ... } }

Get the devDependencies for the given modules. Glob patterns may be used.

  • patterns {String}
  • returns: {Object}
deps.devDependencies('multi*');
//=> { multimatch: { 'array-differ': '^1.0.0', ... } }

Get the keywords for the given modules.

  • patterns {String}
  • returns: {String}
deps.keywords('multi*');
//=> { multimatch: [ 'minimatch', 'match', ... ] }

Get the homepage for the specified modules.

  • patterns {String}
  • returns: {String}
deps.homepage('markdown-*');
//=> { 'markdown-utils': 'https://github.com/jonschlinkert/markdown-utils' }

Get a list of markdown-formatted links, from the homepage properties of the specified modules.

  • patterns {String}
  • returns: {String}
deps.links('markdown-*');
//=> [markdown-utils](https://github.com/jonschlinkert/markdown-utils)

Get a list of markdown-formatted links, from the homepage properties of the specified modules.

  • patterns {String}
  • returns: {String}
deps.reflinks('markdown-*');
//=> [markdown-utils]: https://github.com/jonschlinkert/markdown-utils

Author

Jon Schlinkert

License

Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb on February 03, 2015.

lookup-deps's People

Contributors

jonschlinkert avatar ruyadorno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ruyadorno

lookup-deps's Issues

Missing ./lib/ folder

I installed it on a project to give it a try but I'm getting the following error:

module.js:340
    throw err;
    ^
Error: Cannot find module './lib'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/ruy.adorno/Documents/workspace/generator-html5/node_modules/lookup-deps/index.js:19:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Weird thing is that when I open the installed folder on ./node_modules/lookup_deps/ I can't really find the ./lib/ folder there.

Can it be a problem with the npm published version?

Thanks in advance,

Lookup for devDependencies

Hi,

Thanks for writing this API. I'm trying to get a list of names from devDependencies and their dependencies that match a certain pattern.

I have tried multiple endpoints and always get results regarding dependencies. So if I try for example deps.devDependencies(pattern) this fits almost exactly what I need, but it returns the devDependencies of my dependencies.

Am I doing something wrong or is there a way for the API to go against packages installed as devDependencies?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.