Question: How do I run npm scripts that reference binaries from the root package?
See original GitHub issueI am hoping to keep all shared devDependencies
in the root package to avoid duplication, but this prevents us from running npm scripts directly from the sub-packages. Hereās a concrete example:
Each sub-package defines scripts like this:
"scripts": {
...
"check": "gts check"
...
}
Our root package is the only package that declares a dependency to gts
:
"packages": {
...
"gts": "^1.1.2",
...
}
I can run this with no problem:
$ lerna run check
<SUCCESS!>
However, we cannot run this from a sub-package (the reason we want to do this is to speed up the running of the scripts, especially when most devs only focus on one of the sub-packages at a time):
$ npm run check
sh: gts: command not found
npm ERR! code ELIFECYCLE
...
This makes sense since gts is not in the sub-packageās node_modules/.bin
folder. I could fix the problem if I change the scripts in each sub-package to something like this:
"scripts": {
...
"check": "PATH=$PATH:../../node_modules/.bin && gts check"
...
}
but, this isnāt ideal. For one thing, it does not work on Windows. Another possibility would be to explicitly push all devDependencies down to the sub-packages and nohoist them all. This is not ideal either since we are now duplicating a lot of our packages.
Is there a better solution that doesnāt involve package duplication or explicitly adding paths to each of our scripts?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
Using relative path to the cli without change path should work for you
I donāt see a prefect way to do it. Even if lerna add some cli to resolve the path, the sub-projects doesnāt even know lerna unless you install it as a global tool in your PATH.
another workaround would be, use a shell with the PATH environment variable to the root node_modules/.bin before start working of the day.
which could cause another problem if you work on multiple projects.
Hi Folks š
You may or may not know that lerna is now under the stewardship of Nrwl (announcement here https://github.com/lerna/lerna/issues/3121), a company with a long history of not just producing valuable open-source software (OSS), but also backing others (at the time of writing, Nrwl has donated over $50,000 to OSS it hasnāt created, see https://opencollective.com/nx for full details).
Quite simply, Nrwl ā¤ļø OSS, and is committed to making lerna the best it can be. We use it ourselves.
In order to take this awesome project forward from its current state, it is important that we focus our finite resources on what is most important to lerna users in 2022.
With that in mind, we have identified this issue as being potentially stale due to its age and/or lack of recent activity.
Next steps:
We want to give you some time to read through this comment and take action per one of the steps outlined below, so for the next 14 days we will not make any further updates to this issue.
@aeisenberg as the original author of this issue, we are looking to you to update us on the latest state of this as it relates to the latest version of lerna.
Please choose one of the steps below, depending on what type of issue this is:
A) If this issue relates to a potential BUG in the latest version of lerna:
B) If this issue is a FEATURE request to be added to the latest version of lerna:
C) If this issue is a QUESTION which is applicable to latest version of lerna:
D) If this issue is no longer applicable to the latest version of lerna:
If we do not hear from @aeisenberg on this thread within the next 14 days, we will automatically close this issue.
If you are another user impacted by this issue but it ends up being closed as part of this process, we still want to hear from you! Please simply head over to our new issue templates and fill out all the requested details on the template which applies to your situation:
https://github.com/lerna/lerna/issues/new/choose
Thank you all for being a part of this awesome community, we could not be more excited to help move things forward from here š š