Open steelbrain opened 6 years ago
What's the benefit of running yarn install
in one of the package directories? Shouldn't it be the same as running it at the root directory since all modules are installed there?
I think it would be nice if yarn forwarded the postinstall
"event" to the children, after running install at the root, so that all postinstall
scripts run.
@GAumala Imagine adding a dependency to one of the package directories. You don't want to add a package to the root level, you wanna add it to that specific package.
Right, I forgot that postinstall
also runs after yarn add
. Running the top level postinstall
script after any yarn add
seems reasonable to me.
My workaround here is to add a postinstall
script to every workspace that runs yarn workspaces run postinstall
— it seems to work. Uses the script from the root package.json
and I only have to change the command in one place 👍
Edit: Sorry, this doesn't actually work. I guess the script command must've been cached or something since it did act as I want it to for a minute 🙂
@denkristoffer - would "postinstall": "cd ../.. && yarn postinstall"
work?
@mattfysh It works, but then you can't use it because if you do a top-level yarn add -W
all the postinstall
hooks from packages will run. If you have 3 packages in the workspace, the script will run 3 times + 1 for the root workspace.
Maybe we need another hook for the root workspace?
Any update on this issue? I have the same problem.🍻
Confirm this issue. Scenario: yarn workspaces provide the yarn workspaces focus
command which is intended to be run inside a specific packages folder to install only the dependencies needed there (great for CI to speed up jobs of certain packages).
That feature is de facto incompatible with postinstall
configuration through .yarnrc.yml
. At this point we're not speaking about a custom usage scenario or best / bad practice discussion but about built-in features that are not compatible when used as intended.
The current documentation around postinstall hooks is a little misleading - they states that the hook will be executed when package's dependency tree changes are written to the disk
. yarn.lock
updates after one local package is being yarn add
-ed to another one, but the hooks is not executed.
The nearest solution is afterWorkspaceDependencyAddition
plugin hook and it is executed in the right place, but not in the right "time" - before any physical file gets updated.
But I've found a way - https://gist.github.com/theKashey/3614c91bcd6bd3fb116172297a3522fb
Do you want to request a feature or report a bug? Bug
What is the current behavior?
Image a yarn workspaces repository with the following struct
and
package.json
at root has apostinstall
script and the children don't. When we doyarn
at the top level it installs dependencies and run thepostinstall
script from top level manifest, which is good at the expected behavior.But if you do
yarn
from any of the two packages, it will only invoke the localpostinstall
script and not the one in the top level manifest.What is the expected behavior?
In
yarn workspaces
, anyyarn
oryarn add
oryarn remove
in children should invoke lifecycle scripts in top level manifest too.Please mention your node.js, yarn and operating system version. Yarn version is
v1.3.2
Node version isv8.11.1
OS is macOS