2

This question (How to use executables from a package installed locally in node_modules?) asked this years ago, and the correct answer is generally just npx these days. But in a monorepo with multiple subpackages, with different dependencies in each, although it works, it is quite annoying.

my_pkg_root/ package.json
   sub_pkg_1/ package.json
   sub_pkg_2/ package.json
   sub_pkg_3/ package.json

Or other more deeply nested structures. If in the root you install npm i myutils providing doit, then in my_pkg_root, npx doit just works. In the subpackages, what npx (apparently) does is it first installs myutils in the local node_modules, runs the script, and then UNINSTALLs it. Every time.

I want a way that (using npx or other techniques) I can run doit in any subdirectory without all the annoying overhead.

Marvin
  • 2,537
  • 24
  • 35
  • Have you looked at https://www.npmjs.com/package/bin-up – Peter W Dec 03 '20 at 23:49
  • No. Although it just changes from having to install the tool everywhere, to having to install `bin-up` everywhere. Does it work if you install `bin-up` globally? – Marvin Dec 04 '20 at 23:42
  • yeah seems to work as a global package. Also, I'm thinking that even if I have to install it as a dev dep in each monorepo sub-package, it's much better (from a disk space and version-consistency perspective) than, say, trying to keep "typescript" et al in sync. – Peter W Dec 06 '20 at 03:42

1 Answers1

0

Extending the idea from this answer (https://stackoverflow.com/a/15157360/500902) to the earlier question, if you know the monorepo's root directory name (seems likely, here assuming /internal)

alias basex='_x=$(pwd); PATH="${_x%%/internal/*}/internal/node_modules/.bin:$PATH"'

Then from anywhere in the monorepo, you can do

basex doit
Marvin
  • 2,537
  • 24
  • 35