Skip to content

@stephansama/pnpm-hooks

source code documentation npm socket.dev jsr npm downloads

tsdown

preconfigured pnpm hooks and types for pnpmfile

Open Table of contents
Terminal window
pnpm install @stephansama/pnpm-hooks

pnpmfile hooks are useful, but the types and small reusable hook helpers are easy to reimplement in every workspace. This package collects both:

  • ready-to-use pnpm hook implementations
  • exported TypeScript types for authoring your own pnpmfile hooks

The package exposes two top-level namespaces:

  • readPackageHooks prebuilt readPackage hook utilities
  • types pnpm hook types including PnpmFileHooks, ReadPackageHook, BeforePackingHook, AfterAllResolvedHook, ImportPackageHook, PreResolutionHook, and UpdateConfigHook

The sections below are organized so each hook can carry its own behavior notes and example output as the package grows.

Pins dependency ranges by removing leading ^ and ~ prefixes from:

  • dependencies
  • devDependencies
  • optionalDependencies

This runs on every manifest processed by pnpm through the readPackage hook, which makes it useful for workspaces that want consistently pinned transitive and nested dependency ranges during resolution.

Given a dependency manifest like this:

{
"dependencies": {
"react": "^19.1.0"
},
"devDependencies": {
"typescript": "~5.9.2"
},
"optionalDependencies": {
"@types/node": "^24.0.0"
}
}

pinAllDependencies rewrites it to:

{
"dependencies": {
"react": "19.1.0"
},
"devDependencies": {
"typescript": "5.9.2"
},
"optionalDependencies": {
"@types/node": "24.0.0"
}
}
  • Node.js >=24
  • a pnpm setup that loads a pnpmfile
import { readPackageHooks, type types } from "@stephansama/pnpm-hooks";
export const hooks = {
readPackage: readPackageHooks.pinAllDependencies,
} satisfies types.PnpmFileHooks;
Module Description

index

read-package

types