{"id":15394999,"url":"https://github.com/goto-bus-stop/require-with-global","last_synced_at":"2025-04-16T00:01:58.332Z","repository":{"id":31875025,"uuid":"130045625","full_name":"goto-bus-stop/require-with-global","owner":"goto-bus-stop","description":"inject a global variable into a module require() tree","archived":false,"fork":false,"pushed_at":"2022-04-21T04:17:00.000Z","size":20,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T03:06:10.795Z","etag":null,"topics":["global","inject","insert","mock","require","variable"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goto-bus-stop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-18T10:27:11.000Z","updated_at":"2024-07-27T10:33:28.000Z","dependencies_parsed_at":"2022-08-07T17:00:33.290Z","dependency_job_id":null,"html_url":"https://github.com/goto-bus-stop/require-with-global","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Frequire-with-global","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Frequire-with-global/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Frequire-with-global/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Frequire-with-global/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goto-bus-stop","download_url":"https://codeload.github.com/goto-bus-stop/require-with-global/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173071,"owners_count":21224483,"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":["global","inject","insert","mock","require","variable"],"created_at":"2024-10-01T15:25:17.193Z","updated_at":"2025-04-16T00:01:58.301Z","avatar_url":"https://github.com/goto-bus-stop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# require-with-global\n\ninject a global variable into a module require() tree\n\n[![npm][npm-image]][npm-url]\n[![travis][travis-image]][travis-url]\n[![standard][standard-image]][standard-url]\n\n[npm-image]: https://img.shields.io/npm/v/require-with-global.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/require-with-global\n[travis-image]: https://img.shields.io/travis/goto-bus-stop/require-with-global.svg?style=flat-square\n[travis-url]: https://travis-ci.org/goto-bus-stop/require-with-global\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[standard-url]: http://npm.im/standard\n\n## Install\n\n```\nnpm install require-with-global\n```\n\n## Usage\n\n```js\nvar withGlobal = require('require-with-global')\nvar uppercaseStream = require('through2')(function (chunk, enc, next) {\n  next(null, chunk.toUpperCase())\n})\nvar virtualConsole = require('console').Console(uppercaseStream)\nvar r = withGlobal()\n// `console` in ./app.js and all child modules will be `virtualConsole`.\nvar app = r('./app', {\n  console: virtualConsole\n})\n\napp.run()\n\nuppercaseStream.pipe(process.stdout)\n\nr.remove() // Remove the require hook\n```\n\n## API\n\n### `req = withGlobal()`\n\nCreate a `require` function that can be used to inject module-global variables.\n\n### `req(specifier, vars)`\n\nRequire the module at `specifier`, injecting `vars` into all its deeply required\nmodules. All the variables specified in the `vars` object will be available in\nmodules required using the `req` function. Calls to `require()` inside the\nmodule will be wrapped so that `vars` are also recursively injected in\ndependencies of the module.\n\n### `req.remove()`\n\nRemove the compile hooks and global state that `withGlobal` uses to inject\nvariables into modules.\n\nNote that globals that were already injected will continue to work; it's\nperfectly safe to call `req.remove()` immediately after requiring some modules,\nif you are certain that there are no lazy require() calls left.\n\n## License\n\n[Apache-2.0](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Frequire-with-global","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoto-bus-stop%2Frequire-with-global","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Frequire-with-global/lists"}