Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: config.js
/* eslint-disable standard/no-callback-literal */
[0] Fix | Delete
module.exports = config
[1] Fix | Delete
[2] Fix | Delete
var log = require('npmlog')
[3] Fix | Delete
var npm = require('./npm.js')
[4] Fix | Delete
var npmconf = require('./config/core.js')
[5] Fix | Delete
var fs = require('graceful-fs')
[6] Fix | Delete
var writeFileAtomic = require('write-file-atomic')
[7] Fix | Delete
var types = npmconf.defs.types
[8] Fix | Delete
var ini = require('ini')
[9] Fix | Delete
var editor = require('editor')
[10] Fix | Delete
var os = require('os')
[11] Fix | Delete
var path = require('path')
[12] Fix | Delete
var mkdirp = require('gentle-fs').mkdir
[13] Fix | Delete
var umask = require('./utils/umask')
[14] Fix | Delete
var usage = require('./utils/usage')
[15] Fix | Delete
var output = require('./utils/output')
[16] Fix | Delete
var noProgressTillDone = require('./utils/no-progress-while-running').tillDone
[17] Fix | Delete
[18] Fix | Delete
config.usage = usage(
[19] Fix | Delete
'config',
[20] Fix | Delete
'npm config set <key> <value>' +
[21] Fix | Delete
'\nnpm config get [<key>]' +
[22] Fix | Delete
'\nnpm config delete <key>' +
[23] Fix | Delete
'\nnpm config list [--json]' +
[24] Fix | Delete
'\nnpm config edit' +
[25] Fix | Delete
'\nnpm set <key> <value>' +
[26] Fix | Delete
'\nnpm get [<key>]'
[27] Fix | Delete
)
[28] Fix | Delete
config.completion = function (opts, cb) {
[29] Fix | Delete
var argv = opts.conf.argv.remain
[30] Fix | Delete
if (argv[1] !== 'config') argv.unshift('config')
[31] Fix | Delete
if (argv.length === 2) {
[32] Fix | Delete
var cmds = ['get', 'set', 'delete', 'ls', 'rm', 'edit']
[33] Fix | Delete
if (opts.partialWord !== 'l') cmds.push('list')
[34] Fix | Delete
return cb(null, cmds)
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
var action = argv[2]
[38] Fix | Delete
switch (action) {
[39] Fix | Delete
case 'set':
[40] Fix | Delete
// todo: complete with valid values, if possible.
[41] Fix | Delete
if (argv.length > 3) return cb(null, [])
[42] Fix | Delete
// fallthrough
[43] Fix | Delete
/* eslint no-fallthrough:0 */
[44] Fix | Delete
case 'get':
[45] Fix | Delete
case 'delete':
[46] Fix | Delete
case 'rm':
[47] Fix | Delete
return cb(null, Object.keys(types))
[48] Fix | Delete
case 'edit':
[49] Fix | Delete
case 'list':
[50] Fix | Delete
case 'ls':
[51] Fix | Delete
return cb(null, [])
[52] Fix | Delete
default:
[53] Fix | Delete
return cb(null, [])
[54] Fix | Delete
}
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
// npm config set key value
[58] Fix | Delete
// npm config get key
[59] Fix | Delete
// npm config list
[60] Fix | Delete
function config (args, cb) {
[61] Fix | Delete
var action = args.shift()
[62] Fix | Delete
switch (action) {
[63] Fix | Delete
case 'set':
[64] Fix | Delete
return set(args[0], args[1], cb)
[65] Fix | Delete
case 'get':
[66] Fix | Delete
return get(args[0], cb)
[67] Fix | Delete
case 'delete':
[68] Fix | Delete
case 'rm':
[69] Fix | Delete
case 'del':
[70] Fix | Delete
return del(args[0], cb)
[71] Fix | Delete
case 'list':
[72] Fix | Delete
case 'ls':
[73] Fix | Delete
return npm.config.get('json') ? listJson(cb) : list(cb)
[74] Fix | Delete
case 'edit':
[75] Fix | Delete
return edit(cb)
[76] Fix | Delete
default:
[77] Fix | Delete
return unknown(action, cb)
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
function edit (cb) {
[82] Fix | Delete
var e = npm.config.get('editor')
[83] Fix | Delete
var which = npm.config.get('global') ? 'global' : 'user'
[84] Fix | Delete
var f = npm.config.get(which + 'config')
[85] Fix | Delete
if (!e) return cb(new Error('No EDITOR config or environ set.'))
[86] Fix | Delete
npm.config.save(which, function (er) {
[87] Fix | Delete
if (er) return cb(er)
[88] Fix | Delete
fs.readFile(f, 'utf8', function (er, data) {
[89] Fix | Delete
if (er) data = ''
[90] Fix | Delete
data = [
[91] Fix | Delete
';;;;',
[92] Fix | Delete
'; npm ' + (npm.config.get('global')
[93] Fix | Delete
? 'globalconfig' : 'userconfig') + ' file',
[94] Fix | Delete
'; this is a simple ini-formatted file',
[95] Fix | Delete
'; lines that start with semi-colons are comments.',
[96] Fix | Delete
'; read `npm help config` for help on the various options',
[97] Fix | Delete
';;;;',
[98] Fix | Delete
'',
[99] Fix | Delete
data
[100] Fix | Delete
].concat([
[101] Fix | Delete
';;;;',
[102] Fix | Delete
'; all options with default values',
[103] Fix | Delete
';;;;'
[104] Fix | Delete
]).concat(Object.keys(npmconf.defaults).reduce(function (arr, key) {
[105] Fix | Delete
var obj = {}
[106] Fix | Delete
obj[key] = npmconf.defaults[key]
[107] Fix | Delete
if (key === 'logstream') return arr
[108] Fix | Delete
return arr.concat(
[109] Fix | Delete
ini.stringify(obj)
[110] Fix | Delete
.replace(/\n$/m, '')
[111] Fix | Delete
.replace(/^/g, '; ')
[112] Fix | Delete
.replace(/\n/g, '\n; ')
[113] Fix | Delete
.split('\n'))
[114] Fix | Delete
}, []))
[115] Fix | Delete
.concat([''])
[116] Fix | Delete
.join(os.EOL)
[117] Fix | Delete
mkdirp(path.dirname(f), function (er) {
[118] Fix | Delete
if (er) return cb(er)
[119] Fix | Delete
writeFileAtomic(
[120] Fix | Delete
f,
[121] Fix | Delete
data,
[122] Fix | Delete
function (er) {
[123] Fix | Delete
if (er) return cb(er)
[124] Fix | Delete
editor(f, { editor: e }, noProgressTillDone(cb))
[125] Fix | Delete
}
[126] Fix | Delete
)
[127] Fix | Delete
})
[128] Fix | Delete
})
[129] Fix | Delete
})
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
function del (key, cb) {
[133] Fix | Delete
if (!key) return cb(new Error('no key provided'))
[134] Fix | Delete
var where = npm.config.get('global') ? 'global' : 'user'
[135] Fix | Delete
npm.config.del(key, where)
[136] Fix | Delete
npm.config.save(where, cb)
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
function set (key, val, cb) {
[140] Fix | Delete
if (key === undefined) {
[141] Fix | Delete
return unknown('', cb)
[142] Fix | Delete
}
[143] Fix | Delete
if (val === undefined) {
[144] Fix | Delete
if (key.indexOf('=') !== -1) {
[145] Fix | Delete
var k = key.split('=')
[146] Fix | Delete
key = k.shift()
[147] Fix | Delete
val = k.join('=')
[148] Fix | Delete
} else {
[149] Fix | Delete
val = ''
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
key = key.trim()
[153] Fix | Delete
val = val.trim()
[154] Fix | Delete
log.info('config', 'set %j %j', key, val)
[155] Fix | Delete
var where = npm.config.get('global') ? 'global' : 'user'
[156] Fix | Delete
if (key.match(/umask/)) val = umask.fromString(val)
[157] Fix | Delete
npm.config.set(key, val, where)
[158] Fix | Delete
npm.config.save(where, cb)
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
function get (key, cb) {
[162] Fix | Delete
if (!key) return list(cb)
[163] Fix | Delete
if (!publicVar(key)) {
[164] Fix | Delete
return cb(new Error('---sekretz---'))
[165] Fix | Delete
}
[166] Fix | Delete
var val = npm.config.get(key)
[167] Fix | Delete
if (key.match(/umask/)) val = umask.toString(val)
[168] Fix | Delete
output(val)
[169] Fix | Delete
cb()
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
function sort (a, b) {
[173] Fix | Delete
return a > b ? 1 : -1
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
function publicVar (k) {
[177] Fix | Delete
return !(k.charAt(0) === '_' || k.indexOf(':_') !== -1)
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
function getKeys (data) {
[181] Fix | Delete
return Object.keys(data).filter(publicVar).sort(sort)
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
function listJson (cb) {
[185] Fix | Delete
const publicConf = npm.config.keys.reduce((publicConf, k) => {
[186] Fix | Delete
var value = npm.config.get(k)
[187] Fix | Delete
[188] Fix | Delete
if (publicVar(k) &&
[189] Fix | Delete
// argv is not really config, it's command config
[190] Fix | Delete
k !== 'argv' &&
[191] Fix | Delete
// logstream is a Stream, and would otherwise produce circular refs
[192] Fix | Delete
k !== 'logstream') publicConf[k] = value
[193] Fix | Delete
[194] Fix | Delete
return publicConf
[195] Fix | Delete
}, {})
[196] Fix | Delete
[197] Fix | Delete
output(JSON.stringify(publicConf, null, 2))
[198] Fix | Delete
return cb()
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
function listFromSource (title, conf, long) {
[202] Fix | Delete
var confKeys = getKeys(conf)
[203] Fix | Delete
var msg = ''
[204] Fix | Delete
[205] Fix | Delete
if (confKeys.length) {
[206] Fix | Delete
msg += '; ' + title + '\n'
[207] Fix | Delete
confKeys.forEach(function (k) {
[208] Fix | Delete
var val = JSON.stringify(conf[k])
[209] Fix | Delete
if (conf[k] !== npm.config.get(k)) {
[210] Fix | Delete
if (!long) return
[211] Fix | Delete
msg += '; ' + k + ' = ' + val + ' (overridden)\n'
[212] Fix | Delete
} else msg += k + ' = ' + val + '\n'
[213] Fix | Delete
})
[214] Fix | Delete
msg += '\n'
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
return msg
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
function list (cb) {
[221] Fix | Delete
var msg = ''
[222] Fix | Delete
var long = npm.config.get('long')
[223] Fix | Delete
[224] Fix | Delete
var cli = npm.config.sources.cli.data
[225] Fix | Delete
var cliKeys = getKeys(cli)
[226] Fix | Delete
if (cliKeys.length) {
[227] Fix | Delete
msg += '; cli configs\n'
[228] Fix | Delete
cliKeys.forEach(function (k) {
[229] Fix | Delete
if (cli[k] && typeof cli[k] === 'object') return
[230] Fix | Delete
if (k === 'argv') return
[231] Fix | Delete
msg += k + ' = ' + JSON.stringify(cli[k]) + '\n'
[232] Fix | Delete
})
[233] Fix | Delete
msg += '\n'
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
// env configs
[237] Fix | Delete
msg += listFromSource('environment configs', npm.config.sources.env.data, long)
[238] Fix | Delete
[239] Fix | Delete
// project config file
[240] Fix | Delete
var project = npm.config.sources.project
[241] Fix | Delete
msg += listFromSource('project config ' + project.path, project.data, long)
[242] Fix | Delete
[243] Fix | Delete
// user config file
[244] Fix | Delete
msg += listFromSource('userconfig ' + npm.config.get('userconfig'), npm.config.sources.user.data, long)
[245] Fix | Delete
[246] Fix | Delete
// global config file
[247] Fix | Delete
msg += listFromSource('globalconfig ' + npm.config.get('globalconfig'), npm.config.sources.global.data, long)
[248] Fix | Delete
[249] Fix | Delete
// builtin config file
[250] Fix | Delete
var builtin = npm.config.sources.builtin || {}
[251] Fix | Delete
if (builtin && builtin.data) {
[252] Fix | Delete
msg += listFromSource('builtin config ' + builtin.path, builtin.data, long)
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
// only show defaults if --long
[256] Fix | Delete
if (!long) {
[257] Fix | Delete
msg += '; node bin location = ' + process.execPath + '\n' +
[258] Fix | Delete
'; cwd = ' + process.cwd() + '\n' +
[259] Fix | Delete
'; HOME = ' + process.env.HOME + '\n' +
[260] Fix | Delete
'; "npm config ls -l" to show all defaults.\n'
[261] Fix | Delete
[262] Fix | Delete
output(msg)
[263] Fix | Delete
return cb()
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
var defaults = npmconf.defaults
[267] Fix | Delete
var defKeys = getKeys(defaults)
[268] Fix | Delete
msg += '; default values\n'
[269] Fix | Delete
defKeys.forEach(function (k) {
[270] Fix | Delete
if (defaults[k] && typeof defaults[k] === 'object') return
[271] Fix | Delete
var val = JSON.stringify(defaults[k])
[272] Fix | Delete
if (defaults[k] !== npm.config.get(k)) {
[273] Fix | Delete
msg += '; ' + k + ' = ' + val + ' (overridden)\n'
[274] Fix | Delete
} else msg += k + ' = ' + val + '\n'
[275] Fix | Delete
})
[276] Fix | Delete
msg += '\n'
[277] Fix | Delete
[278] Fix | Delete
output(msg)
[279] Fix | Delete
return cb()
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
function unknown (action, cb) {
[283] Fix | Delete
cb('Usage:\n' + config.usage)
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function