add-node-modules-path icon indicating copy to clipboard operation
add-node-modules-path copied to clipboard

Doesn't work with hoisted dependencies in monorepos

Open rassie opened this issue 2 years ago • 5 comments

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.

rassie avatar May 25 '22 09:05 rassie

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.

rassie avatar Jul 06 '22 07:07 rassie

This might be easily solved with a recursive function until node_modules does not exists since exec_path admits a list of paths.

texaco avatar Sep 10 '22 09:09 texaco

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.

codesuki avatar Sep 12 '22 00:09 codesuki

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.

forty avatar Oct 07 '22 16:10 forty

I don't have time for it but it sounds useful. If you send a PR I'll look at it.

codesuki avatar Oct 12 '22 08:10 codesuki