add-node-modules-path
add-node-modules-path copied to clipboard
Doesn't work with hoisted dependencies in monorepos
In monorepos, especially managed by lerna
or pnpm
, npm bin
doesn't return the correct binary directory, since a binary can be either hoisted to the root directory of the monorepo or be located in the package's node_modules
. Solving this would probably require adding both the monorepo's node_modules/.bin
as well package's node_modules/.bin
to the path.
Hmm. It seems to work somewhat correctly if I set add-node-modules-path-command
to pnpm bin
, since it's also capable of resolving paths in npm
and yarn
projects.
This might be easily solved with a recursive function until node_modules does not exists since exec_path
admits a list of paths.
Hi! The first implementation actually used to recurse, but we got rid of it due to security concerns: https://github.com/codesuki/add-node-modules-path/issues/15
I think if setting add-node-modules-path-command
works as @rassie described then this is definitely the way to go.
Ideally I would be able to have a list of commands and this would add all the successful results: For example
(setq add-node-modules-path-commands '("npm bin" "pnpm bin -w"))
This way I could have both binary in the local package and in the workspace package (if any) - and it would work with both npm and pnpm packages with the same config.
I don't have time for it but it sounds useful. If you send a PR I'll look at it.