Skip to content

automatically loaded configDependency hooks run after workspace pnpmfile hooks #9891

@fpapado

Description

@fpapado

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

No response

Which area(s) of pnpm are affected? (leave empty if unsure)

Hooks

Link to the code that reproduces this issue or a replay of the bug

https://github.com/fpapado/pnpmfile-order

Reproduction steps

Following the instructions from https://github.com/fpapado/pnpmfile-order:

# install the dependencies first
pnpm install

# patch plugin-better-defaults to log out its updateConfig invocation
patch -p1 < add-log.patch

pnpm install

Observe the console output:

own pnpmfile updateConfig
plugin-better-defaults pnpmfile updateConfig

Another way to test this would be to to change a specific config value in a workspace's pnpmfile (e.g. verifyDepsBeforeInstall), and observe whether plugin-better-defaults overrides it.

I tried both pnpm 10.15.0 (latest) and pnpm 10.14.0 (just to see whether the latest changes around loading affected this; they seem not to)

Describe the Bug

The documentation for config dependencies, as well as pnpmfile and plugin-better-defaults hints that a workspace's own pnpmfile executes after config dependency hooks (at least for updateConfig).

https://pnpm.io/pnpmfile#hooksupdateconfigconfig-config--promiseconfig

Allows you to modify the configuration settings used by pnpm. This hook is most useful when paired with configDependencies, allowing you to share and reuse settings across different Git repositories.

https://github.com/pnpm/plugin-better-defaults?tab=readme-ov-file#what-it-changes

You can extend or override these settings in your own .pnpmfile.cjs.

With explicit config dependency invocation (importing the config dependencies and calling them), the caller can control the order and merge configs, which matches the documentation.

However, when relying on the autoloading behaviour, it seems that the workspace pnpmfile updateConfig hook executes first, and the config dependencies' after. This makes it impossible to override config dependency settings from a workspace pnpmfile, as far as I can tell.

Please let me know if I can provide more context, or if I am wrong about this 😌

Expected Behavior

I would expect the pnpmfile hooks from the workspace to execute after the autoloaded config dependency hooks. However, I might be wrong! In either scenario, I have a hunch that the docs could be more explicit about the order when autoloading is used.

Which Node.js version are you using?

22.18.0

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions