{"id":19558108,"url":"https://github.com/bttmly/intercept-require","last_synced_at":"2025-06-28T00:05:14.436Z","repository":{"id":25457751,"uuid":"28887967","full_name":"bttmly/intercept-require","owner":"bttmly","description":"intercept require() calls","archived":false,"fork":false,"pushed_at":"2017-04-14T06:53:28.000Z","size":60,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T23:31:59.589Z","etag":null,"topics":["nodejs","require"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bttmly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-06T23:08:17.000Z","updated_at":"2023-05-06T13:20:21.000Z","dependencies_parsed_at":"2022-08-24T00:30:33.867Z","dependency_job_id":null,"html_url":"https://github.com/bttmly/intercept-require","commit_stats":null,"previous_names":["nickb1080/intercept-require"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bttmly/intercept-require","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bttmly%2Fintercept-require","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bttmly%2Fintercept-require/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bttmly%2Fintercept-require/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bttmly%2Fintercept-require/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bttmly","download_url":"https://codeload.github.com/bttmly/intercept-require/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bttmly%2Fintercept-require/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262352620,"owners_count":23297689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","require"],"created_at":"2024-11-11T04:46:16.361Z","updated_at":"2025-06-28T00:05:14.414Z","avatar_url":"https://github.com/bttmly.png","language":"JavaScript","readme":"# intercept-require [![Build Status](https://travis-ci.org/bttmly/intercept-require.svg?branch=master)](https://travis-ci.org/bttmly/intercept-require)\n\n## Installation\n`npm install intercept-require`\n\n## About\nIntercept, prevent, modify, and short-circuit calls to `require()`. Given that this involves messing with the methods Node.js uses to require modules, it should be used judiciously. A few possible use-cases:\n\n- You're deprecating use of a library you don't control; use this module to print a deprecation warning and a stack trace whenever that library is `require`'d\n\n- Transparently stubbing dependencies. Sure, dependency injection is probably a better pattern, but it can be verbose. Instead, you could (during testing) replace e.g. `redis` with a simple in-memory store that exposes the same interface.\n\n- Implementing some kind of development environment hot-swapping functionality that wraps modules in a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) and transparently reloads them when files change\n\n... and any other bad ideas you can think up!\n\n## Example\n```js\nconst intercept = require(\"intercept-require\");\n// in this example, just transparently log every require\nconst restore = intercept(function (moduleExport, info) {\n  // moduleExport is whatever the actual module exported\n\n  // info looks like:\n  //  {\n  //    moduleId: \"lodash\",\n  //    callingFile: \"index.js\",\n  //    native: false,\n  //    extname: \".js\",\n  //    thirdParty: true,\n  //    exports: [[actual lodash object]]\n  //    absPath: /from/root/to/project/node_modules/lodash/lodash.js,\n  //    absPathResolvedCorrectly: true,\n  //    testOnly: false,\n  //    local: false\n  //  }\n  console.log(\"require:\", info.moduleId, \"from\", info.callingFile);\n\n  // value returned from this function will be passed back to the caller as if it was module.exports\n  return moduleExport;\n}, config);\n// config has only one option `shortCircuit: boolean`\n// if short-circuit is active, `moduleExport` argument to listener will be null\n\n// require() calls now being intercepted\nrestore();\n// require() calls no longer intercepted\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbttmly%2Fintercept-require","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbttmly%2Fintercept-require","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbttmly%2Fintercept-require/lists"}