Package Exports
- require-in-the-middle
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (require-in-the-middle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
require-in-the-middle
Hook into the Node.js require
function. This allows you to modify
modules on-the-fly as they are being required.
Installation
npm install require-in-the-middle --save
Usage
var path = require('path')
var hook = require('require-in-the-middle')
// Hook into the express and mongodb module
hook(['express', 'mongodb'], function (exports, name, basedir) {
var version = require(path.join(basedir, 'package.json')).version
console.log('loading %s@%s', name, version)
// expose the module version as a property on its exports object
exports._version = version
// whatever you return will be returned by `require`
return exports
})
API
The require-in-the-middle module exposes a single function:
function ([modules][, options], onrequire) {}
modules
<string[]> An optional array of module names to limit which modules trigger a call of theonrequire
callback. If specified, this must be the first argument.options
onrequire
The function to call when a module is required.
Supply a callback function as the last argument. This function will be
called the first time a module is required. The onrequire
function is
called with three arguments:
exports
name
The name of the module being required. If options.internals
was set totrue
, the path of module-internal files that are loaded (relative tobasedir
) will be appended to the module name, separated bypath.sep
.basedir
The directory where the module is located, or undefined
for core modules.
Return the value you want the module to expose (normally the exports
argument).
License
MIT