reverse-require
v2.0.0
Published
Search for node modules from host project first
Downloads
46
Readme
reverse-require
Search for node modules from host project first
Overview
This project provides a set of methods to reverse the search order of module imports.
So instead of searching the module first and moving up the chain, we start at the top-level project and work our way down the child projects until we find the module.
When is this useful?
Imagine you have a Core library that defines a set of npm
dependencies.
You reference Core in Project A and Project B to get a common set of dependencies and behaviour :sunglasses:
But now you want to test out how a new dependency will work in Project A. You npm link
the module into Project A, fire it up and... Core still loads the old version :neutral_face:
Of course! Core defines the dependency so it's installed locally to that project and linking the new version to Project A won't help.
You could link the dependency into Core but it can get a bit hairy if you have a few libraries deep. And what if you need a different set of libraries in Project B?
reverse-require
lets you link a module near the base of the tree and version with your dependency modules (a little like npm dedupe
but without having to define the same dependency in your package.json
file).
Installation
$ npm install --save reverse-require
Usage
// Configuration:
// In the index of your project:
var ReverseRequire = require('reverse-require');
ReverseRequire.moduleRoot = __filename;
// Usage:
var rr = require('reverse-require')();
var _ = rr('lodash');