MCPcopy Create free account
hub / github.com/changesets/changesets / getTokenIsRequired

Function getTokenIsRequired

packages/cli/src/commands/publish/npm-utils.ts:106–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104}
105
106export async function getTokenIsRequired() {
107 const { scope, registry } = getCorrectRegistry();
108 // Due to a super annoying issue in yarn, we have to manually override this env variable
109 // See: https://github.com/yarnpkg/yarn/issues/2935#issuecomment-355292633
110 const envOverride = {
111 [scope ? `npm_config_${scope}:registry` : "npm_config_registry"]: registry,
112 };
113 let result = await spawn("npm", ["profile", "get", "--json"], {
114 env: Object.assign({}, process.env, envOverride),
115 });
116 if (result.code !== 0) {
117 error(
118 "error while checking if token is required",
119 result.stderr.toString().trim() || result.stdout.toString().trim()
120 );
121 return false;
122 }
123 let json = jsonParse(result.stdout.toString());
124 if (json.error || !json.tfa || !json.tfa.mode) {
125 return false;
126 }
127 return json.tfa.mode === "auth-and-writes";
128}
129
130// `npm info <pkg> --json` (aka `npm view`) behavior:
131//

Callers 1

getTwoFactorStateFunction · 0.90

Calls 3

errorFunction · 0.90
getCorrectRegistryFunction · 0.85
jsonParseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…