Skip to content

Commit

Permalink
Do not check if a 2FA token is required when on other registries (#288)
Browse files Browse the repository at this point in the history
* Do not check if a 2FA token is required when on other registries

* Create purple-parrots-sin.md

* Fix soem other cases
  • Loading branch information
Noviny committed Mar 5, 2020
1 parent ca934d7 commit 2adfe66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-parrots-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Stop running `npm profile get` when using non-npm registries
9 changes: 2 additions & 7 deletions packages/cli/src/commands/publish/npm-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ export async function getTokenIsRequired() {
env: Object.assign({}, process.env, envOverride)
});
let json = JSON.parse(result.stdout.toString());
if (json.error) {
error(
`an error occurred while running \`npm profile get\`: ${json.error.code}`
);
error(json.error.summary);
if (json.error.summary) error(json.error.summary);
throw new ExitError(1);
if (json.error || !json.tfa || !json.tfa.mode) {
return false;
}
return json.tfa.mode === "auth-and-writes";
}
Expand Down
23 changes: 19 additions & 4 deletions packages/cli/src/commands/publish/publishPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@ export default async function publishPackages({
otp === undefined
? {
token: null,
isRequired: isCI
? Promise.resolve(false)
: // note: we're not awaiting this here, we want this request to happen in parallel with getUnpublishedPackages
npmUtils.getTokenIsRequired()
isRequired:
isCI ||
publicPackages.some(
x =>
x.config.publishConfig &&
(x.config.publishConfig as any).registry &&
(x.config.publishConfig as any).registry !==
"https://registry.npmjs.org" &&
(x.config.publishConfig as any).registry !==
"https://registry.yarnpkg.com"
) ||
(process.env.npm_config_registry !== undefined &&
process.env.npm_config_registry !==
"https://registry.npmjs.org" &&
process.env.npm_config_registry !==
"https://registry.yarnpkg.com")
? Promise.resolve(false)
: // note: we're not awaiting this here, we want this request to happen in parallel with getUnpublishedPackages
npmUtils.getTokenIsRequired()
}
: {
token: otp,
Expand Down

0 comments on commit 2adfe66

Please sign in to comment.