Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: shrinkwrap.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
const BB = require('bluebird')
[2] Fix | Delete
[3] Fix | Delete
const chain = require('slide').chain
[4] Fix | Delete
const detectIndent = require('detect-indent')
[5] Fix | Delete
const detectNewline = require('detect-newline')
[6] Fix | Delete
const readFile = BB.promisify(require('graceful-fs').readFile)
[7] Fix | Delete
const getRequested = require('./install/get-requested.js')
[8] Fix | Delete
const id = require('./install/deps.js')
[9] Fix | Delete
const iferr = require('iferr')
[10] Fix | Delete
const isOnlyOptional = require('./install/is-only-optional.js')
[11] Fix | Delete
const isOnlyDev = require('./install/is-only-dev.js')
[12] Fix | Delete
const lifecycle = require('./utils/lifecycle.js')
[13] Fix | Delete
const log = require('npmlog')
[14] Fix | Delete
const moduleName = require('./utils/module-name.js')
[15] Fix | Delete
const move = require('move-concurrently')
[16] Fix | Delete
const npm = require('./npm.js')
[17] Fix | Delete
const path = require('path')
[18] Fix | Delete
const readPackageTree = BB.promisify(require('read-package-tree'))
[19] Fix | Delete
const ssri = require('ssri')
[20] Fix | Delete
const stringifyPackage = require('stringify-package')
[21] Fix | Delete
const validate = require('aproba')
[22] Fix | Delete
const writeFileAtomic = require('write-file-atomic')
[23] Fix | Delete
const unixFormatPath = require('./utils/unix-format-path.js')
[24] Fix | Delete
const isRegistry = require('./utils/is-registry.js')
[25] Fix | Delete
[26] Fix | Delete
const { chown } = require('fs')
[27] Fix | Delete
const inferOwner = require('infer-owner')
[28] Fix | Delete
const selfOwner = {
[29] Fix | Delete
uid: process.getuid && process.getuid(),
[30] Fix | Delete
gid: process.getgid && process.getgid()
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
const PKGLOCK = 'package-lock.json'
[34] Fix | Delete
const SHRINKWRAP = 'npm-shrinkwrap.json'
[35] Fix | Delete
const PKGLOCK_VERSION = npm.lockfileVersion
[36] Fix | Delete
[37] Fix | Delete
// emit JSON describing versions of all packages currently installed (for later
[38] Fix | Delete
// use with shrinkwrap install)
[39] Fix | Delete
shrinkwrap.usage = 'npm shrinkwrap'
[40] Fix | Delete
[41] Fix | Delete
module.exports = exports = shrinkwrap
[42] Fix | Delete
exports.treeToShrinkwrap = treeToShrinkwrap
[43] Fix | Delete
[44] Fix | Delete
function shrinkwrap (args, silent, cb) {
[45] Fix | Delete
if (typeof cb !== 'function') {
[46] Fix | Delete
cb = silent
[47] Fix | Delete
silent = false
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
if (args.length) {
[51] Fix | Delete
log.warn('shrinkwrap', "doesn't take positional args")
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
move(
[55] Fix | Delete
path.resolve(npm.prefix, PKGLOCK),
[56] Fix | Delete
path.resolve(npm.prefix, SHRINKWRAP),
[57] Fix | Delete
{ Promise: BB }
[58] Fix | Delete
).then(() => {
[59] Fix | Delete
log.notice('', `${PKGLOCK} has been renamed to ${SHRINKWRAP}. ${SHRINKWRAP} will be used for future installations.`)
[60] Fix | Delete
return readFile(path.resolve(npm.prefix, SHRINKWRAP)).then((d) => {
[61] Fix | Delete
return JSON.parse(d)
[62] Fix | Delete
})
[63] Fix | Delete
}, (err) => {
[64] Fix | Delete
if (err.code !== 'ENOENT') {
[65] Fix | Delete
throw err
[66] Fix | Delete
} else {
[67] Fix | Delete
return readPackageTree(npm.localPrefix).then(
[68] Fix | Delete
id.computeMetadata
[69] Fix | Delete
).then((tree) => {
[70] Fix | Delete
return BB.fromNode((cb) => {
[71] Fix | Delete
createShrinkwrap(tree, {
[72] Fix | Delete
silent,
[73] Fix | Delete
defaultFile: SHRINKWRAP
[74] Fix | Delete
}, cb)
[75] Fix | Delete
})
[76] Fix | Delete
})
[77] Fix | Delete
}
[78] Fix | Delete
}).then((data) => cb(null, data), cb)
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
module.exports.createShrinkwrap = createShrinkwrap
[82] Fix | Delete
[83] Fix | Delete
function createShrinkwrap (tree, opts, cb) {
[84] Fix | Delete
opts = opts || {}
[85] Fix | Delete
lifecycle(tree.package, 'preshrinkwrap', tree.path, function () {
[86] Fix | Delete
const pkginfo = treeToShrinkwrap(tree)
[87] Fix | Delete
chain([
[88] Fix | Delete
[lifecycle, tree.package, 'shrinkwrap', tree.path],
[89] Fix | Delete
[shrinkwrap_, tree.path, pkginfo, opts],
[90] Fix | Delete
[lifecycle, tree.package, 'postshrinkwrap', tree.path]
[91] Fix | Delete
], iferr(cb, function (data) {
[92] Fix | Delete
cb(null, pkginfo)
[93] Fix | Delete
}))
[94] Fix | Delete
})
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
function treeToShrinkwrap (tree) {
[98] Fix | Delete
validate('O', arguments)
[99] Fix | Delete
var pkginfo = {}
[100] Fix | Delete
if (tree.package.name) pkginfo.name = tree.package.name
[101] Fix | Delete
if (tree.package.version) pkginfo.version = tree.package.version
[102] Fix | Delete
if (tree.children.length) {
[103] Fix | Delete
pkginfo.requires = true
[104] Fix | Delete
shrinkwrapDeps(pkginfo.dependencies = {}, tree, tree)
[105] Fix | Delete
}
[106] Fix | Delete
return pkginfo
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
function shrinkwrapDeps (deps, top, tree, seen) {
[110] Fix | Delete
validate('OOO', [deps, top, tree])
[111] Fix | Delete
if (!seen) seen = new Set()
[112] Fix | Delete
if (seen.has(tree)) return
[113] Fix | Delete
seen.add(tree)
[114] Fix | Delete
sortModules(tree.children).forEach(function (child) {
[115] Fix | Delete
var childIsOnlyDev = isOnlyDev(child)
[116] Fix | Delete
var pkginfo = deps[moduleName(child)] = {}
[117] Fix | Delete
var requested = getRequested(child) || child.package._requested || {}
[118] Fix | Delete
var linked = child.isLink || child.isInLink
[119] Fix | Delete
pkginfo.version = childVersion(top, child, requested)
[120] Fix | Delete
if (requested.type === 'git' && child.package._from) {
[121] Fix | Delete
pkginfo.from = child.package._from
[122] Fix | Delete
}
[123] Fix | Delete
if (child.fromBundle && !linked) {
[124] Fix | Delete
pkginfo.bundled = true
[125] Fix | Delete
} else {
[126] Fix | Delete
if (isRegistry(requested)) {
[127] Fix | Delete
pkginfo.resolved = child.package._resolved
[128] Fix | Delete
}
[129] Fix | Delete
// no integrity for git deps as integrity hashes are based on the
[130] Fix | Delete
// tarball and we can't (yet) create consistent tarballs from a stable
[131] Fix | Delete
// source.
[132] Fix | Delete
if (requested.type !== 'git') {
[133] Fix | Delete
pkginfo.integrity = child.package._integrity || undefined
[134] Fix | Delete
if (!pkginfo.integrity && child.package._shasum) {
[135] Fix | Delete
pkginfo.integrity = ssri.fromHex(child.package._shasum, 'sha1')
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
if (childIsOnlyDev) pkginfo.dev = true
[140] Fix | Delete
if (isOnlyOptional(child)) pkginfo.optional = true
[141] Fix | Delete
if (child.requires.length) {
[142] Fix | Delete
pkginfo.requires = {}
[143] Fix | Delete
sortModules(child.requires).forEach((required) => {
[144] Fix | Delete
var requested = getRequested(required, child) || required.package._requested || {}
[145] Fix | Delete
pkginfo.requires[moduleName(required)] = childRequested(top, required, requested)
[146] Fix | Delete
})
[147] Fix | Delete
}
[148] Fix | Delete
// iterate into children on non-links and links contained within the top level package
[149] Fix | Delete
if (child.children.length) {
[150] Fix | Delete
pkginfo.dependencies = {}
[151] Fix | Delete
shrinkwrapDeps(pkginfo.dependencies, top, child, seen)
[152] Fix | Delete
}
[153] Fix | Delete
})
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
function sortModules (modules) {
[157] Fix | Delete
// sort modules with the locale-agnostic Unicode sort
[158] Fix | Delete
var sortedModuleNames = modules.map(moduleName).sort()
[159] Fix | Delete
return modules.sort((a, b) => (
[160] Fix | Delete
sortedModuleNames.indexOf(moduleName(a)) - sortedModuleNames.indexOf(moduleName(b))
[161] Fix | Delete
))
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
function childVersion (top, child, req) {
[165] Fix | Delete
if (req.type === 'directory' || req.type === 'file') {
[166] Fix | Delete
return 'file:' + unixFormatPath(path.relative(top.path, child.package._resolved || req.fetchSpec))
[167] Fix | Delete
} else if (!isRegistry(req) && !child.fromBundle) {
[168] Fix | Delete
return child.package._resolved || req.saveSpec || req.rawSpec
[169] Fix | Delete
} else if (req.type === 'alias') {
[170] Fix | Delete
return `npm:${child.package.name}@${child.package.version}`
[171] Fix | Delete
} else {
[172] Fix | Delete
return child.package.version
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
function childRequested (top, child, requested) {
[177] Fix | Delete
if (requested.type === 'directory' || requested.type === 'file') {
[178] Fix | Delete
return 'file:' + unixFormatPath(path.relative(top.path, child.package._resolved || requested.fetchSpec))
[179] Fix | Delete
} else if (requested.type === 'git' && child.package._from) {
[180] Fix | Delete
return child.package._from
[181] Fix | Delete
} else if (!isRegistry(requested) && !child.fromBundle) {
[182] Fix | Delete
return child.package._resolved || requested.saveSpec || requested.rawSpec
[183] Fix | Delete
} else if (requested.type === 'tag') {
[184] Fix | Delete
// tags are not ranges we can match against, so we invent a "reasonable"
[185] Fix | Delete
// one based on what we actually installed.
[186] Fix | Delete
return npm.config.get('save-prefix') + child.package.version
[187] Fix | Delete
} else if (requested.saveSpec || requested.rawSpec) {
[188] Fix | Delete
return requested.saveSpec || requested.rawSpec
[189] Fix | Delete
} else if (child.package._from || (child.package._requested && child.package._requested.rawSpec)) {
[190] Fix | Delete
return child.package._from.replace(/^@?[^@]+@/, '') || child.package._requested.rawSpec
[191] Fix | Delete
} else {
[192] Fix | Delete
return child.package.version
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
function shrinkwrap_ (dir, pkginfo, opts, cb) {
[197] Fix | Delete
save(dir, pkginfo, opts, cb)
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
function save (dir, pkginfo, opts, cb) {
[201] Fix | Delete
// copy the keys over in a well defined order
[202] Fix | Delete
// because javascript objects serialize arbitrarily
[203] Fix | Delete
BB.join(
[204] Fix | Delete
checkPackageFile(dir, SHRINKWRAP),
[205] Fix | Delete
checkPackageFile(dir, PKGLOCK),
[206] Fix | Delete
checkPackageFile(dir, 'package.json'),
[207] Fix | Delete
(shrinkwrap, lockfile, pkg) => {
[208] Fix | Delete
const info = (
[209] Fix | Delete
shrinkwrap ||
[210] Fix | Delete
lockfile ||
[211] Fix | Delete
{
[212] Fix | Delete
path: path.resolve(dir, opts.defaultFile || PKGLOCK),
[213] Fix | Delete
data: '{}',
[214] Fix | Delete
indent: pkg && pkg.indent,
[215] Fix | Delete
newline: pkg && pkg.newline
[216] Fix | Delete
}
[217] Fix | Delete
)
[218] Fix | Delete
const updated = updateLockfileMetadata(pkginfo, pkg && JSON.parse(pkg.raw))
[219] Fix | Delete
const swdata = stringifyPackage(updated, info.indent, info.newline)
[220] Fix | Delete
if (swdata === info.raw) {
[221] Fix | Delete
// skip writing if file is identical
[222] Fix | Delete
log.verbose('shrinkwrap', `skipping write for ${path.basename(info.path)} because there were no changes.`)
[223] Fix | Delete
cb(null, pkginfo)
[224] Fix | Delete
} else {
[225] Fix | Delete
inferOwner(info.path).then(owner => {
[226] Fix | Delete
writeFileAtomic(info.path, swdata, (err) => {
[227] Fix | Delete
if (err) return cb(err)
[228] Fix | Delete
if (opts.silent) return cb(null, pkginfo)
[229] Fix | Delete
if (!shrinkwrap && !lockfile) {
[230] Fix | Delete
log.notice('', `created a lockfile as ${path.basename(info.path)}. You should commit this file.`)
[231] Fix | Delete
}
[232] Fix | Delete
if (selfOwner.uid === 0 && (selfOwner.uid !== owner.uid || selfOwner.gid !== owner.gid)) {
[233] Fix | Delete
chown(info.path, owner.uid, owner.gid, er => cb(er, pkginfo))
[234] Fix | Delete
} else {
[235] Fix | Delete
cb(null, pkginfo)
[236] Fix | Delete
}
[237] Fix | Delete
})
[238] Fix | Delete
})
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
).then((file) => {
[242] Fix | Delete
}, cb)
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
function updateLockfileMetadata (pkginfo, pkgJson) {
[246] Fix | Delete
// This is a lot of work just to make sure the extra metadata fields are
[247] Fix | Delete
// between version and dependencies fields, without affecting any other stuff
[248] Fix | Delete
const newPkg = {}
[249] Fix | Delete
let metainfoWritten = false
[250] Fix | Delete
const metainfo = new Set([
[251] Fix | Delete
'lockfileVersion',
[252] Fix | Delete
'preserveSymlinks'
[253] Fix | Delete
])
[254] Fix | Delete
Object.keys(pkginfo).forEach((k) => {
[255] Fix | Delete
if (k === 'dependencies') {
[256] Fix | Delete
writeMetainfo(newPkg)
[257] Fix | Delete
}
[258] Fix | Delete
if (!metainfo.has(k)) {
[259] Fix | Delete
newPkg[k] = pkginfo[k]
[260] Fix | Delete
}
[261] Fix | Delete
if (k === 'version') {
[262] Fix | Delete
writeMetainfo(newPkg)
[263] Fix | Delete
}
[264] Fix | Delete
})
[265] Fix | Delete
if (!metainfoWritten) {
[266] Fix | Delete
writeMetainfo(newPkg)
[267] Fix | Delete
}
[268] Fix | Delete
function writeMetainfo (pkginfo) {
[269] Fix | Delete
pkginfo.lockfileVersion = PKGLOCK_VERSION
[270] Fix | Delete
if (process.env.NODE_PRESERVE_SYMLINKS) {
[271] Fix | Delete
pkginfo.preserveSymlinks = process.env.NODE_PRESERVE_SYMLINKS
[272] Fix | Delete
}
[273] Fix | Delete
metainfoWritten = true
[274] Fix | Delete
}
[275] Fix | Delete
return newPkg
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
function checkPackageFile (dir, name) {
[279] Fix | Delete
const file = path.resolve(dir, name)
[280] Fix | Delete
return readFile(
[281] Fix | Delete
file, 'utf8'
[282] Fix | Delete
).then((data) => {
[283] Fix | Delete
const format = npm.config.get('format-package-lock') !== false
[284] Fix | Delete
const indent = format ? detectIndent(data).indent : 0
[285] Fix | Delete
const newline = format ? detectNewline(data) : 0
[286] Fix | Delete
[287] Fix | Delete
return {
[288] Fix | Delete
path: file,
[289] Fix | Delete
raw: data,
[290] Fix | Delete
indent,
[291] Fix | Delete
newline
[292] Fix | Delete
}
[293] Fix | Delete
}).catch({code: 'ENOENT'}, () => {})
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function