Noiseless Peaceful Morning
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

intercept-require

1.1.0 • Public • Published

intercept-require Build Status

Installation

npm install intercept-require

About

Intercept, prevent, modify, and short-circuit calls to require().

Example

const intercept = require("intercept-require");
// in this example, just transparently log every require
const restore = intercept(function (moduleExport, info) {
  // moduleExport is whatever the actual module exported
 
  // info looks like:
  //  {
  //    moduleId: "lodash",
  //    callingFile: "index.js",
  //    native: false,
  //    extname: ".js",
  //    thirdParty: true,
  //    exports: [[actual lodash object]]
  //    absPath: /from/root/to/project/node_modules/lodash/lodash.js,
  //    absPathResolvedCorrectly: true,
  //    testOnly: false,
  //    local: false
  //  }
  console.log("require:", info.moduleId, "from", info.callingFile);
  
  // value returned from this function will be passed back to the caller as if it was module.exports
  return moduleExport;
}, config);
// config has only one option `shortCircuit: boolean`
// if short-circuit is active, `moduleExport` argument to listener will be null
 
// require() calls now being intercepted
restore();
// require() calls no longer intercepted

install

npm i intercept-require

Downloadsweekly downloads

432

version

1.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability