We are developing an npm package
, a library, that is going to be included in other projects. This package sometimes has to run a shell script: it calls Prettier using ${somePath}/node_modules/prettier/bin/prettier.js
with some parameters.
The problem is that, because of the way node_modules
is generated, the location of that prettier.js
script doesn't seem to be guaranteed. It may be directly under the node_module
folder of the package, for example :
mainProject/node_modules/ourNpmPackage/node_modules/prettier/bin/prettier.js
or it can be moved by npm to the root node_module
folder :
mainProject/node_modules/prettier/bin/prettier.js
Our script has to know the location of this .js
to call it! What is the recommended way of locating it?
Would it be possible to first check in the local node_modules
, then, if prettier
is not found, in the parent's node_modules
, etc until the package is found? Would this be a solid solution?