summaryrefslogtreecommitdiff
path: root/deps/npm/lib/adduser.js
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2021-03-04 17:40:28 -0500
committerRuy Adorno <ruyadorno@hotmail.com>2021-03-05 15:32:56 -0500
commitf3d3769f9f6da29fb562f25074cda6c86a0366df (patch)
tree4a233305c3fcb06212a83a080f2ac988dbd3a6b9 /deps/npm/lib/adduser.js
parent54bb7e3bff819431af1e860daf46844859e002c0 (diff)
downloadnode-new-f3d3769f9f6da29fb562f25074cda6c86a0366df.tar.gz
deps: upgrade npm to 7.6.1
PR-URL: https://github.com/nodejs/node/pull/37606 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'deps/npm/lib/adduser.js')
-rw-r--r--deps/npm/lib/adduser.js105
1 files changed, 57 insertions, 48 deletions
diff --git a/deps/npm/lib/adduser.js b/deps/npm/lib/adduser.js
index c68c2b80f8..dac0f5a468 100644
--- a/deps/npm/lib/adduser.js
+++ b/deps/npm/lib/adduser.js
@@ -1,5 +1,4 @@
const log = require('npmlog')
-const npm = require('./npm.js')
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
const replaceInfo = require('./utils/replace-info.js')
@@ -10,66 +9,76 @@ const authTypes = {
sso: require('./auth/sso.js'),
}
-const usage = usageUtil(
- 'adduser',
- 'npm adduser [--registry=url] [--scope=@orgname] [--always-auth]'
-)
+class AddUser {
+ constructor (npm) {
+ this.npm = npm
+ }
-const cmd = (args, cb) => adduser(args).then(() => cb()).catch(cb)
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ get usage () {
+ return usageUtil(
+ 'adduser',
+ 'npm adduser [--registry=url] [--scope=@orgname] [--always-auth]'
+ )
+ }
-const getRegistry = ({ scope, registry }) => {
- if (scope) {
- const scopedRegistry = npm.config.get(`${scope}:registry`)
- const cliRegistry = npm.config.get('registry', 'cli')
- if (scopedRegistry && !cliRegistry)
- return scopedRegistry
+ exec (args, cb) {
+ this.adduser(args).then(() => cb()).catch(cb)
}
- return registry
-}
-const getAuthType = ({ authType }) => {
- const type = authTypes[authType]
+ async adduser (args) {
+ const { scope } = this.npm.flatOptions
+ const registry = this.getRegistry(this.npm.flatOptions)
+ const auth = this.getAuthType(this.npm.flatOptions)
+ const creds = this.npm.config.getCredentialsByURI(registry)
- if (!type)
- throw new Error('no such auth module')
+ log.disableProgress()
- return type
-}
+ log.notice('', `Log in on ${replaceInfo(registry)}`)
-const updateConfig = async ({ newCreds, registry, scope }) => {
- npm.config.delete('_token', 'user') // prevent legacy pollution
+ const { message, newCreds } = await auth(this.npm, {
+ ...this.npm.flatOptions,
+ creds,
+ registry,
+ scope,
+ })
- if (scope)
- npm.config.set(scope + ':registry', registry, 'user')
+ await this.updateConfig({
+ newCreds,
+ registry,
+ scope,
+ })
- npm.config.setCredentialsByURI(registry, newCreds)
- await npm.config.save('user')
-}
+ output(message)
+ }
-const adduser = async (args) => {
- const { scope } = npm.flatOptions
- const registry = getRegistry(npm.flatOptions)
- const auth = getAuthType(npm.flatOptions)
- const creds = npm.config.getCredentialsByURI(registry)
+ getRegistry ({ scope, registry }) {
+ if (scope) {
+ const scopedRegistry = this.npm.config.get(`${scope}:registry`)
+ const cliRegistry = this.npm.config.get('registry', 'cli')
+ if (scopedRegistry && !cliRegistry)
+ return scopedRegistry
+ }
+ return registry
+ }
- log.disableProgress()
+ getAuthType ({ authType }) {
+ const type = authTypes[authType]
- log.notice('', `Log in on ${replaceInfo(registry)}`)
+ if (!type)
+ throw new Error('no such auth module')
- const { message, newCreds } = await auth({
- ...npm.flatOptions,
- creds,
- registry,
- scope,
- })
+ return type
+ }
- await updateConfig({
- newCreds,
- registry,
- scope,
- })
+ async updateConfig ({ newCreds, registry, scope }) {
+ this.npm.config.delete('_token', 'user') // prevent legacy pollution
- output(message)
-}
+ if (scope)
+ this.npm.config.set(scope + ':registry', registry, 'user')
-module.exports = Object.assign(cmd, { usage })
+ this.npm.config.setCredentialsByURI(registry, newCreds)
+ await this.npm.config.save('user')
+ }
+}
+module.exports = AddUser