Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: completion.js
module.exports = completion
[0] Fix | Delete
[1] Fix | Delete
completion.usage = 'source <(npm completion)'
[2] Fix | Delete
[3] Fix | Delete
var npm = require('./npm.js')
[4] Fix | Delete
var npmconf = require('./config/core.js')
[5] Fix | Delete
var configDefs = npmconf.defs
[6] Fix | Delete
var configTypes = configDefs.types
[7] Fix | Delete
var shorthands = configDefs.shorthands
[8] Fix | Delete
var nopt = require('nopt')
[9] Fix | Delete
var configNames = Object.keys(configTypes)
[10] Fix | Delete
.filter(function (e) { return e.charAt(0) !== '_' })
[11] Fix | Delete
var shorthandNames = Object.keys(shorthands)
[12] Fix | Delete
var allConfs = configNames.concat(shorthandNames)
[13] Fix | Delete
var once = require('once')
[14] Fix | Delete
var isWindowsShell = require('./utils/is-windows-shell.js')
[15] Fix | Delete
var output = require('./utils/output.js')
[16] Fix | Delete
[17] Fix | Delete
completion.completion = function (opts, cb) {
[18] Fix | Delete
if (opts.w > 3) return cb()
[19] Fix | Delete
[20] Fix | Delete
var fs = require('graceful-fs')
[21] Fix | Delete
var path = require('path')
[22] Fix | Delete
var bashExists = null
[23] Fix | Delete
var zshExists = null
[24] Fix | Delete
fs.stat(path.resolve(process.env.HOME, '.bashrc'), function (er) {
[25] Fix | Delete
bashExists = !er
[26] Fix | Delete
next()
[27] Fix | Delete
})
[28] Fix | Delete
fs.stat(path.resolve(process.env.HOME, '.zshrc'), function (er) {
[29] Fix | Delete
zshExists = !er
[30] Fix | Delete
next()
[31] Fix | Delete
})
[32] Fix | Delete
function next () {
[33] Fix | Delete
if (zshExists === null || bashExists === null) return
[34] Fix | Delete
var out = []
[35] Fix | Delete
if (zshExists) out.push('~/.zshrc')
[36] Fix | Delete
if (bashExists) out.push('~/.bashrc')
[37] Fix | Delete
if (opts.w === 2) {
[38] Fix | Delete
out = out.map(function (m) {
[39] Fix | Delete
return ['>>', m]
[40] Fix | Delete
})
[41] Fix | Delete
}
[42] Fix | Delete
cb(null, out)
[43] Fix | Delete
}
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
function completion (args, cb) {
[47] Fix | Delete
if (isWindowsShell) {
[48] Fix | Delete
var e = new Error('npm completion supported only in MINGW / Git bash on Windows')
[49] Fix | Delete
e.code = 'ENOTSUP'
[50] Fix | Delete
e.errno = require('constants').ENOTSUP // eslint-disable-line node/no-deprecated-api
[51] Fix | Delete
return cb(e)
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
// if the COMP_* isn't in the env, then just dump the script.
[55] Fix | Delete
if (process.env.COMP_CWORD === undefined ||
[56] Fix | Delete
process.env.COMP_LINE === undefined ||
[57] Fix | Delete
process.env.COMP_POINT === undefined) {
[58] Fix | Delete
return dumpScript(cb)
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
console.error(process.env.COMP_CWORD)
[62] Fix | Delete
console.error(process.env.COMP_LINE)
[63] Fix | Delete
console.error(process.env.COMP_POINT)
[64] Fix | Delete
[65] Fix | Delete
// get the partial line and partial word,
[66] Fix | Delete
// if the point isn't at the end.
[67] Fix | Delete
// ie, tabbing at: npm foo b|ar
[68] Fix | Delete
var w = +process.env.COMP_CWORD
[69] Fix | Delete
var words = args.map(unescape)
[70] Fix | Delete
var word = words[w]
[71] Fix | Delete
var line = process.env.COMP_LINE
[72] Fix | Delete
var point = +process.env.COMP_POINT
[73] Fix | Delete
var partialLine = line.substr(0, point)
[74] Fix | Delete
var partialWords = words.slice(0, w)
[75] Fix | Delete
[76] Fix | Delete
// figure out where in that last word the point is.
[77] Fix | Delete
var partialWord = args[w]
[78] Fix | Delete
var i = partialWord.length
[79] Fix | Delete
while (partialWord.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) {
[80] Fix | Delete
i--
[81] Fix | Delete
}
[82] Fix | Delete
partialWord = unescape(partialWord.substr(0, i))
[83] Fix | Delete
partialWords.push(partialWord)
[84] Fix | Delete
[85] Fix | Delete
var opts = {
[86] Fix | Delete
words: words,
[87] Fix | Delete
w: w,
[88] Fix | Delete
word: word,
[89] Fix | Delete
line: line,
[90] Fix | Delete
lineLength: line.length,
[91] Fix | Delete
point: point,
[92] Fix | Delete
partialLine: partialLine,
[93] Fix | Delete
partialWords: partialWords,
[94] Fix | Delete
partialWord: partialWord,
[95] Fix | Delete
raw: args
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
cb = wrapCb(cb, opts)
[99] Fix | Delete
[100] Fix | Delete
console.error(opts)
[101] Fix | Delete
[102] Fix | Delete
if (partialWords.slice(0, -1).indexOf('--') === -1) {
[103] Fix | Delete
if (word.charAt(0) === '-') return configCompl(opts, cb)
[104] Fix | Delete
if (words[w - 1] &&
[105] Fix | Delete
words[w - 1].charAt(0) === '-' &&
[106] Fix | Delete
!isFlag(words[w - 1])) {
[107] Fix | Delete
// awaiting a value for a non-bool config.
[108] Fix | Delete
// don't even try to do this for now
[109] Fix | Delete
console.error('configValueCompl')
[110] Fix | Delete
return configValueCompl(opts, cb)
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
// try to find the npm command.
[115] Fix | Delete
// it's the first thing after all the configs.
[116] Fix | Delete
// take a little shortcut and use npm's arg parsing logic.
[117] Fix | Delete
// don't have to worry about the last arg being implicitly
[118] Fix | Delete
// boolean'ed, since the last block will catch that.
[119] Fix | Delete
var parsed = opts.conf =
[120] Fix | Delete
nopt(configTypes, shorthands, partialWords.slice(0, -1), 0)
[121] Fix | Delete
// check if there's a command already.
[122] Fix | Delete
console.error(parsed)
[123] Fix | Delete
var cmd = parsed.argv.remain[1]
[124] Fix | Delete
if (!cmd) return cmdCompl(opts, cb)
[125] Fix | Delete
[126] Fix | Delete
Object.keys(parsed).forEach(function (k) {
[127] Fix | Delete
npm.config.set(k, parsed[k])
[128] Fix | Delete
})
[129] Fix | Delete
[130] Fix | Delete
// at this point, if words[1] is some kind of npm command,
[131] Fix | Delete
// then complete on it.
[132] Fix | Delete
// otherwise, do nothing
[133] Fix | Delete
cmd = npm.commands[cmd]
[134] Fix | Delete
if (cmd && cmd.completion) return cmd.completion(opts, cb)
[135] Fix | Delete
[136] Fix | Delete
// nothing to do.
[137] Fix | Delete
cb()
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
function dumpScript (cb) {
[141] Fix | Delete
var fs = require('graceful-fs')
[142] Fix | Delete
var path = require('path')
[143] Fix | Delete
var p = path.resolve(__dirname, 'utils/completion.sh')
[144] Fix | Delete
[145] Fix | Delete
// The Darwin patch below results in callbacks first for the write and then
[146] Fix | Delete
// for the error handler, so make sure we only call our callback once.
[147] Fix | Delete
cb = once(cb)
[148] Fix | Delete
[149] Fix | Delete
fs.readFile(p, 'utf8', function (er, d) {
[150] Fix | Delete
if (er) return cb(er)
[151] Fix | Delete
d = d.replace(/^#!.*?\n/, '')
[152] Fix | Delete
[153] Fix | Delete
process.stdout.write(d, function () { cb() })
[154] Fix | Delete
process.stdout.on('error', function (er) {
[155] Fix | Delete
// Darwin is a pain sometimes.
[156] Fix | Delete
//
[157] Fix | Delete
// This is necessary because the "source" or "." program in
[158] Fix | Delete
// bash on OS X closes its file argument before reading
[159] Fix | Delete
// from it, meaning that you get exactly 1 write, which will
[160] Fix | Delete
// work most of the time, and will always raise an EPIPE.
[161] Fix | Delete
//
[162] Fix | Delete
// Really, one should not be tossing away EPIPE errors, or any
[163] Fix | Delete
// errors, so casually. But, without this, `. <(npm completion)`
[164] Fix | Delete
// can never ever work on OS X.
[165] Fix | Delete
if (er.errno === 'EPIPE') er = null
[166] Fix | Delete
cb(er)
[167] Fix | Delete
})
[168] Fix | Delete
})
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
function unescape (w) {
[172] Fix | Delete
if (w.charAt(0) === '\'') return w.replace(/^'|'$/g, '')
[173] Fix | Delete
else return w.replace(/\\ /g, ' ')
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
function escape (w) {
[177] Fix | Delete
if (!w.match(/\s+/)) return w
[178] Fix | Delete
return '\'' + w + '\''
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
// The command should respond with an array. Loop over that,
[182] Fix | Delete
// wrapping quotes around any that have spaces, and writing
[183] Fix | Delete
// them to stdout. Use console.log, not the outfd config.
[184] Fix | Delete
// If any of the items are arrays, then join them with a space.
[185] Fix | Delete
// Ie, returning ['a', 'b c', ['d', 'e']] would allow it to expand
[186] Fix | Delete
// to: 'a', 'b c', or 'd' 'e'
[187] Fix | Delete
function wrapCb (cb, opts) {
[188] Fix | Delete
return function (er, compls) {
[189] Fix | Delete
if (!Array.isArray(compls)) compls = compls ? [compls] : []
[190] Fix | Delete
compls = compls.map(function (c) {
[191] Fix | Delete
if (Array.isArray(c)) c = c.map(escape).join(' ')
[192] Fix | Delete
else c = escape(c)
[193] Fix | Delete
return c
[194] Fix | Delete
})
[195] Fix | Delete
[196] Fix | Delete
if (opts.partialWord) {
[197] Fix | Delete
compls = compls.filter(function (c) {
[198] Fix | Delete
return c.indexOf(opts.partialWord) === 0
[199] Fix | Delete
})
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
console.error([er && er.stack, compls, opts.partialWord])
[203] Fix | Delete
if (er || compls.length === 0) return cb(er)
[204] Fix | Delete
[205] Fix | Delete
output(compls.join('\n'))
[206] Fix | Delete
cb()
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
// the current word has a dash. Return the config names,
[211] Fix | Delete
// with the same number of dashes as the current word has.
[212] Fix | Delete
function configCompl (opts, cb) {
[213] Fix | Delete
var word = opts.word
[214] Fix | Delete
var split = word.match(/^(-+)((?:no-)*)(.*)$/)
[215] Fix | Delete
var dashes = split[1]
[216] Fix | Delete
var no = split[2]
[217] Fix | Delete
var flags = configNames.filter(isFlag)
[218] Fix | Delete
console.error(flags)
[219] Fix | Delete
[220] Fix | Delete
return cb(null, allConfs.map(function (c) {
[221] Fix | Delete
return dashes + c
[222] Fix | Delete
}).concat(flags.map(function (f) {
[223] Fix | Delete
return dashes + (no || 'no-') + f
[224] Fix | Delete
})))
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
// expand with the valid values of various config values.
[228] Fix | Delete
// not yet implemented.
[229] Fix | Delete
function configValueCompl (opts, cb) {
[230] Fix | Delete
console.error('configValue', opts)
[231] Fix | Delete
return cb(null, [])
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
// check if the thing is a flag or not.
[235] Fix | Delete
function isFlag (word) {
[236] Fix | Delete
// shorthands never take args.
[237] Fix | Delete
var split = word.match(/^(-*)((?:no-)+)?(.*)$/)
[238] Fix | Delete
var no = split[2]
[239] Fix | Delete
var conf = split[3]
[240] Fix | Delete
return no || configTypes[conf] === Boolean || shorthands[conf]
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
// complete against the npm commands
[244] Fix | Delete
function cmdCompl (opts, cb) {
[245] Fix | Delete
return cb(null, npm.fullList)
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function