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
package.json
packages:
- package-a:
package.json
index.js
- package-b:
package.json
index.js
and package.json at root has a postinstall script and the children don't. When we do yarn at the top level it installs dependencies and run the postinstall 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 local postinstall script and not the one in the top level manifest.
What is the expected behavior?
In yarn workspaces, any yarn or yarn add or yarn 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 is v8.11.1
OS is macOS
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?
Most helpful comment
Right, I forgot that
postinstallalso runs afteryarn add. Running the top levelpostinstallscript after anyyarn addseems reasonable to me.