Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Run root prepare lifecycle script on repeat installs (or expose an install hook) #16545

Closed

Description

@JounQin

Context

Since pnpm 11, optimisticRepeatInstall defaults to true, so a repeated pnpm install short-circuits (Lockfile is up to date, resolution step is skipped) and root lifecycle scripts — notably prepare — are not run. pnpm ≤ 10 ran the root prepare on every pnpm install.

Use case

Tools that (re)generate local, non-dependency state on install rely on prepare running on every install:

  • simple-git-hooks (git hooks) — if .simple-git-hooks.json changes, the hooks in .git/hooks go stale until a real install happens, and there is no automatic way to refresh them.
  • codegen / type generation.

Yarn Berry has a plugin for exactly this (run prepare after yarn install): https://github.com/un-es/yarn-plugin-prepare-lifecycle. There is no pnpm equivalent.

What I verified

  • .pnpmfile.cjs hooks (readPackage, afterAllResolved, preResolution, filterLog) only run during resolution, which is skipped on a repeat install, so they cannot be used as a workaround. afterAllResolved fires on the first install but not on the repeat.
  • optimisticRepeatInstall: false no longer restores the behaviour in v12: the setting is read (pnpm config get optimistic-repeat-install → false), but pnpm install still prints Lockfile is up to date, resolution step is skipped and prepare does not run.
  • pnpm has no general plugin API (unlike Yarn Berry's install-completion hook), so a userland plugin cannot fill the gap.

Behaviour across versions (repeat install, project with a real dependency, "prepare": "echo PREPARE_RAN"):

pnpm prepare on repeat install
7 / 8 / 9 / 10 runs
11 / 12 skipped

Request

One of:

  1. Restore the pnpm ≤ 10 behaviour when optimisticRepeatInstall: false — i.e. still run root lifecycle scripts even when the install is otherwise up to date; or
  2. Add a setting to always run the root prepare (and/or other root lifecycle scripts) on every pnpm install; or
  3. Expose an install-completion hook so a plugin like yarn-plugin-prepare-lifecycle can be ported.

Related

Activity

  1. github-actions commented on Oct 3, 2026

    @github-actions
    Contributor

    @JounQin, are you planning to open a pull request for this? If so, reply here and a maintainer will assign the issue to you, so nobody else starts on the same fix.

  2. JounQin commented on Oct 3, 2026

    @JounQin
    Author

    yes

  3. zkochan commented on Oct 3, 2026

    @zkochan
    Member

    I don't know what would be the best solution for this. Maybe we need to skip install using the optimistic skip but then run the hooks anyway every time. Although that would also reintroduce a lot of sf operations to read the scripts. That might make repeat install much slower on huge monorepos.

  4. JounQin commented on Oct 3, 2026

    @JounQin
    Author

    At least optimisticRepeatInstall: false should run the hooks anyway?


    My two cents:

    optimisticRepeatInstall:
      afterAllResolved: false
  5. zkochan commented on Oct 3, 2026

    @zkochan
    Member

    I don't know. I am thinking there are two realistic options. Either we accept this as the default and if you want the hook to run on every install, you may disable optimistic repeat install. Or we could only check the lifecycle scripts in the root package.json.

  6. zkochan commented on Oct 3, 2026

    @zkochan
    Member

    Opened #16566 for this.

    On pnpm v11, optimisticRepeatInstall: false already runs the projects' lifecycle scripts, including prepare, on every repeat install. On v12 that setting didn't help, because the install still ended early once node_modules was up to date. The PR fixes v12 so optimisticRepeatInstall: false behaves as it does on v11 and v10. The default (optimistic) behaviour stays the same: when nothing changed, the install is skipped and so are its scripts. The PR also documents that, so turning the setting off is the documented way to run prepare on every install. It doesn't add a new setting or hook.


    Written by an agent (Claude Code, claude-opus-5-5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions