# @contrast/patcher

> Advanced monkey patching--registers hooks to run in and around functions

Latest version **1.40.0** (published 2026-08-19) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @contrast/patcher
pnpm add @contrast/patcher
yarn add @contrast/patcher
bun add @contrast/patcher
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.40.0 |
| Published | 2026-08-19 |
| First published | 2022-06-16 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.7.0 |
| Dependencies | 1 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Contrast Security |
| Maintainers | tough-griff, chrisdunne, contrast_admin, jcolekaplan, contrastsec, mhenry-contrast, nbuckwalt |

## Links

- npm: https://www.npmjs.com/package/@contrast/patcher
- npm.io page: https://npm.io/package/@contrast/patcher

## Dependencies (1)

- [@contrast/logger](https://npm.io/package/@contrast/logger.md) 1.41.0

## Recent versions

- 1.40.0 (latest) — 2026-08-19
- 1.39.0 — 2026-07-31
- 1.38.0 — 2026-07-13
- 1.37.0 — 2026-06-16
- 1.36.0 — 2026-06-12
- 1.35.3 — 2026-06-01
- 1.35.2 — 2026-04-17
- 1.35.1 — 2026-03-31
- 1.35.0 — 2026-03-26
- 1.34.1 — 2026-03-06
- 1.34.0 — 2026-03-03
- 1.33.0 — 2026-02-04
- 1.32.1 — 2026-01-23
- 1.32.0 — 2025-12-16
- 1.31.1 — 2025-12-02
- … 48 more at https://npm.io/package/@contrast/patcher/versions

## README

# `@contrast/patcher`

Monkey patching.

# Notes on v5 Parity

This was ported directly from the `node-agent` but code with every dependency commented out. As a result there are differences in parity.

1. Removed dependency on `AsyncStorage`.

    **Old Behavior**

    Pre and post hooks only run when async storage context indicates an active request scope.

    **New Behavior**

    Hooks always run, independent of request scope.

1. Removed dependency on `agent` and `perf-logger`.

    **Old Behavior**

    A configuration setting would allow for logging of perf data of hooks and original function calls.

    **New Behavior**

    Performance logging of hooks is non-funcitonal.

1. Removed the dependency on `scopes`.

   **Old Behavior**

   One could specify a `scope` in the hook options and the original function would be run in that scope. This allowed control over when to run instrumentaion based on current scope value.

   Also, the `alwaysRun` option forced hooks to run independent of scope state.

   **New Behavior**

   There are no notions of scopes yet in v5. Patcher instrumentation always runs.

   The `scope` and `alwaysRun` options are effectively ignored.

1. Removed the dependency on `tracker`.

    **Old Behavior**
    
    We used to short-circuit `__add` function if tracker showed all arguments to be untracked.
    
    **New Behavior**
    
    We do not make this check; no short-circuiting.

---
_Source: https://npm.io/package/@contrast/patcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
