Skip to main content

Module pkg_managers

Module pkg_managers 

Source
Expand description

Detect which Node.js package manager produced the layout in a project root (npm, pnpm, yarn classic, or yarn-berry PnP).

The apply pipeline cares about this for two reasons:

  1. pnpm: node_modules/<pkg> is typically a symlink into the content-addressed global store. Patching the link target would corrupt every other project on the machine that points at the same store entry. The CoW guard in crate::patch::cow::break_hardlink_if_needed is what actually fixes this; this detector just lets the CLI surface a one-line “we detected pnpm, applied with CoW” notice so users understand the layout was handled.

  2. yarn-berry / Plug’n’Play: packages do not live on disk at all — they’re inside .yarn/cache/<pkg>.zip and resolved via a custom Node loader (.pnp.cjs). The npm crawler can’t reach them, and rewriting bytes inside a zip is a totally different operation than rewriting bytes in node_modules/. The right move is to refuse with a clear error and point the user at yarn patch <pkg>.

Classic yarn (yarn.lock + a real node_modules/) behaves like npm at the filesystem level, so no special handling is needed.

Enums§

NpmPkgManager
Identified Node.js package manager / layout flavor.

Functions§

detect_npm_pkg_manager
Detect the package manager that produced the layout under project_root. Inspection is purely path-based — no shell-outs, no parsing — so the detector is fast and side-effect-free.