MCPcopy Index your code
hub / github.com/nodejs/node / set

Method set

deps/npm/lib/commands/profile.js:161–222  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

159 }
160
161 async set (args) {
162 const conf = { ...this.npm.flatOptions }
163 const prop = (args[0] || '').toLowerCase().trim()
164
165 let value = args.length > 1 ? args.slice(1).join(' ') : null
166
167 const readPasswords = async () => {
168 const newpassword = await readUserInfo.password('New password: ')
169 const confirmedpassword = await readUserInfo.password(' Again: ')
170
171 if (newpassword !== confirmedpassword) {
172 log.warn('profile', 'Passwords do not match, please try again.')
173 return readPasswords()
174 }
175
176 return newpassword
177 }
178
179 if (prop !== 'password' && value === null) {
180 throw new Error('npm profile set <prop> <value>')
181 }
182
183 if (prop === 'password' && value !== null) {
184 throw new Error(
185 'npm profile set password\n' +
186 'Do not include your current or new passwords on the command line.')
187 }
188
189 if (writableProfileKeys.indexOf(prop) === -1) {
190 throw new Error(`"${prop}" is not a property we can set. ` +
191 `Valid properties are: ` + writableProfileKeys.join(', '))
192 }
193
194 if (prop === 'password') {
195 const current = await readUserInfo.password('Current password: ')
196 const newpassword = await readPasswords()
197
198 value = { old: current, new: newpassword }
199 }
200
201 // FIXME: Work around to not clear everything other than what we're setting
202 const user = await get(conf)
203 const newUser = {}
204
205 for (const key of writableProfileKeys) {
206 newUser[key] = user[key]
207 }
208
209 newUser[prop] = value
210
211 const result = await otplease(this.npm, conf, c => set(newUser, c))
212
213 if (this.npm.config.get('json')) {
214 output.buffer({ [prop]: result[prop] })
215 } else if (this.npm.config.get('parseable')) {
216 output.standard(prop + '\t' + result[prop])
217 } else if (result[prop] != null) {
218 output.standard('Set', prop, 'to', result[prop])

Callers 1

execMethod · 0.95

Calls 9

otpleaseFunction · 0.85
passwordMethod · 0.80
sliceMethod · 0.65
getMethod · 0.65
getFunction · 0.50
setFunction · 0.50
joinMethod · 0.45
indexOfMethod · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected