{"id":13547516,"url":"https://github.com/danez/pirates","last_synced_at":"2025-05-13T22:12:14.236Z","repository":{"id":10605826,"uuid":"47372003","full_name":"danez/pirates","owner":"danez","description":"Properly hijack require","archived":false,"fork":false,"pushed_at":"2025-03-27T11:22:18.000Z","size":890,"stargazers_count":402,"open_issues_count":0,"forks_count":20,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-08T10:06:00.472Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ariporad/pirates","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["danez"]}},"created_at":"2015-12-04T01:09:33.000Z","updated_at":"2025-05-04T14:47:04.000Z","dependencies_parsed_at":"2023-02-10T07:15:53.826Z","dependency_job_id":"ffbaddde-f835-4855-bd6c-f761c7c69a65","html_url":"https://github.com/danez/pirates","commit_stats":{"total_commits":168,"total_committers":16,"mean_commits":10.5,"dds":0.6726190476190477,"last_synced_commit":"3d4da84194b36f1d3e8adb8a14fa06615ec5868f"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danez%2Fpirates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danez%2Fpirates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danez%2Fpirates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danez%2Fpirates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danez","download_url":"https://codeload.github.com/danez/pirates/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253358161,"owners_count":21895978,"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":[],"created_at":"2024-08-01T12:00:57.376Z","updated_at":"2025-05-13T22:12:13.904Z","avatar_url":"https://github.com/danez.png","language":"JavaScript","funding_links":["https://github.com/sponsors/danez"],"categories":["JavaScript"],"sub_categories":[],"readme":"# Pirates [![Coverage][codecov-badge]][codecov-link]\n\n### Properly hijack require\n\nThis library allows to add custom require hooks, which do not interfere with other require hooks.\n\nThis library only works with commonJS.\n\n[codecov-badge]: https://img.shields.io/codecov/c/github/danez/pirates/master.svg?style=flat \"codecov\"\n[codecov-link]: https://codecov.io/gh/danez/pirates \"codecov\"\n\n## Why?\n\nTwo reasons:\n1. Babel and istanbul were breaking each other.\n2. Everyone seemed to re-invent the wheel on this, and everyone wanted a solution that was DRY, simple, easy to use,\nand made everything Just Work™, while allowing multiple require hooks, in a fashion similar to calling `super`.\n\nFor some context, see [the Babel issue thread][] which started this all, then [the nyc issue thread][], where\ndiscussion was moved (as we began to discuss just using the code nyc had developed), and finally to [#1][issue-1]\nwhere discussion was finally moved.\n\n[the Babel issue thread]: https://github.com/babel/babel/pull/3062 \"Babel Issue Thread\"\n[the nyc issue thread]: https://github.com/bcoe/nyc/issues/70 \"NYC Issue Thread\"\n[issue-1]: https://github.com/danez/pirates/issues/1 \"Issue #1\"\n\n## Installation\n\n    npm install --save pirates\n\n## Usage\n\nUsing pirates is really easy:\n```javascript\n// my-module/register.js\nconst addHook = require('pirates').addHook;\n// Or if you use ES modules\n// import { addHook } from 'pirates';\n\nfunction matcher(filename) {\n  // Here, you can inspect the filename to determine if it should be hooked or\n  // not. Just return a truthy/falsey. Files in node_modules are automatically ignored,\n  // unless otherwise specified in options (see below).\n\n  // TODO: Implement your logic here\n  return true;\n}\n\nconst revert = addHook(\n  (code, filename) =\u003e code.replace('@@foo', 'console.log(\\'foo\\');'),\n  { exts: ['.js'], matcher }\n);\n\n// And later, if you want to un-hook require, you can just do:\nrevert();\n```\n\n## API\n\n### pirates.addHook(hook, [opts={ [matcher: true], [exts: ['.js']], [ignoreNodeModules: true] }]);\nAdd a require hook. `hook` must be a function that takes `(code, filename)`, and returns the modified code. `opts` is\nan optional options object. Available options are: `matcher`, which is a function that accepts a filename, and\nreturns a truthy value if the file should be hooked (defaults to a function that always returns true), falsey if\notherwise; `exts`, which is an array of extensions to hook, they should begin with `.` (defaults to `['.js']`);\n`ignoreNodeModules`, if true, any file in a `node_modules` folder wont be hooked (the matcher also wont be called),\nif false, then the matcher will be called for any files in `node_modules` (defaults to true).\n\n\n## Projects that use Pirates\n\nSee the [wiki page](https://github.com/danez/pirates/wiki/Projects-using-Pirates). If you add Pirates to your project,\n(And you should! It works best if everyone uses it. Then we can have a happy world full of happy require hooks!), please\nadd yourself to the wiki.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanez%2Fpirates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanez%2Fpirates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanez%2Fpirates/lists"}