MCPcopy Index your code
hub / github.com/angular/angular-cli / createNpmConfigForAuthentication

Function createNpmConfigForAuthentication

tests/e2e/utils/registry.ts:52–98  ·  view source on GitHub ↗
(
  /**
   * When true, the authentication token will be scoped to the registry URL.
   * @example
   * ```ini
   * //localhost:4876/:_auth="dGVzdGluZzpzM2NyZXQ="
   * ```
   *
   * When false, the authentication will be added as seperate key.
   * @example
   * ```ini
   * _auth="dGVzdGluZzpzM2NyZXQ="`
   * ```
   */
  scopedAuthentication = true,
  /** When true, an incorrect token is used. Use this to validate authentication failures. */
  invalidToken = false,
)

Source from the content-addressed store, hash-verified

50const VALID_TOKEN = `dGVzdGluZzpzM2NyZXQ=`;
51
52export async function createNpmConfigForAuthentication(
53 /**
54 * When true, the authentication token will be scoped to the registry URL.
55 * @example
56 * ```ini
57 * //localhost:4876/:_auth="dGVzdGluZzpzM2NyZXQ="
58 * ```
59 *
60 * When false, the authentication will be added as seperate key.
61 * @example
62 * ```ini
63 * _auth="dGVzdGluZzpzM2NyZXQ="`
64 * ```
65 */
66 scopedAuthentication = true,
67 /** When true, an incorrect token is used. Use this to validate authentication failures. */
68 invalidToken = false,
69): Promise<void> {
70 const token = invalidToken ? `invalid=` : VALID_TOKEN;
71 const registry = (getGlobalVariable('package-secure-registry') as string).replace(/^\w+:/, '');
72
73 await writeFile(
74 '.npmrc',
75 scopedAuthentication
76 ? `
77${registry}/:_auth="${token}"
78registry=http:${registry}
79`
80 : `
81_auth="${token}"
82registry=http:${registry}
83`,
84 );
85
86 await writeFile(
87 '.yarnrc',
88 scopedAuthentication
89 ? `
90${registry}/:_auth "${token}"
91registry http:${registry}
92`
93 : `
94_auth "${token}"
95registry http:${registry}
96`,
97 );
98}
99
100export function setNpmEnvVarsForAuthentication(
101 /** When true, an incorrect token is used. Use this to validate authentication failures. */

Callers 3

yarn-env-vars.tsFile · 0.90
secure-registry.tsFile · 0.90

Calls 2

getGlobalVariableFunction · 0.90
writeFileFunction · 0.90

Tested by

no test coverage detected