0.4.0 • Published 7 years ago
require-up v0.4.0
Require-up
Require modules from anywhere up the parent directories. Like find-up but for require
.
Optionally, a new syntax ('.../'
) which will work with regular require/import calls.
Install
$ npm install --save require-up
Usage
If you have a structure like this:
proj
├───index.js
├───utils.js
└───foo
└───bar
└───some-file.js
// proj/foo/bar/some-file.js
const requireUp = require('require-up')
const { utils } = requireUp('utils')
It will look for (in this order):
proj/foo/bar/node_modules/utils
proj/foo/bar/utils
proj/foo/node_modules/utils
proj/foo/utils
proj/node_modules/utils
proj/utils # << found
Register
A new syntax ('.../'
) which will work with regular require/import calls.
// proj/index.js
import 'require-up/register'
// proj/foo/bar/some-file.js
import utils from '.../utils'
CAUTION
BEWARE: Registering new syntax patches core module.js's Module._resolveFilename
.