module-resolve-as-caller
v0.1.1
Published
Resolve relative paths as though it were in the caller's file
Downloads
1,321
Readme
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