https://github.com/fengb/module-resolve-as-caller
https://github.com/fengb/module-resolve-as-caller
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/fengb/module-resolve-as-caller
- Owner: fengb
- Created: 2015-11-10T05:19:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-11T22:00:01.000Z (about 10 years ago)
- Last Synced: 2025-05-26T17:57:51.883Z (about 1 year ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# module-resolve-as-caller
## Installation
```bash
$ npm install module-resolve-as-caller
```
## Example
```javascript
//* 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:
* [require-optional](https://github.com/fengb/require-optional)
## License
MIT