{"name":"require-in-the-middle","version":"7.5.0","keywords":["require","hook","shim","shimmer","shimming","patch","monkey","monkeypatch","module","load"],"author":{"url":"https://twitter.com/wa7son","name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","_id":"require-in-the-middle@7.5.0","homepage":"https://github.com/elastic/require-in-the-middle#readme","bugs":{"url":"https://github.com/elastic/require-in-the-middle/issues"},"dist":{"shasum":"6466fa87d6297b46d3ceca99ec03f901cab35d11","tarball":"http://registry-npm.ywwl.com/require-in-the-middle/download/require-in-the-middle-7.5.0.tgz","fileCount":5,"integrity":"sha512-/Tvpny/RVVicqlYTKwt/GtpZRsPG1CmJNhxVKGz+Sy/4MONfXCVNK69MFgGKdUt0/324q3ClI2dICcPgISrC8g==","signatures":[{"sig":"MEQCIBKbxX57kwwk8pAovF0iPYZ5e89XtgqtnPTKUvY9suLZAiAdyIhu6oIvVCaiqczY/+hi1PChOB5Jya39XaePFf1sng==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19585,"size":6723,"noattachment":false,"key":"/require-in-the-middle/-/require-in-the-middle-7.5.0.tgz"},"main":"index.js","types":"types/index.d.ts","engines":{"node":">=8.6.0"},"gitHead":"f23ff521dc5611ba7c24f8b1a0f69dfad0ece47a","scripts":{"test":"npm run test:lint && npm run test:tape && npm run test:babel","test:lint":"standard","test:tape":"tape test/*.js","test:babel":"node test/babel/babel-register.js"},"_npmUser":{"name":"trentm","email":"trentm@gmail.com"},"repository":{"url":"git+https://github.com/elastic/require-in-the-middle.git","type":"git"},"_npmVersion":"10.7.0","description":"Module to hook into the Node.js require function","directories":{},"_nodeVersion":"18.20.4","dependencies":{"debug":"^4.3.5","resolve":"^1.22.8","module-details-from-path":"^1.0.3"},"_hasShrinkwrap":false,"devDependencies":{"tape":"^4.11.0","semver":"^6.3.0","patterns":"^1.0.3","standard":"^14.3.1","roundround":"^0.2.0","@babel/core":"^7.9.0","ipp-printer":"^1.0.0","@babel/register":"^7.9.0","@babel/preset-env":"^7.9.5","@babel/preset-typescript":"^7.9.0"},"_npmOperationalInternal":{"tmp":"tmp/require-in-the-middle_7.5.0_1738018969029_0.4969973500310325","host":"s3://npm-registry-packages-npm-production"},"readme":"# require-in-the-middle\n\nHook into the Node.js `require` function. This allows you to modify\nmodules on-the-fly as they are being required.\n\n[![npm](https://img.shields.io/npm/v/require-in-the-middle.svg)](https://www.npmjs.com/package/require-in-the-middle)\n[![Test status](https://github.com/nodejs/require-in-the-middle/workflows/Test/badge.svg)](https://github.com/nodejs/require-in-the-middle/actions)\n\nAlso supports hooking into calls to `process.getBuiltinModule()`, which was introduced in Node.js v22.3.0.\n\n## Installation\n\n```\nnpm install require-in-the-middle --save\n```\n\n## Usage\n\n```js\nconst path = require('path')\nconst { Hook } = require('require-in-the-middle')\n\n// Hook into the express and mongodb module\nnew Hook(['express', 'mongodb'], function (exports, name, basedir) {\n  const version = require(path.join(basedir, 'package.json')).version\n\n  console.log('loading %s@%s', name, version)\n\n  // expose the module version as a property on its exports object\n  exports._version = version\n\n  // whatever you return will be returned by `require`\n  return exports\n})\n```\n\n## API\n\nThe require-in-the-middle module exposes a single function:\n\n### `hook = new Hook([modules][, options], onrequire)`\n\nWhen called a `hook` object is returned.\n\nArguments:\n\n- `modules` &lt;string[]> An optional array of module names to limit which modules\n  trigger a call of the `onrequire` callback. If specified, this must be the\n  first argument. Both regular modules (e.g. `react-dom`) and\n  sub-modules (e.g. `react-dom/server`) can be specified in the array.\n- `options` &lt;Object> An optional object containing fields that change when the\n  `onrequire` callback is called. If specified, this must be the second\n  argument.\n  - `options.internals` &lt;boolean> Specifies whether `onrequire` should be called\n    when module-internal files are loaded; defaults to `false`.\n- `onrequire` &lt;Function> The function to call when a module is required.\n\nThe `onrequire` callback will be called the first time a module is\nrequired. The function is called with three arguments:\n\n- `exports` &lt;Object> The value of the `module.exports` property that would\n  normally be exposed by the required module.\n- `name` &lt;string> The name of the module being required. If `options.internals`\n  was set to `true`, the path of module-internal files that are loaded\n  (relative to `basedir`) will be appended to the module name, separated by\n  `path.sep`.\n- `basedir` &lt;string> The directory where the module is located, or `undefined`\n  for core modules.\n\nReturn the value you want the module to expose (normally the `exports`\nargument).\n\n### `hook.unhook()`\n\nRemoves the `onrequire` callback so that it will not be triggerd by\nsubsequent calls to `require()` or `process.getBuiltinModule()`.\n\n## License\n\n[MIT](https://github.com/nodejs/require-in-the-middle/blob/master/LICENSE)\n","publish_time":1738018969230,"maintainers":[{"name":"trentm","email":"trentm@gmail.com"},{"name":"watson","email":"w@tson.dk"},{"name":"nodejs-foundation","email":"build@iojs.org"}],"_cnpm_publish_time":1738018969230,"dist-tags":{"latest":"8.0.1"}}