pnpm

Stop PNPM from hoisting common deps / isolate subdirectories


I have a project using PNPM that will, amongst other things, clone various projects, install their dependencies, and run their tests. As I need to do some manipulation of the dependencies, I decided to do this internally to the project, rather than cloning to a temp directory, so my project structure looks a bit like the following:

my-proj/
--node_modules/
--src/
--workspaces/
----proj-1/
------node_modules/
------...
----proj-2/
------node_modules/
------...
----...

This works really well when projects are using NPM or Yarn; a node_modules/ folder is added inside of the projects isolating their dependencies as it should. This is a simple cd workspaces/proj-1 && <package manger> install situation, where <package manger> is determined by the lock file of the repo.

PNPM, however, decides it's going to hoist dependencies to my-proj/node_modules. Note that my-proj is not a PNPM workspace and should make no attempt to install the modules of the subprojects -- the project managers of projects within the workspace directory are varied and unknown. The tests of proj-2 end up failing as it's using a module in my-proj/node_modules, rather than my-proj/workspaces/proj-2/node_modules which does not adhere to conditions it (proj-2) needs.

How can I tell PNPM to knock it off and stick to the current directory, ignoring any node_modules directories higher up in the directory tree? Importantly, how can I do this without altering anything within proj-2?


Solution

  • This seems to work, though it makes no sense:

    .npmrc

    node-linker=hoisted
    

    Better answers appreciated if they exist.