0.1.1 • Published 8 years ago

module-resolve-as-caller v0.1.1

Weekly downloads
311
License
MIT
Repository
github
Last release
8 years ago

module-resolve-as-caller

Installation

$ npm install module-resolve-as-caller

Example

//* node_modules/fancy/index.js

var moduleResolveAsCaller = require('module-resolve-as-caller')
function resolve (path) {
  return moduleResolveAsCaller(path)
}

function require (path) {
  return moduleResolveAsCaller.require(path)
}

//* user.js

var fancy = require('fancy')

// Use node_modules when not relative path
fancy.resolve('dependency')
fancy.require('dependency')

// Relative paths search up the callsite.
// In this example, this is relative to **user.js**, not **fancy.js**.
fancy.resolve('./relative')
fancy.require('./relative')

Why?

Sometimes, we need metaprogramming tricks to get around the standard module resolution:

License

MIT