()
| 104 | } |
| 105 | |
| 106 | export 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 | // |
no test coverage detected
searching dependent graphs…