-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workspaces don't run lifecycle scripts when linking local packages #3911
Comments
PR is welcome BTW :) |
I took a stab at it, but could figure out the code base unfortunately. All I can see is that |
Thanks for giving it a try, @jquense. If you want you can start with submitting a PR with a failing test and we can sort it out in a follow up. |
The failing test case linked in the issue is the best I can do sorry! Unfortunately I just don't have the time to spend hours learning the yarn codebase to try and fix this. |
Hi. I'm quite interested in yarn and workspaces in particular. I'll be giving a look at this as a possible first contribution. |
Awesome!
If you have any questions ask away
…On Mon, Jul 31, 2017 at 7:28 PM Burt Harris ***@***.***> wrote:
Hi. I'm quite interested in yarn and workspaces in particular. I'll be
giving a look at this as a possible first contribution.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3911 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACBdWBmqV2fFlBlOvOlXB77Ml0213Xw6ks5sTo1UgaJpZM4OUyrV>
.
|
@bestander I hit a snag right away, Issue #4059. Its almost certainly related to the fact I'm running Windows any hints on how to make that work? |
As a workaround you should be able to run tests like this |
Any word from anyone? I might have some time to jump, and I really would love to get this fixed :) I have to think that for most folks the lack of lifecycle scripts running is a dealbreaker for this feature? |
The core team is focused on fixing the most high priority issues right now, cases where Yarn may crash or install wrong versions of dependencies. This bug will be resolved eventually but considering that this is a community project the quickest way would be to spend time learning the codebase and sending a fix. |
Definately :) I'm not trying to be pushy or entitled just wanted to get a sense of where the issue was and if there was any existing work |
FWIW, it's not the blocker for my adoption of workspaces. I haven't figured out how to reliable add and remove dependencies (not unlikely to be user error). Handling this was annoying, but I just needed to add calls to the packages' prepare scripts to the parent package.json prepare script, which was a good enough workaround for me. |
Some more findings (yarn workspaces + lerna) that might be helpful With workspaces yarn install --pure-lockfile
yarn lerna run prepublish Lerna is smart enough to run The only thing is you should not enforce parallel lerna build like |
I've also found the prepublish lerna approah works well. However the one problem with the |
@jquense my workaround was to create additional entries that just require the actual binaries. Those entries are present at the moment of installation, so yarn has something to link. |
This behavior is currently making it impossible to migrate from Lerna's It is imperative that the |
Sounds reasonable, send a PR |
As a work-around, what seems to work for us is to add the lifecycle scripts to the root
If |
Incidentally, I'm now running into: #4973 The work-around I had posted above ^^^^ doesn't work for packages that aren't part of the workspace. |
I hope I don't deter anyone else from starting, so unless I update this thread and say I'm working on it please assume that I'm not working on it 😅 |
…are" Yarn workspaces currently don't run the npm lifecycle scripts of workspace packages (c.f. yarnpkg/yarn#3911). This is a simple way to get things working for now. Test plan: run `yarn` in the workspace root and see that tsc runs in expo.
I'm using @ccapndave technique to trigger |
I'm using @martijnthe's solution above and when I "scripts": {
"prepare": "lerna run prepare"
} |
For everybody in need of this feature. Take a look at |
Add prepare lifecycle script to root as a workaround for yarnpkg/yarn#3911
Came here looking for a different problem, but wanted to note that I don't terribly mind the current state of things, as it allows me to control which packages' scripts get run. Imagine a really, really big monorepo: you wouldn't necessarily want to run every prepare script just to work on one! If you want to simulate the proposed behavior, you can quite easily do so in the corresponding lifecycle script in the top-level {
// ...
"scripts": {
// This runs the `prepare` script in each package.
"prepare": "for P in packages/*/; do echo \"\n\n---------- $P\" && (cd $P && yarn prepare); done"
// This runs the `test` script in each package, but exits on the first failure
"test": "for P in packages/*/; do echo \"\n\n---------- $P\" && if ! (cd $P && yarn test); then exit 1; fi; done"
}
} I think any solution that changes the current behavior would need a way to opt out. |
@mike-marcacci if you want to avoid building already built packages, then skip build process if already built
|
Yes, I think that there is probably a better strategy than an all-or-nothing approach to this (regardless of what the default behavior is). Let's say I have a repo with 26 packages – I may want to work in
...without building the remaining 23 packages.
Additionally, running AuthX is one project I've been working on where the build order is important. Note how the build script hard-codes the order of some packages, which are dependancies of the later ones. |
The root Easiest way - using yarn workspaces with lerna:
If you are using yarn and yarn workspaces by itself:
Or you can specifically select which workspaces will have
Or you can write a shell script that parses the JSON output from
|
|
@ryanhiebert, is there any reason you don't want to use How does it [yarn] compare to Lerna?
I don't think it's worth the development time for |
Now if someone invokes yarn in the monorepo, or installs a package from a subdirectory with git (e.g. w/ gitpkg.now.sh) the build is automatically invoked. Because of yarnpkg/yarn#3911, we still need a top-level prepare.
Now if someone invokes yarn in the monorepo, or installs a package from a subdirectory with git (e.g. w/ gitpkg.now.sh) the build is automatically invoked. Because of yarnpkg/yarn#3911, we still need a top-level prepare.
I'd prefer not to have to pick up, learn, and manage an entire second tool that does a lot more than I need just for one feature. But I can't speak for others. |
When using yarn workspaces in lerna the npm lifecycle scripts don't work as intended. In this case running `prepare` in all bootstrapped packages is a step during `lerna bootstrap`. Adding the script in the root package.json solves the problem. More can be read [here](yarnpkg/yarn#3911 (comment)).
Now if someone invokes yarn in the monorepo, or installs a package from a subdirectory with git (e.g. w/ gitpkg.now.sh) the build is automatically invoked. Because of yarnpkg/yarn#3911, we still need a top-level prepare.
Now if someone invokes yarn in the monorepo, or installs a package from a subdirectory with git (e.g. w/ gitpkg.now.sh) the build is automatically invoked. Because of yarnpkg/yarn#3911, we still need a top-level prepare.
I cannot use preinstall and put a lerna command because the lerna package is not downloaded when executing the preinstall. Logs:
the 'prepare' script is not an option for me as I want to execute a script before the installation of the packages. |
What is the current behavior?
When you do a yarn install in a workspaces enabled project, yarn doesn't run the various lifecycle scripts for workspace packages, e.g.
prepare
prepublish
preinstall
etcIf the current behavior is a bug, please provide the steps to reproduce.
Here is a commit adding a failing test case: jquense@61eaf42
What is the expected behavior?
Lifecycle scripts are run for the local packages so they have an opportunity to build steps. This is what lerna does.
Please mention your node.js, yarn and operating system version.
yarn 27.5
node 8
Mac Sierra
cc @bestander
The text was updated successfully, but these errors were encountered: