Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: publish.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
const BB = require('bluebird')
[2] Fix | Delete
[3] Fix | Delete
const cacache = require('cacache')
[4] Fix | Delete
const figgyPudding = require('figgy-pudding')
[5] Fix | Delete
const libpub = require('libnpm/publish')
[6] Fix | Delete
const libunpub = require('libnpm/unpublish')
[7] Fix | Delete
const lifecycle = BB.promisify(require('./utils/lifecycle.js'))
[8] Fix | Delete
const log = require('npmlog')
[9] Fix | Delete
const npa = require('libnpm/parse-arg')
[10] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[11] Fix | Delete
const output = require('./utils/output.js')
[12] Fix | Delete
const otplease = require('./utils/otplease.js')
[13] Fix | Delete
const pack = require('./pack')
[14] Fix | Delete
const { tarball, extract } = require('libnpm')
[15] Fix | Delete
const path = require('path')
[16] Fix | Delete
const readFileAsync = BB.promisify(require('graceful-fs').readFile)
[17] Fix | Delete
const readJson = BB.promisify(require('read-package-json'))
[18] Fix | Delete
const semver = require('semver')
[19] Fix | Delete
const statAsync = BB.promisify(require('graceful-fs').stat)
[20] Fix | Delete
[21] Fix | Delete
publish.usage = 'npm publish [<tarball>|<folder>] [--tag <tag>] [--access <public|restricted>] [--dry-run]' +
[22] Fix | Delete
"\n\nPublishes '.' if no argument supplied" +
[23] Fix | Delete
'\n\nSets tag `latest` if no --tag specified'
[24] Fix | Delete
[25] Fix | Delete
publish.completion = function (opts, cb) {
[26] Fix | Delete
// publish can complete to a folder with a package.json
[27] Fix | Delete
// or a tarball, or a tarball url.
[28] Fix | Delete
// for now, not yet implemented.
[29] Fix | Delete
return cb()
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
const PublishConfig = figgyPudding({
[33] Fix | Delete
dryRun: 'dry-run',
[34] Fix | Delete
'dry-run': { default: false },
[35] Fix | Delete
force: { default: false },
[36] Fix | Delete
json: { default: false },
[37] Fix | Delete
Promise: { default: () => Promise },
[38] Fix | Delete
tag: { default: 'latest' },
[39] Fix | Delete
tmp: {}
[40] Fix | Delete
})
[41] Fix | Delete
[42] Fix | Delete
module.exports = publish
[43] Fix | Delete
function publish (args, isRetry, cb) {
[44] Fix | Delete
if (typeof cb !== 'function') {
[45] Fix | Delete
cb = isRetry
[46] Fix | Delete
isRetry = false
[47] Fix | Delete
}
[48] Fix | Delete
if (args.length === 0) args = ['.']
[49] Fix | Delete
if (args.length !== 1) return cb(publish.usage)
[50] Fix | Delete
[51] Fix | Delete
log.verbose('publish', args)
[52] Fix | Delete
[53] Fix | Delete
const opts = PublishConfig(npmConfig())
[54] Fix | Delete
const t = opts.tag.trim()
[55] Fix | Delete
if (semver.validRange(t)) {
[56] Fix | Delete
return cb(new Error('Tag name must not be a valid SemVer range: ' + t))
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return publish_(args[0], opts)
[60] Fix | Delete
.then((tarball) => {
[61] Fix | Delete
const silent = log.level === 'silent'
[62] Fix | Delete
if (!silent && opts.json) {
[63] Fix | Delete
output(JSON.stringify(tarball, null, 2))
[64] Fix | Delete
} else if (!silent) {
[65] Fix | Delete
output(`+ ${tarball.id}`)
[66] Fix | Delete
}
[67] Fix | Delete
})
[68] Fix | Delete
.nodeify(cb)
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
function publish_ (arg, opts) {
[72] Fix | Delete
return statAsync(arg).then((stat) => {
[73] Fix | Delete
if (stat.isDirectory()) {
[74] Fix | Delete
return stat
[75] Fix | Delete
} else {
[76] Fix | Delete
const err = new Error('not a directory')
[77] Fix | Delete
err.code = 'ENOTDIR'
[78] Fix | Delete
throw err
[79] Fix | Delete
}
[80] Fix | Delete
}).then(() => {
[81] Fix | Delete
return publishFromDirectory(arg, opts)
[82] Fix | Delete
}, (err) => {
[83] Fix | Delete
if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') {
[84] Fix | Delete
throw err
[85] Fix | Delete
} else {
[86] Fix | Delete
return publishFromPackage(arg, opts)
[87] Fix | Delete
}
[88] Fix | Delete
})
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
function publishFromDirectory (arg, opts) {
[92] Fix | Delete
// All this readJson is because any of the given scripts might modify the
[93] Fix | Delete
// package.json in question, so we need to refresh after every step.
[94] Fix | Delete
let contents
[95] Fix | Delete
return pack.prepareDirectory(arg).then(() => {
[96] Fix | Delete
return readJson(path.join(arg, 'package.json'))
[97] Fix | Delete
}).then((pkg) => {
[98] Fix | Delete
return lifecycle(pkg, 'prepublishOnly', arg)
[99] Fix | Delete
}).then(() => {
[100] Fix | Delete
return readJson(path.join(arg, 'package.json'))
[101] Fix | Delete
}).then((pkg) => {
[102] Fix | Delete
return cacache.tmp.withTmp(opts.tmp, {tmpPrefix: 'fromDir'}, (tmpDir) => {
[103] Fix | Delete
const target = path.join(tmpDir, 'package.tgz')
[104] Fix | Delete
return pack.packDirectory(pkg, arg, target, null, true)
[105] Fix | Delete
.tap((c) => { contents = c })
[106] Fix | Delete
.then((c) => !opts.json && pack.logContents(c))
[107] Fix | Delete
.then(() => upload(pkg, false, target, opts))
[108] Fix | Delete
})
[109] Fix | Delete
}).then(() => {
[110] Fix | Delete
return readJson(path.join(arg, 'package.json'))
[111] Fix | Delete
}).tap((pkg) => {
[112] Fix | Delete
return lifecycle(pkg, 'publish', arg)
[113] Fix | Delete
}).tap((pkg) => {
[114] Fix | Delete
return lifecycle(pkg, 'postpublish', arg)
[115] Fix | Delete
})
[116] Fix | Delete
.then(() => contents)
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
function publishFromPackage (arg, opts) {
[120] Fix | Delete
return cacache.tmp.withTmp(opts.tmp, {tmpPrefix: 'fromPackage'}, tmp => {
[121] Fix | Delete
const extracted = path.join(tmp, 'package')
[122] Fix | Delete
const target = path.join(tmp, 'package.json')
[123] Fix | Delete
return tarball.toFile(arg, target, opts)
[124] Fix | Delete
.then(() => extract(arg, extracted, opts))
[125] Fix | Delete
.then(() => readJson(path.join(extracted, 'package.json')))
[126] Fix | Delete
.then((pkg) => {
[127] Fix | Delete
return BB.resolve(pack.getContents(pkg, target))
[128] Fix | Delete
.tap((c) => !opts.json && pack.logContents(c))
[129] Fix | Delete
.tap(() => upload(pkg, false, target, opts))
[130] Fix | Delete
})
[131] Fix | Delete
})
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
function upload (pkg, isRetry, cached, opts) {
[135] Fix | Delete
if (!opts.dryRun) {
[136] Fix | Delete
return readFileAsync(cached).then(tarball => {
[137] Fix | Delete
return otplease(opts, opts => {
[138] Fix | Delete
return libpub(pkg, tarball, opts)
[139] Fix | Delete
}).catch(err => {
[140] Fix | Delete
if (
[141] Fix | Delete
err.code === 'EPUBLISHCONFLICT' &&
[142] Fix | Delete
opts.force &&
[143] Fix | Delete
!isRetry
[144] Fix | Delete
) {
[145] Fix | Delete
log.warn('publish', 'Forced publish over ' + pkg._id)
[146] Fix | Delete
return otplease(opts, opts => libunpub(
[147] Fix | Delete
npa.resolve(pkg.name, pkg.version), opts
[148] Fix | Delete
)).finally(() => {
[149] Fix | Delete
// ignore errors. Use the force. Reach out with your feelings.
[150] Fix | Delete
return otplease(opts, opts => {
[151] Fix | Delete
return upload(pkg, true, tarball, opts)
[152] Fix | Delete
}).catch(() => {
[153] Fix | Delete
// but if it fails again, then report the first error.
[154] Fix | Delete
throw err
[155] Fix | Delete
})
[156] Fix | Delete
})
[157] Fix | Delete
} else {
[158] Fix | Delete
throw err
[159] Fix | Delete
}
[160] Fix | Delete
})
[161] Fix | Delete
})
[162] Fix | Delete
} else {
[163] Fix | Delete
return opts.Promise.resolve(true)
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function