module-resolve-as-caller

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i module-resolve-as-caller

Weekly Downloads

449

Version

0.1.1

License

MIT

Last publish

Collaborators

  • fengb