Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: pack.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
// npm pack <pkg>
[2] Fix | Delete
// Packs the specified package into a .tgz file, which can then
[3] Fix | Delete
// be installed.
[4] Fix | Delete
[5] Fix | Delete
// Set this early to avoid issues with circular dependencies.
[6] Fix | Delete
module.exports = pack
[7] Fix | Delete
[8] Fix | Delete
const BB = require('bluebird')
[9] Fix | Delete
[10] Fix | Delete
const byteSize = require('byte-size')
[11] Fix | Delete
const cacache = require('cacache')
[12] Fix | Delete
const columnify = require('columnify')
[13] Fix | Delete
const cp = require('child_process')
[14] Fix | Delete
const deprCheck = require('./utils/depr-check')
[15] Fix | Delete
const fpm = require('./fetch-package-metadata')
[16] Fix | Delete
const fs = require('graceful-fs')
[17] Fix | Delete
const install = require('./install')
[18] Fix | Delete
const lifecycle = BB.promisify(require('./utils/lifecycle'))
[19] Fix | Delete
const log = require('npmlog')
[20] Fix | Delete
const move = require('move-concurrently')
[21] Fix | Delete
const npm = require('./npm')
[22] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[23] Fix | Delete
const output = require('./utils/output')
[24] Fix | Delete
const pacote = require('pacote')
[25] Fix | Delete
const path = require('path')
[26] Fix | Delete
const PassThrough = require('stream').PassThrough
[27] Fix | Delete
const pathIsInside = require('path-is-inside')
[28] Fix | Delete
const pipe = BB.promisify(require('mississippi').pipe)
[29] Fix | Delete
const prepublishWarning = require('./utils/warn-deprecated')('prepublish-on-install')
[30] Fix | Delete
const pinflight = require('promise-inflight')
[31] Fix | Delete
const readJson = BB.promisify(require('read-package-json'))
[32] Fix | Delete
const tar = require('tar')
[33] Fix | Delete
const packlist = require('npm-packlist')
[34] Fix | Delete
const ssri = require('ssri')
[35] Fix | Delete
[36] Fix | Delete
pack.usage = 'npm pack [[<@scope>/]<pkg>...] [--dry-run]'
[37] Fix | Delete
[38] Fix | Delete
// if it can be installed, it can be packed.
[39] Fix | Delete
pack.completion = install.completion
[40] Fix | Delete
[41] Fix | Delete
function pack (args, silent, cb) {
[42] Fix | Delete
const cwd = process.cwd()
[43] Fix | Delete
if (typeof cb !== 'function') {
[44] Fix | Delete
cb = silent
[45] Fix | Delete
silent = false
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
if (args.length === 0) args = ['.']
[49] Fix | Delete
[50] Fix | Delete
BB.all(
[51] Fix | Delete
args.map((arg) => pack_(arg, cwd))
[52] Fix | Delete
).then((tarballs) => {
[53] Fix | Delete
if (!silent && npm.config.get('json')) {
[54] Fix | Delete
output(JSON.stringify(tarballs, null, 2))
[55] Fix | Delete
} else if (!silent) {
[56] Fix | Delete
tarballs.forEach(logContents)
[57] Fix | Delete
output(tarballs.map((f) => path.relative(cwd, f.filename)).join('\n'))
[58] Fix | Delete
}
[59] Fix | Delete
return tarballs
[60] Fix | Delete
}).nodeify(cb)
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
function pack_ (pkg, dir) {
[64] Fix | Delete
return BB.fromNode((cb) => fpm(pkg, dir, cb)).then((mani) => {
[65] Fix | Delete
let name = mani.name[0] === '@'
[66] Fix | Delete
// scoped packages get special treatment
[67] Fix | Delete
? mani.name.substr(1).replace(/\//g, '-')
[68] Fix | Delete
: mani.name
[69] Fix | Delete
const target = `${name}-${mani.version}.tgz`
[70] Fix | Delete
return pinflight(target, () => {
[71] Fix | Delete
const dryRun = npm.config.get('dry-run')
[72] Fix | Delete
if (mani._requested.type === 'directory') {
[73] Fix | Delete
return prepareDirectory(mani._resolved)
[74] Fix | Delete
.then(() => {
[75] Fix | Delete
return packDirectory(mani, mani._resolved, target, target, true, dryRun)
[76] Fix | Delete
})
[77] Fix | Delete
} else if (dryRun) {
[78] Fix | Delete
log.verbose('pack', '--dry-run mode enabled. Skipping write.')
[79] Fix | Delete
return cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'packing'}, (tmp) => {
[80] Fix | Delete
const tmpTarget = path.join(tmp, path.basename(target))
[81] Fix | Delete
return packFromPackage(pkg, tmpTarget, target)
[82] Fix | Delete
})
[83] Fix | Delete
} else {
[84] Fix | Delete
return packFromPackage(pkg, target, target)
[85] Fix | Delete
}
[86] Fix | Delete
})
[87] Fix | Delete
})
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
function packFromPackage (arg, target, filename) {
[91] Fix | Delete
const opts = npmConfig()
[92] Fix | Delete
return pacote.tarball.toFile(arg, target, opts)
[93] Fix | Delete
.then(() => cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'unpacking'}, (tmp) => {
[94] Fix | Delete
const tmpTarget = path.join(tmp, filename)
[95] Fix | Delete
return pacote.extract(arg, tmpTarget, opts)
[96] Fix | Delete
.then(() => readJson(path.join(tmpTarget, 'package.json')))
[97] Fix | Delete
}))
[98] Fix | Delete
.then((pkg) => getContents(pkg, target, filename))
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
module.exports.prepareDirectory = prepareDirectory
[102] Fix | Delete
function prepareDirectory (dir) {
[103] Fix | Delete
return readJson(path.join(dir, 'package.json')).then((pkg) => {
[104] Fix | Delete
if (!pkg.name) {
[105] Fix | Delete
throw new Error('package.json requires a "name" field')
[106] Fix | Delete
}
[107] Fix | Delete
if (!pkg.version) {
[108] Fix | Delete
throw new Error('package.json requires a valid "version" field')
[109] Fix | Delete
}
[110] Fix | Delete
if (!pathIsInside(dir, npm.tmp)) {
[111] Fix | Delete
if (pkg.scripts && pkg.scripts.prepublish) {
[112] Fix | Delete
prepublishWarning([
[113] Fix | Delete
'As of npm@5, `prepublish` scripts are deprecated.',
[114] Fix | Delete
'Use `prepare` for build steps and `prepublishOnly` for upload-only.',
[115] Fix | Delete
'See the deprecation note in `npm help scripts` for more information.'
[116] Fix | Delete
])
[117] Fix | Delete
}
[118] Fix | Delete
if (npm.config.get('ignore-prepublish')) {
[119] Fix | Delete
return lifecycle(pkg, 'prepare', dir).then(() => pkg)
[120] Fix | Delete
} else {
[121] Fix | Delete
return lifecycle(pkg, 'prepublish', dir).then(() => {
[122] Fix | Delete
return lifecycle(pkg, 'prepare', dir)
[123] Fix | Delete
}).then(() => pkg)
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
return pkg
[127] Fix | Delete
})
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
module.exports.packDirectory = packDirectory
[131] Fix | Delete
function packDirectory (mani, dir, target, filename, logIt, dryRun) {
[132] Fix | Delete
deprCheck(mani)
[133] Fix | Delete
return readJson(path.join(dir, 'package.json')).then((pkg) => {
[134] Fix | Delete
return lifecycle(pkg, 'prepack', dir)
[135] Fix | Delete
}).then(() => {
[136] Fix | Delete
return readJson(path.join(dir, 'package.json'))
[137] Fix | Delete
}).then((pkg) => {
[138] Fix | Delete
return cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'packing'}, (tmp) => {
[139] Fix | Delete
const tmpTarget = path.join(tmp, path.basename(target))
[140] Fix | Delete
[141] Fix | Delete
const tarOpt = {
[142] Fix | Delete
file: tmpTarget,
[143] Fix | Delete
cwd: dir,
[144] Fix | Delete
prefix: 'package/',
[145] Fix | Delete
portable: true,
[146] Fix | Delete
// Provide a specific date in the 1980s for the benefit of zip,
[147] Fix | Delete
// which is confounded by files dated at the Unix epoch 0.
[148] Fix | Delete
mtime: new Date('1985-10-26T08:15:00.000Z'),
[149] Fix | Delete
gzip: true
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
return BB.resolve(packlist({ path: dir }))
[153] Fix | Delete
// NOTE: node-tar does some Magic Stuff depending on prefixes for files
[154] Fix | Delete
// specifically with @ signs, so we just neutralize that one
[155] Fix | Delete
// and any such future "features" by prepending `./`
[156] Fix | Delete
.then((files) => tar.create(tarOpt, files.map((f) => `./${f}`)))
[157] Fix | Delete
.then(() => getContents(pkg, tmpTarget, filename, logIt))
[158] Fix | Delete
// thread the content info through
[159] Fix | Delete
.tap(() => {
[160] Fix | Delete
if (dryRun) {
[161] Fix | Delete
log.verbose('pack', '--dry-run mode enabled. Skipping write.')
[162] Fix | Delete
} else {
[163] Fix | Delete
return move(tmpTarget, target, {Promise: BB, fs})
[164] Fix | Delete
}
[165] Fix | Delete
})
[166] Fix | Delete
.tap(() => lifecycle(pkg, 'postpack', dir))
[167] Fix | Delete
})
[168] Fix | Delete
})
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
module.exports.logContents = logContents
[172] Fix | Delete
function logContents (tarball) {
[173] Fix | Delete
log.notice('')
[174] Fix | Delete
log.notice('', `${npm.config.get('unicode') ? '📦 ' : 'package:'} ${tarball.name}@${tarball.version}`)
[175] Fix | Delete
log.notice('=== Tarball Contents ===')
[176] Fix | Delete
if (tarball.files.length) {
[177] Fix | Delete
log.notice('', columnify(tarball.files.map((f) => {
[178] Fix | Delete
const bytes = byteSize(f.size)
[179] Fix | Delete
return {path: f.path, size: `${bytes.value}${bytes.unit}`}
[180] Fix | Delete
}), {
[181] Fix | Delete
include: ['size', 'path'],
[182] Fix | Delete
showHeaders: false
[183] Fix | Delete
}))
[184] Fix | Delete
}
[185] Fix | Delete
if (tarball.bundled.length) {
[186] Fix | Delete
log.notice('=== Bundled Dependencies ===')
[187] Fix | Delete
tarball.bundled.forEach((name) => log.notice('', name))
[188] Fix | Delete
}
[189] Fix | Delete
log.notice('=== Tarball Details ===')
[190] Fix | Delete
log.notice('', columnify([
[191] Fix | Delete
{name: 'name:', value: tarball.name},
[192] Fix | Delete
{name: 'version:', value: tarball.version},
[193] Fix | Delete
tarball.filename && {name: 'filename:', value: tarball.filename},
[194] Fix | Delete
{name: 'package size:', value: byteSize(tarball.size)},
[195] Fix | Delete
{name: 'unpacked size:', value: byteSize(tarball.unpackedSize)},
[196] Fix | Delete
{name: 'shasum:', value: tarball.shasum},
[197] Fix | Delete
{
[198] Fix | Delete
name: 'integrity:',
[199] Fix | Delete
value: tarball.integrity.toString().substr(0, 20) + '[...]' + tarball.integrity.toString().substr(80)},
[200] Fix | Delete
tarball.bundled.length && {name: 'bundled deps:', value: tarball.bundled.length},
[201] Fix | Delete
tarball.bundled.length && {name: 'bundled files:', value: tarball.entryCount - tarball.files.length},
[202] Fix | Delete
tarball.bundled.length && {name: 'own files:', value: tarball.files.length},
[203] Fix | Delete
{name: 'total files:', value: tarball.entryCount}
[204] Fix | Delete
].filter((x) => x), {
[205] Fix | Delete
include: ['name', 'value'],
[206] Fix | Delete
showHeaders: false
[207] Fix | Delete
}))
[208] Fix | Delete
log.notice('', '')
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
module.exports.getContents = getContents
[212] Fix | Delete
function getContents (pkg, target, filename, silent) {
[213] Fix | Delete
const bundledWanted = new Set(
[214] Fix | Delete
pkg.bundleDependencies ||
[215] Fix | Delete
pkg.bundledDependencies ||
[216] Fix | Delete
[]
[217] Fix | Delete
)
[218] Fix | Delete
const files = []
[219] Fix | Delete
const bundled = new Set()
[220] Fix | Delete
let totalEntries = 0
[221] Fix | Delete
let totalEntrySize = 0
[222] Fix | Delete
return tar.t({
[223] Fix | Delete
file: target,
[224] Fix | Delete
onentry (entry) {
[225] Fix | Delete
totalEntries++
[226] Fix | Delete
totalEntrySize += entry.size
[227] Fix | Delete
const p = entry.path
[228] Fix | Delete
if (p.startsWith('package/node_modules/')) {
[229] Fix | Delete
const name = p.match(/^package\/node_modules\/((?:@[^/]+\/)?[^/]+)/)[1]
[230] Fix | Delete
if (bundledWanted.has(name)) {
[231] Fix | Delete
bundled.add(name)
[232] Fix | Delete
}
[233] Fix | Delete
} else {
[234] Fix | Delete
files.push({
[235] Fix | Delete
path: entry.path.replace(/^package\//, ''),
[236] Fix | Delete
size: entry.size,
[237] Fix | Delete
mode: entry.mode
[238] Fix | Delete
})
[239] Fix | Delete
}
[240] Fix | Delete
},
[241] Fix | Delete
strip: 1
[242] Fix | Delete
})
[243] Fix | Delete
.then(() => BB.all([
[244] Fix | Delete
BB.fromNode((cb) => fs.stat(target, cb)),
[245] Fix | Delete
ssri.fromStream(fs.createReadStream(target), {
[246] Fix | Delete
algorithms: ['sha1', 'sha512']
[247] Fix | Delete
})
[248] Fix | Delete
]))
[249] Fix | Delete
.then(([stat, integrity]) => {
[250] Fix | Delete
const shasum = integrity['sha1'][0].hexDigest()
[251] Fix | Delete
return {
[252] Fix | Delete
id: pkg._id,
[253] Fix | Delete
name: pkg.name,
[254] Fix | Delete
version: pkg.version,
[255] Fix | Delete
from: pkg._from,
[256] Fix | Delete
size: stat.size,
[257] Fix | Delete
unpackedSize: totalEntrySize,
[258] Fix | Delete
shasum,
[259] Fix | Delete
integrity: ssri.parse(integrity['sha512'][0]),
[260] Fix | Delete
filename,
[261] Fix | Delete
files,
[262] Fix | Delete
entryCount: totalEntries,
[263] Fix | Delete
bundled: Array.from(bundled)
[264] Fix | Delete
}
[265] Fix | Delete
})
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
const PASSTHROUGH_OPTS = [
[269] Fix | Delete
'always-auth',
[270] Fix | Delete
'auth-type',
[271] Fix | Delete
'ca',
[272] Fix | Delete
'cafile',
[273] Fix | Delete
'cert',
[274] Fix | Delete
'git',
[275] Fix | Delete
'local-address',
[276] Fix | Delete
'maxsockets',
[277] Fix | Delete
'offline',
[278] Fix | Delete
'prefer-offline',
[279] Fix | Delete
'prefer-online',
[280] Fix | Delete
'proxy',
[281] Fix | Delete
'https-proxy',
[282] Fix | Delete
'registry',
[283] Fix | Delete
'send-metrics',
[284] Fix | Delete
'sso-poll-frequency',
[285] Fix | Delete
'sso-type',
[286] Fix | Delete
'strict-ssl'
[287] Fix | Delete
]
[288] Fix | Delete
[289] Fix | Delete
module.exports.packGitDep = packGitDep
[290] Fix | Delete
function packGitDep (manifest, dir) {
[291] Fix | Delete
const stream = new PassThrough()
[292] Fix | Delete
readJson(path.join(dir, 'package.json')).then((pkg) => {
[293] Fix | Delete
if (pkg.scripts && pkg.scripts.prepare) {
[294] Fix | Delete
log.verbose('prepareGitDep', `${manifest._spec}: installing devDeps and running prepare script.`)
[295] Fix | Delete
const cliArgs = PASSTHROUGH_OPTS.reduce((acc, opt) => {
[296] Fix | Delete
if (npm.config.get(opt, 'cli') != null) {
[297] Fix | Delete
acc.push(`--${opt}=${npm.config.get(opt)}`)
[298] Fix | Delete
}
[299] Fix | Delete
return acc
[300] Fix | Delete
}, [])
[301] Fix | Delete
const child = cp.spawn(process.env.NODE || process.execPath, [
[302] Fix | Delete
require.resolve('../bin/npm-cli.js'),
[303] Fix | Delete
'install',
[304] Fix | Delete
'--dev',
[305] Fix | Delete
'--prod',
[306] Fix | Delete
'--ignore-prepublish',
[307] Fix | Delete
'--no-progress',
[308] Fix | Delete
'--no-save'
[309] Fix | Delete
].concat(cliArgs), {
[310] Fix | Delete
cwd: dir,
[311] Fix | Delete
env: process.env
[312] Fix | Delete
})
[313] Fix | Delete
let errData = []
[314] Fix | Delete
let errDataLen = 0
[315] Fix | Delete
let outData = []
[316] Fix | Delete
let outDataLen = 0
[317] Fix | Delete
child.stdout.on('data', (data) => {
[318] Fix | Delete
outData.push(data)
[319] Fix | Delete
outDataLen += data.length
[320] Fix | Delete
log.gauge.pulse('preparing git package')
[321] Fix | Delete
})
[322] Fix | Delete
child.stderr.on('data', (data) => {
[323] Fix | Delete
errData.push(data)
[324] Fix | Delete
errDataLen += data.length
[325] Fix | Delete
log.gauge.pulse('preparing git package')
[326] Fix | Delete
})
[327] Fix | Delete
return BB.fromNode((cb) => {
[328] Fix | Delete
child.on('error', cb)
[329] Fix | Delete
child.on('exit', (code, signal) => {
[330] Fix | Delete
if (code > 0) {
[331] Fix | Delete
const err = new Error(`${signal}: npm exited with code ${code} while attempting to build ${manifest._requested}. Clone the repository manually and run 'npm install' in it for more information.`)
[332] Fix | Delete
err.code = code
[333] Fix | Delete
err.signal = signal
[334] Fix | Delete
cb(err)
[335] Fix | Delete
} else {
[336] Fix | Delete
cb()
[337] Fix | Delete
}
[338] Fix | Delete
})
[339] Fix | Delete
}).then(() => {
[340] Fix | Delete
if (outDataLen > 0) log.silly('prepareGitDep', '1>', Buffer.concat(outData, outDataLen).toString())
[341] Fix | Delete
if (errDataLen > 0) log.silly('prepareGitDep', '2>', Buffer.concat(errData, errDataLen).toString())
[342] Fix | Delete
}, (err) => {
[343] Fix | Delete
if (outDataLen > 0) log.error('prepareGitDep', '1>', Buffer.concat(outData, outDataLen).toString())
[344] Fix | Delete
if (errDataLen > 0) log.error('prepareGitDep', '2>', Buffer.concat(errData, errDataLen).toString())
[345] Fix | Delete
throw err
[346] Fix | Delete
})
[347] Fix | Delete
}
[348] Fix | Delete
}).then(() => {
[349] Fix | Delete
return readJson(path.join(dir, 'package.json'))
[350] Fix | Delete
}).then((pkg) => {
[351] Fix | Delete
return cacache.tmp.withTmp(npm.tmp, {
[352] Fix | Delete
tmpPrefix: 'pacote-packing'
[353] Fix | Delete
}, (tmp) => {
[354] Fix | Delete
const tmpTar = path.join(tmp, 'package.tgz')
[355] Fix | Delete
return packDirectory(manifest, dir, tmpTar).then(() => {
[356] Fix | Delete
return pipe(fs.createReadStream(tmpTar), stream)
[357] Fix | Delete
})
[358] Fix | Delete
})
[359] Fix | Delete
}).catch((err) => stream.emit('error', err))
[360] Fix | Delete
return stream
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function