pkgresolve
Resolve a dependency of another package.
Last updated 12 years ago by timoxley .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pkgresolve 
SYNC missed versions from official npm registry.

pkgresolve

Resolve a dependency from within the context of another package.

Build Status

Useful for hacks, monkeypatching or wrappers that require manipulation of the exact dependency that would be loaded by a package.

Installation

npm install --save pkgresolve

Example

var resolve = require('pkgresolve')

// Resolve 'through' from locally installed 'tape'
resolve('through').from('tape', function(err, pkgPath) {
  // pkgPath - path to through or null
})

// Resolve 'npmconf' from globally installed 'npm'
resolve('npmconf').fromGlobal('npm', function(err, pkgPath) {
  // pkgPath - path to npmconf or null
})

CLI

# Resolve 'through' from locally installed 'tape'
pkgresolve tape through

# Resolve 'npmconf' from globally installed 'npm'
pkgresolve --global npm npmconf

Why not require('parent/node_modules/child')?

Due to deduplication, child is not guaranteed to exist at that location. You don't even need to call npm dedupe for this to happen – npm will not install something that is already installed in the hierarchy. pkgresolve is a more robust method.

Use Responsibly.

This intentially breaks the encapsulation provided by node/npm's module system. Don't use this unless you have to.

See Also

License

MIT

Current Tags

  • 1.1.4                                ...           latest (9 years ago)

6 Versions

  • 1.1.4                                ...           9 years ago
  • 1.1.3                                ...           12 years ago
  • 1.1.2                                ...           12 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |