pnpm.io
pnpm.io copied to clipboard
Document missing pnpmfile hooks
Adds documentation for;
filterLogfetchersimportPackagepreResolution
Local/global pnpmfiles and how they interact is now also documented. For example readPackage is supported by local and global pnpmfiles, and both run with global going first so (global then local).
Run & review this pull request in StackBlitz Codeflow.
@Silic0nS0ldier is attempting to deploy a commit to the pnpm Team on Vercel.
A member of the Team first needs to authorize it.
I am not sure we want people to know about these. All these hooks except filterLog were added for easier integration with stackblitz. Would anyone else want to use these low level hooks?
Would anyone else want to use these low level hooks?
The use case I have in mind sourcing package data directly from the npm_package rule (Bazel ruleset), such that content is identical across Bazel builds and external tools that use pnpm's node_modules (including IDEs).
There are alternatives.
- Using Bazel's
node_modulesinstance instead, a crude implementation of which exists here, however.- This breaks the
pnpm patchworkflow which relies on pnpm'snode_modulesexisting. Related: https://github.com/pnpm/pnpm/issues/8257 - pnpm is able to do in-place mutation of
node_moduleswhich is faster than than copying over. Symlinking would close this gap though (why didn't I think to do that before...)
- This breaks the
- Write generated sources into version control (what we are doing at Canva right now).
- Prevents in-place modification of files. This pattern is unusual in the NodeJS ecosystem, but in the context of our build system such transforms are useful it allows input sources to be normalised (stripping comments, etc) to avoid unnecessary rebuilds, however.
- Packages in pnpm's
node_modulesinclude more files than intended (e.g..tssources). - Need to confirm generated sources are up-to-date on CI.
- Devs need to run an extra step whenever such packages are modified (a common complaint, especially when testing changes to a workflow like ESLint which operates outside of our build system).
- More noise to sift through in code review (even with Github hiding the diff of these generated files).
- Redirect
workspace:*references to tarballs/directories built by Bazel (e.g. by mutating the lockfile). This alternative came about from ideation and has not been implemented. The cons of this haven't had much thought at this stage, off the top of my head it could affect dependency resolution (workspace packages are already by default something of a special case unless they are injected).
The use case I give likely runs into the same dependency resolution issue as mentioned in (3). The issue is not insurmountable (a great deal of flexibility is afforded across all the hooks) but would need to be carefully thought out.
@zkochan I noticed pnpm v10.10 allows preResolution, importPackage and fetchers hooks in the local .pnpmfile.cjs. Has their scope (stackblitz integration) expanded?
A few other companies are planning to use the hooks. I added short docs about them: https://github.com/pnpm/pnpm.io/commit/4e852ad5052cb3217560d72643522ce2bbea139c
also, it is now easier to ship hooks via dependencies, using configDependencies.