{"name":"pirates","description":"Properly hijack require, i.e., properly define require hooks and customizations","main":"lib/index.js","types":"index.d.ts","scripts":{"test":"ava"},"repository":{"type":"git","url":"git+https://github.com/danez/pirates.git"},"engines":{"node":">= 6"},"author":{"name":"Ari Porad","email":"ari@ariporad.com","url":"http://ariporad.com"},"devDependencies":{"ava":"1.4.1","decache":"4.6.2"},"license":"MIT","bugs":{"url":"https://github.com/danez/pirates/issues"},"homepage":"https://github.com/danez/pirates#readme","ava":{"files":["test/*.js"],"sources":["lib/**/*.js"]},"version":"4.0.7","_id":"pirates@4.0.7","gitHead":"ecd5f6cd8491c4f0e496f98ed18fb073257a0444","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==","shasum":"643b4a18c4257c8a65104b73f3049ce9a0a15e22","tarball":"http://registry-npm.ywwl.com/pirates/download/pirates-4.0.7.tgz","fileCount":5,"unpackedSize":12564,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEDOaLXgpfdHi3YSvPXAvpsCx6ZY+mE+vZoGT89aoFzTAiA9O91Dygz7ZOQ7Z9hjpxWufLJX2uP/hfTB6XfCussq8A=="}],"size":4638,"noattachment":false,"key":"/pirates/-/pirates-4.0.7.tgz"},"_npmUser":{"name":"danez","email":"npm@tschinder.de"},"directories":{},"maintainers":[{"name":"ariporad","email":"ari@ariporad.com"},{"name":"hzoo","email":"hi@henryzoo.com"},{"name":"danez","email":"npm@tschinder.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pirates_4.0.7_1743074518269_0.640316239481086"},"_hasShrinkwrap":false,"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) => 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","publish_time":1743074518481,"_cnpm_publish_time":1743074518481,"dist-tags":{"latest":"4.0.7"}}