Fix auth setup for Yarn Berry#654
Conversation
🦋 Changeset detectedLatest commit: e881258 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| "@changesets/action": minor | ||
| --- | ||
|
|
||
| Internal auth setup for provided `NPM_TOKEN` environment variable when using Yarn gets now written to Yarn Berry's `~/.yarnrc.yml`. |
There was a problem hiding this comment.
is there a big benefit from doing this compared to just using env vars?
if anything, storing the value in a file if we might not need to sounds like a bad idea
There was a problem hiding this comment.
I agree and I was under the impression that you kinda can't get away from storing it in .npmrc file. But, according to a fresh agent run, npm actually supports overlaying its configs with environment variables, so... this should work:
let changesetPublishOutput = await getExecOutput(script, undefined, {
cwd,
ignoreReturnCode: true,
env: {
...process.env,
GITHUB_TOKEN: githubToken,
...(process.env.NPM_TOKEN && {
"npm_config_//registry.npmjs.org/:_authToken": process.env.NPM_TOKEN,
}),
},
});I would have to test this out to ensure it works but this would be a great way of improving this (thanks for the pushback!).
That said:
- pnpm doesn't seem to support this. It might support it in older versions (pre v11) because it just delegated to the npm CLI for a bunch of this stuff, but v11 reimplements publishing and it doesn't seem to support this
- yarn classic supports
YARN_AUTH_TOKENandNPM_AUTH_TOKEN(yes, it supports an npm-named variable that npm itself doesn't support), and it also supports the weirdnpm_config_*shape too - yarn berry supports
YARN_NPM_AUTH_TOKEN
There was a problem hiding this comment.
okay, so for yarn we can use env vars, but for pnpm and npm we need to write it to a file, i see.
pnpm still supports .npmrc for just auth, and it can also be put in ~/.config/pnpm/auth.ini or (i think) ~/.config/pnpm/rc
I think we should not do it at all. We have a lot of issues around the token handling, we should leave for Yarn needs like this, like what you did in the PR with .yarnrc.yml. It's not great but we can document it. One of the super annoying things with yarn these days. Plus, there's not a lot of reason to use tokens in CI these days with them having a short time limit. But if you really prefer to have a better DX for yarn, then I'd prefer |
@changesets/clito actually call Yarn when publishingchangesets/action/setup-authfor those that don't use trusted publishing? the current approach doesn't even respect configuration options likenpmrcAuthFile