Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
adduser.js51 linesDownload Raw Back to commands
1const { log, output } = require('proc-log')
2const { redactLog: replaceInfo } = require('@npmcli/redact')
3const auth = require('../utils/auth.js')
4const BaseCommand = require('../base-cmd.js')
5
6class AddUser extends BaseCommand {
7  static description = 'Add a registry user account'
8  static name = 'adduser'
9  static params = [
10    'registry',
11    'scope',
12    'auth-type',
13  ]
14
15  async exec () {
16    const scope = this.npm.config.get('scope')
17    let registry = this.npm.config.get('registry')
18
19    if (scope) {
20      const scopedRegistry = this.npm.config.get(`${scope}:registry`)
21      const cliRegistry = this.npm.config.get('registry', 'cli')
22      if (scopedRegistry && !cliRegistry) {
23        registry = scopedRegistry
24      }
25    }
26
27    const creds = this.npm.config.getCredentialsByURI(registry)
28
29    log.notice('', `Log in on ${replaceInfo(registry)}`)
30
31    const { message, newCreds } = await auth.adduser(this.npm, {
32      ...this.npm.flatOptions,
33      creds,
34      registry,
35    })
36
37    this.npm.config.delete('_token', 'user') // prevent legacy pollution
38    this.npm.config.setCredentialsByURI(registry, newCreds)
39
40    if (scope) {
41      this.npm.config.set(scope + ':registry', registry, 'user')
42    }
43
44    await this.npm.config.save('user')
45
46    output.standard(message)
47  }
48}
49
50module.exports = AddUser
51