### Configure Requizzle with before/after hooks and requirePaths Source: https://github.com/hegemonic/requizzle/blob/main/README.md Shows two Requizzle configurations: one that logs before and after each module load using the `extras.before` and `extras.after` hooks, and another that uses `infect: true` with `requirePaths` to make modules resolve from a custom `lib` directory. The first example prints "Hello /path/to/mymodule.js!" and "Goodbye /path/to/mymodule.js!" when requiring `mymodule`. ```javascript const requizzle = require('requizzle'); // Say hello and goodbye to each module. const logRequire = requizzle({ extras: { before: function(targetPath, parentModule) { return 'console.log("Hello %s!", ' + targetPath + ');\n'; }, after: function(targetPath, parentModule) { return 'console.log("Goodbye %s!", ' + targetPath + ');\n'; } } }); // Prints "Hello /path/to/mymodule.js!" and "Goodbye /path/to/mymodule.js!" const myModule = logRequire('mymodule'); // Look for modules in the current module's `lib` directory, and force child // modules to do the same. const path = require('path'); const extraPathRequire = requizzle({ infect: true, requirePaths: [path.join(__dirname, 'lib')] }); // If `foo` needs to require a module in `./lib`, it can use `require('bar')` // instead of `require('./lib/bar')`. const foo = extraPathRequire('./foo'); ``` -------------------------------- ### requizzle(options) Source: https://github.com/hegemonic/requizzle/blob/main/README.md Documentation for the requizzle function, which returns a drop-in replacement for require(). ```APIDOC ## requizzle(options) ### Description Returns a drop-in replacement for `require()` that can insert text before or after a module's source code, infect child modules, and search additional paths for required modules. ### Parameters - **options** (object) - Required - An object with the following properties: - **extras** (object) - Optional - A pair of functions that return text to insert before or after the module's source code. - **extras.before** (function) - Optional - A function that accepts `targetPath` (string) and `parentModule` (Module) and returns a string to insert before the module's source code. - **extras.after** (function) - Optional - A function that accepts `targetPath` (string) and `parentModule` (Module) and returns a string to insert after the module's source code. - **infect** (boolean) - Optional - Determines whether child modules are infected with the same changes as the parent module. Set to `true` to force child modules to inherit your changes. Defaults to `false`. - **requirePaths** (array|object) - Optional - Additional paths to search for required modules. Can be an array of paths, or an object with the following properties: - **requirePaths.before** (array) - Optional - An array of paths to search before the default module paths. - **requirePaths.after** (array) - Optional - An array of paths to search after the default module paths. ### Returns - **function** - A drop-in replacement for `require()`. ### Example ```js const requizzle = require('requizzle'); const requireWithExtras = requizzle({ extras: { before: (targetPath, parentModule) => '/* before */', after: (targetPath, parentModule) => '/* after */' }, infect: true, requirePaths: ['/usr/lib/junk/modules'] }); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.