Even with the existence of 鈥攏on-interactive from #2770, it seems that login still requires a TTY.
If you try to programmatically login where a TTY doesn't exist you get:
error An unexpected error occurred: "Can't answer a question unless a user TTY".
yarn - 0.24.4
os - macos, linux
Help needed, send a PR
@bestander 馃憢 im gonna give a crack
@Ramblurr
If you try to programmatically login where a TTY doesn't exist you get:
can you give an explicit example of how you are trying to log in programmatically, or are you and @bestander asking for a way to yarn login with username/password flags and vars? ie yarn login username='[email protected]' password='abcd'
My actual example might not be too helpful as it is in gradle. However what I'm trying to do is the equivalent of:
echo -e "$USER\n$EMAIL\n$PASS" | yarn login --registry=$NPM_CONFIG_REGISTRY
However this doesn't work when their is no tty.
A way to login with env vars or flags would be great.
ok so it sounds like env variables are the way to go.
So the procedure that I have in mind is to check if the session is not tty, if not then check to see that there exists env vars $NPM_USER, $NPM_EMAIL. If they exist we pipe them into the login procedure and raise an error otherwise. I'm still looking into all of the instances where the password is required, but I imagine it would be almost identical as the one outlined above.
how does all that sound @bestander
So the procedure that I have in mind is to check if the session is not tty, if not then check to see that there exists env vars
This would make using env vars not possible when there is no tty, which is a valid use case. For example some CI servers run their commands in an interactive shell.
I would say, use the env vars if present, else fall back to prompting. If there is no tty and no env vars, then display an appropriate error message.
I'm having this exact same issue. What this means is we can't use yarn in our Dockerfiles, which means we have to get rid of it everywhere. Can anybody help here?
Yea, using Yarn in CI or containers is a real pain in the ass. I'm surprised this isn't a bigger issue for people. I wonder what they're doing.
@Ramblurr it is actually a priority. We are just not aware of all the problems you are having! Would you mind filing issues about them?
I like your suggestion built onto https://github.com/yarnpkg/yarn/issues/3450#issuecomment-304293911 so why not send a PR?
Something that worked before for us was we'd just used Github private keys and point to GH repositories. The issue came when we tried to switch to Lerna, which uses package designations from NPM. We're probably going to have to go back to the Github pointers. npm can't handle non-interactive login, either. But the private GH packages don't require that, just the keys!
Most helpful comment
Yea, using Yarn in CI or containers is a real pain in the ass. I'm surprised this isn't a bigger issue for people. I wonder what they're doing.