Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: unpublish.js
/* eslint-disable standard/no-callback-literal */
[0] Fix | Delete
'use strict'
[1] Fix | Delete
[2] Fix | Delete
module.exports = unpublish
[3] Fix | Delete
[4] Fix | Delete
const BB = require('bluebird')
[5] Fix | Delete
[6] Fix | Delete
const figgyPudding = require('figgy-pudding')
[7] Fix | Delete
const libaccess = require('libnpm/access')
[8] Fix | Delete
const libunpub = require('libnpm/unpublish')
[9] Fix | Delete
const log = require('npmlog')
[10] Fix | Delete
const npa = require('npm-package-arg')
[11] Fix | Delete
const npm = require('./npm.js')
[12] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[13] Fix | Delete
const npmFetch = require('npm-registry-fetch')
[14] Fix | Delete
const otplease = require('./utils/otplease.js')
[15] Fix | Delete
const output = require('./utils/output.js')
[16] Fix | Delete
const path = require('path')
[17] Fix | Delete
const readJson = BB.promisify(require('read-package-json'))
[18] Fix | Delete
const usage = require('./utils/usage.js')
[19] Fix | Delete
const whoami = BB.promisify(require('./whoami.js'))
[20] Fix | Delete
[21] Fix | Delete
unpublish.usage = usage(
[22] Fix | Delete
'unpublish',
[23] Fix | Delete
'\nnpm unpublish [<@scope>/]<pkg>@<version>' +
[24] Fix | Delete
'\nnpm unpublish [<@scope>/]<pkg> --force'
[25] Fix | Delete
)
[26] Fix | Delete
[27] Fix | Delete
function UsageError () {
[28] Fix | Delete
throw Object.assign(new Error(`Usage: ${unpublish.usage}`), {
[29] Fix | Delete
code: 'EUSAGE'
[30] Fix | Delete
})
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
const UnpublishConfig = figgyPudding({
[34] Fix | Delete
force: {},
[35] Fix | Delete
loglevel: {},
[36] Fix | Delete
silent: {}
[37] Fix | Delete
})
[38] Fix | Delete
[39] Fix | Delete
unpublish.completion = function (cliOpts, cb) {
[40] Fix | Delete
if (cliOpts.conf.argv.remain.length >= 3) return cb()
[41] Fix | Delete
[42] Fix | Delete
whoami([], true).then(username => {
[43] Fix | Delete
if (!username) { return [] }
[44] Fix | Delete
const opts = UnpublishConfig(npmConfig())
[45] Fix | Delete
return libaccess.lsPackages(username, opts).then(access => {
[46] Fix | Delete
// do a bit of filtering at this point, so that we don't need
[47] Fix | Delete
// to fetch versions for more than one thing, but also don't
[48] Fix | Delete
// accidentally a whole project.
[49] Fix | Delete
let pkgs = Object.keys(access)
[50] Fix | Delete
if (!cliOpts.partialWord || !pkgs.length) { return pkgs }
[51] Fix | Delete
const pp = npa(cliOpts.partialWord).name
[52] Fix | Delete
pkgs = pkgs.filter(p => !p.indexOf(pp))
[53] Fix | Delete
if (pkgs.length > 1) return pkgs
[54] Fix | Delete
return npmFetch.json(npa(pkgs[0]).escapedName, opts).then(doc => {
[55] Fix | Delete
const vers = Object.keys(doc.versions)
[56] Fix | Delete
if (!vers.length) {
[57] Fix | Delete
return pkgs
[58] Fix | Delete
} else {
[59] Fix | Delete
return vers.map(v => `${pkgs[0]}@${v}`)
[60] Fix | Delete
}
[61] Fix | Delete
})
[62] Fix | Delete
})
[63] Fix | Delete
}).nodeify(cb)
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
function unpublish (args, cb) {
[67] Fix | Delete
if (args.length > 1) return cb(unpublish.usage)
[68] Fix | Delete
[69] Fix | Delete
const spec = args.length && npa(args[0])
[70] Fix | Delete
const opts = UnpublishConfig(npmConfig())
[71] Fix | Delete
const version = spec.rawSpec
[72] Fix | Delete
BB.try(() => {
[73] Fix | Delete
log.silly('unpublish', 'args[0]', args[0])
[74] Fix | Delete
log.silly('unpublish', 'spec', spec)
[75] Fix | Delete
if (!version && !opts.force) {
[76] Fix | Delete
throw Object.assign(new Error(
[77] Fix | Delete
'Refusing to delete entire project.\n' +
[78] Fix | Delete
'Run with --force to do this.\n' +
[79] Fix | Delete
unpublish.usage
[80] Fix | Delete
), { code: 'EUSAGE' })
[81] Fix | Delete
}
[82] Fix | Delete
if (!spec || path.resolve(spec.name) === npm.localPrefix) {
[83] Fix | Delete
// if there's a package.json in the current folder, then
[84] Fix | Delete
// read the package name and version out of that.
[85] Fix | Delete
const cwdJson = path.join(npm.localPrefix, 'package.json')
[86] Fix | Delete
return readJson(cwdJson).then(data => {
[87] Fix | Delete
log.verbose('unpublish', data)
[88] Fix | Delete
return otplease(opts, opts => {
[89] Fix | Delete
return libunpub(npa.resolve(data.name, data.version), opts.concat(data.publishConfig))
[90] Fix | Delete
})
[91] Fix | Delete
}, err => {
[92] Fix | Delete
if (err && err.code !== 'ENOENT' && err.code !== 'ENOTDIR') {
[93] Fix | Delete
throw err
[94] Fix | Delete
} else {
[95] Fix | Delete
UsageError()
[96] Fix | Delete
}
[97] Fix | Delete
})
[98] Fix | Delete
} else {
[99] Fix | Delete
return otplease(opts, opts => libunpub(spec, opts))
[100] Fix | Delete
}
[101] Fix | Delete
}).then(
[102] Fix | Delete
ret => {
[103] Fix | Delete
if (!opts.silent && opts.loglevel !== 'silent') {
[104] Fix | Delete
output(`- ${spec.name}${
[105] Fix | Delete
spec.type === 'version' ? `@${spec.rawSpec}` : ''
[106] Fix | Delete
}`)
[107] Fix | Delete
}
[108] Fix | Delete
cb(null, ret)
[109] Fix | Delete
},
[110] Fix | Delete
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
[111] Fix | Delete
)
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function