Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: fund.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
const path = require('path')
[2] Fix | Delete
[3] Fix | Delete
const archy = require('archy')
[4] Fix | Delete
const figgyPudding = require('figgy-pudding')
[5] Fix | Delete
const readPackageTree = require('read-package-tree')
[6] Fix | Delete
[7] Fix | Delete
const npm = require('./npm.js')
[8] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[9] Fix | Delete
const fetchPackageMetadata = require('./fetch-package-metadata.js')
[10] Fix | Delete
const computeMetadata = require('./install/deps.js').computeMetadata
[11] Fix | Delete
const readShrinkwrap = require('./install/read-shrinkwrap.js')
[12] Fix | Delete
const mutateIntoLogicalTree = require('./install/mutate-into-logical-tree.js')
[13] Fix | Delete
const output = require('./utils/output.js')
[14] Fix | Delete
const openUrl = require('./utils/open-url.js')
[15] Fix | Delete
const { getFundingInfo, retrieveFunding, validFundingField, flatCacheSymbol } = require('./utils/funding.js')
[16] Fix | Delete
[17] Fix | Delete
const FundConfig = figgyPudding({
[18] Fix | Delete
browser: {}, // used by ./utils/open-url
[19] Fix | Delete
global: {},
[20] Fix | Delete
json: {},
[21] Fix | Delete
unicode: {},
[22] Fix | Delete
which: {}
[23] Fix | Delete
})
[24] Fix | Delete
[25] Fix | Delete
module.exports = fundCmd
[26] Fix | Delete
[27] Fix | Delete
const usage = require('./utils/usage')
[28] Fix | Delete
fundCmd.usage = usage(
[29] Fix | Delete
'fund',
[30] Fix | Delete
'npm fund [--json]',
[31] Fix | Delete
'npm fund [--browser] [[<@scope>/]<pkg> [--which=<fundingSourceNumber>]'
[32] Fix | Delete
)
[33] Fix | Delete
[34] Fix | Delete
fundCmd.completion = function (opts, cb) {
[35] Fix | Delete
const argv = opts.conf.argv.remain
[36] Fix | Delete
switch (argv[2]) {
[37] Fix | Delete
case 'fund':
[38] Fix | Delete
return cb(null, [])
[39] Fix | Delete
default:
[40] Fix | Delete
return cb(new Error(argv[2] + ' not recognized'))
[41] Fix | Delete
}
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
function printJSON (fundingInfo) {
[45] Fix | Delete
return JSON.stringify(fundingInfo, null, 2)
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
// the human-printable version does some special things that turned out to
[49] Fix | Delete
// be very verbose but hopefully not hard to follow: we stack up items
[50] Fix | Delete
// that have a shared url/type and make sure they're printed at the highest
[51] Fix | Delete
// level possible, in that process they also carry their dependencies along
[52] Fix | Delete
// with them, moving those up in the visual tree
[53] Fix | Delete
function printHuman (fundingInfo, opts) {
[54] Fix | Delete
const flatCache = fundingInfo[flatCacheSymbol]
[55] Fix | Delete
[56] Fix | Delete
const { name, version } = fundingInfo
[57] Fix | Delete
const printableVersion = version ? `@${version}` : ''
[58] Fix | Delete
[59] Fix | Delete
const items = Object.keys(flatCache).map((url) => {
[60] Fix | Delete
const deps = flatCache[url]
[61] Fix | Delete
[62] Fix | Delete
const packages = deps.map((dep) => {
[63] Fix | Delete
const { name, version } = dep
[64] Fix | Delete
[65] Fix | Delete
const printableVersion = version ? `@${version}` : ''
[66] Fix | Delete
return `${name}${printableVersion}`
[67] Fix | Delete
})
[68] Fix | Delete
[69] Fix | Delete
return {
[70] Fix | Delete
label: url,
[71] Fix | Delete
nodes: [packages.join(', ')]
[72] Fix | Delete
}
[73] Fix | Delete
})
[74] Fix | Delete
[75] Fix | Delete
return archy({ label: `${name}${printableVersion}`, nodes: items }, '', { unicode: opts.unicode })
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
function openFundingUrl (packageName, fundingSourceNumber, cb) {
[79] Fix | Delete
function getUrlAndOpen (packageMetadata) {
[80] Fix | Delete
const { funding } = packageMetadata
[81] Fix | Delete
const validSources = [].concat(retrieveFunding(funding)).filter(validFundingField)
[82] Fix | Delete
[83] Fix | Delete
if (validSources.length === 1 || (fundingSourceNumber > 0 && fundingSourceNumber <= validSources.length)) {
[84] Fix | Delete
const { type, url } = validSources[fundingSourceNumber ? fundingSourceNumber - 1 : 0]
[85] Fix | Delete
const typePrefix = type ? `${type} funding` : 'Funding'
[86] Fix | Delete
const msg = `${typePrefix} available at the following URL`
[87] Fix | Delete
openUrl(url, msg, cb)
[88] Fix | Delete
} else if (!(fundingSourceNumber >= 1)) {
[89] Fix | Delete
validSources.forEach(({ type, url }, i) => {
[90] Fix | Delete
const typePrefix = type ? `${type} funding` : 'Funding'
[91] Fix | Delete
const msg = `${typePrefix} available at the following URL`
[92] Fix | Delete
console.log(`${i + 1}: ${msg}: ${url}`)
[93] Fix | Delete
})
[94] Fix | Delete
console.log('Run `npm fund [<@scope>/]<pkg> --which=1`, for example, to open the first funding URL listed in that package')
[95] Fix | Delete
cb()
[96] Fix | Delete
} else {
[97] Fix | Delete
const noFundingError = new Error(`No valid funding method available for: ${packageName}`)
[98] Fix | Delete
noFundingError.code = 'ENOFUND'
[99] Fix | Delete
[100] Fix | Delete
throw noFundingError
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
fetchPackageMetadata(
[105] Fix | Delete
packageName,
[106] Fix | Delete
'.',
[107] Fix | Delete
{ fullMetadata: true },
[108] Fix | Delete
function (err, packageMetadata) {
[109] Fix | Delete
if (err) return cb(err)
[110] Fix | Delete
getUrlAndOpen(packageMetadata)
[111] Fix | Delete
}
[112] Fix | Delete
)
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
function fundCmd (args, cb) {
[116] Fix | Delete
const opts = FundConfig(npmConfig())
[117] Fix | Delete
const dir = path.resolve(npm.dir, '..')
[118] Fix | Delete
const packageName = args[0]
[119] Fix | Delete
const numberArg = opts.which
[120] Fix | Delete
[121] Fix | Delete
const fundingSourceNumber = numberArg && parseInt(numberArg, 10)
[122] Fix | Delete
[123] Fix | Delete
if (numberArg !== undefined && (String(fundingSourceNumber) !== numberArg || fundingSourceNumber < 1)) {
[124] Fix | Delete
const err = new Error('`npm fund [<@scope>/]<pkg> [--which=fundingSourceNumber]` must be given a positive integer')
[125] Fix | Delete
err.code = 'EFUNDNUMBER'
[126] Fix | Delete
throw err
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
if (opts.global) {
[130] Fix | Delete
const err = new Error('`npm fund` does not support global packages')
[131] Fix | Delete
err.code = 'EFUNDGLOBAL'
[132] Fix | Delete
throw err
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if (packageName) {
[136] Fix | Delete
openFundingUrl(packageName, fundingSourceNumber, cb)
[137] Fix | Delete
return
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
readPackageTree(dir, function (err, tree) {
[141] Fix | Delete
if (err) {
[142] Fix | Delete
process.exitCode = 1
[143] Fix | Delete
return cb(err)
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
readShrinkwrap.andInflate(tree, function () {
[147] Fix | Delete
const fundingInfo = getFundingInfo(
[148] Fix | Delete
mutateIntoLogicalTree.asReadInstalled(
[149] Fix | Delete
computeMetadata(tree)
[150] Fix | Delete
)
[151] Fix | Delete
)
[152] Fix | Delete
[153] Fix | Delete
const print = opts.json
[154] Fix | Delete
? printJSON
[155] Fix | Delete
: printHuman
[156] Fix | Delete
[157] Fix | Delete
output(
[158] Fix | Delete
print(
[159] Fix | Delete
fundingInfo,
[160] Fix | Delete
opts
[161] Fix | Delete
)
[162] Fix | Delete
)
[163] Fix | Delete
cb(err, tree)
[164] Fix | Delete
})
[165] Fix | Delete
})
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function