var annotateMetadata = module.exports.annotateMetadata = function (pkg, requested, spec, where) { validate('OOSS', arguments) pkg._requested = requested pkg._spec = spec pkg._where = where if (!pkg._args) pkg._args = [] pkg._args.push([requested, where]) // non-npm registries can and will return unnormalized data, plus // even the npm registry may have package data normalized with older // normalization rules. This ensures we get package data in a consistent, // stable format. try { normalizePackageData(pkg) } catch (ex) { // don't care } }
function resolveWithNewModule (pkg, tree, log, next) { validate('OOOF', arguments) log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status') return isInstallable(pkg, iferr(next, function () { if (!pkg._from) { pkg._from = pkg._requested.name + '@' + pkg._requested.spec } addShrinkwrap(pkg, iferr(next, function () { addBundled(pkg, iferr(next, function () { var parent = earliestInstallable(tree, tree, pkg) || tree var child = createChild({ package: pkg, parent: parent, path: path.join(parent.path, 'node_modules', pkg.name), realpath: path.resolve(parent.realpath, 'node_modules', pkg.name), children: pkg._bundled || [], isLink: tree.isLink, knownInstallable: true }) delete pkg._bundled var hasBundled = child.children.length var replaced = replaceModuleByName(parent, 'children', child) if (replaced) removeObsoleteDep(replaced) addRequiredDep(tree, child, function () { child.location = flatNameFromTree(child) if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child) if (hasBundled) { inflateBundled(child, child.children) } if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) { return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) { next(er, child, log) }) } next(null, child, log) }) })) })) })) }
Installer.prototype.readGlobalPackageData = function (cb) { validate('F', arguments) log.silly('install', 'readGlobalPackageData') var self = this this.loadArgMetadata(iferr(cb, function () { mkdirp(self.where, iferr(cb, function () { var pkgs = {} self.args.forEach(function (pkg) { pkgs[pkg.name] = true }) readPackageTree(self.where, function (ctx, kid) { return ctx.parent || pkgs[kid] }, iferr(cb, function (currentTree) { self.currentTree = currentTree return cb() })) })) })) }
Installer.prototype.printInstalled = function (cb) { validate('F', arguments) log.silly('install', 'printInstalled') var self = this log.clearProgress() this.differences.forEach(function (action) { var mutation = action[0] var child = action[1] var name = packageId(child) var where = path.relative(self.where, child.path) if (mutation === 'remove') { console.log('- ' + name + ' ' + where) } else if (mutation === 'move') { var oldWhere = path.relative(self.where, child.fromPath) console.log(name + ' ' + oldWhere + ' -> ' + where) } }) var addedOrMoved = this.differences.filter(function (action) { var mutation = action[0] var child = action[1] return !child.failed && (mutation === 'add' || mutation === 'update') }).map(function (action) { var child = action[1] return child.path }) log.showProgress() if (!addedOrMoved.length) return cb() recalculateMetadata(this.idealTree, log, iferr(cb, function (tree) { log.clearProgress() // These options control both how installs happen AND how `ls` shows output. // Something like `npm install --production` only installs production deps. // By contrast `npm install --production foo` installs `foo` and the // `production` option is ignored. But when it comes time for `ls` to show // its output, it excludes the thing we just installed because that flag. // The summary output we get should be unfiltered, showing everything // installed, so we clear these options before calling `ls`. npm.config.set('production', false) npm.config.set('dev', false) npm.config.set('only', '') npm.config.set('also', '') ls.fromTree(self.where, tree, addedOrMoved, false, function () { log.showProgress() cb() }) })) }
function Installer (where, dryrun, args) { validate('SBA', arguments) this.where = where this.dryrun = dryrun this.args = args this.currentTree = null this.idealTree = null this.differences = [] this.todo = [] this.progress = {} this.noPackageJsonOk = !!args.length this.topLevelLifecycles = !args.length this.npat = npm.config.get('npat') this.dev = npm.config.get('dev') || !npm.config.get('production') this.rollback = npm.config.get('rollback') this.link = npm.config.get('link') }
var earliestInstallable = exports.earliestInstallable = function (requiredBy, tree, pkg) { validate('OOO', arguments) function undeletedModuleMatches (child) { return !child.removed && moduleName(child) === pkg.name } if (tree.children.some(undeletedModuleMatches)) return null // If any of the children of this tree have conflicting // binaries then we need to decline to install this package here. var binaryMatches = pkg.bin && tree.children.some(function (child) { if (child.removed || !child.package.bin) return false return Object.keys(child.package.bin).some(function (bin) { return pkg.bin[bin] }) }) if (binaryMatches) return null // if this tree location requested the same module then we KNOW it // isn't compatible because if it were findRequirement would have // found that version. var deps = tree.package.dependencies || {} if (!tree.removed && requiredBy !== tree && deps[pkg.name]) { return null } var devDeps = tree.package.devDependencies || {} if (tree.isTop && devDeps[pkg.name]) { var requested = npa(pkg.name + '@' + devDeps[pkg.name]) if (!doesChildVersionMatch({package: pkg}, requested, tree)) { return null } } if (tree.phantomChildren && tree.phantomChildren[pkg.name]) return null if (tree.isTop) return tree if (tree.isGlobal) return tree if (npm.config.get('global-style') && tree.parent.isTop) return tree if (npm.config.get('legacy-bundling')) return tree return (earliestInstallable(requiredBy, tree.parent, pkg) || tree) }
function shrinkwrapDeps (deps, top, tree, seen) { validate('OOO', [deps, top, tree]) if (!seen) seen = new Set() if (seen.has(tree)) return seen.add(tree) sortModules(tree.children).forEach(function (child) { if (child.fakeChild) { deps[moduleName(child)] = child.fakeChild return } var childIsOnlyDev = isOnlyDev(child) var pkginfo = deps[moduleName(child)] = {} var requested = child.package._requested || getRequested(child) || {} pkginfo.version = childVersion(top, child, requested) if (child.fromBundle || child.isInLink) { pkginfo.bundled = true } else { if (isRegistry(requested)) { pkginfo.resolved = child.package._resolved } // no integrity for git deps as integirty hashes are based on the // tarball and we can't (yet) create consistent tarballs from a stable // source. if (requested.type !== 'git') { pkginfo.integrity = child.package._integrity if (!pkginfo.integrity && child.package._shasum) { pkginfo.integrity = ssri.fromHex(child.package._shasum, 'sha1') } } } if (childIsOnlyDev) pkginfo.dev = true if (isOnlyOptional(child)) pkginfo.optional = true if (child.requires.length) { pkginfo.requires = {} sortModules(child.requires).forEach((required) => { var requested = required.package._requested || getRequested(required) || {} pkginfo.requires[moduleName(required)] = childVersion(top, required, requested) }) } if (child.children.length) { pkginfo.dependencies = {} shrinkwrapDeps(pkginfo.dependencies, top, child, seen) } }) }
var inflateShrinkwrap = module.exports = function (tree, swdeps, finishInflating) { validate('OOF', arguments) if (!npm.config.get('shrinkwrap')) return finishInflating() var onDisk = {} tree.children.forEach(function (child) { onDisk[moduleName(child)] = child }) tree.children = [] asyncMap(Object.keys(swdeps), function (name, next) { var sw = swdeps[name] var spec = sw.resolved ? name + '@' + sw.resolved : (sw.from && url.parse(sw.from).protocol) ? name + '@' + sw.from : name + '@' + sw.version var child = onDisk[name] if (child && (child.fromShrinkwrap || (sw.resolved && child.package._resolved === sw.resolved) || (sw.from && url.parse(sw.from).protocol && child.package._from === sw.from) || child.package.version === sw.version)) { if (!child.fromShrinkwrap) child.fromShrinkwrap = spec tree.children.push(child) return next() } fetchPackageMetadata(spec, tree.path, iferr(next, function (pkg) { pkg._from = sw.from || spec addShrinkwrap(pkg, iferr(next, function () { addBundled(pkg, iferr(next, function () { var child = createChild({ package: pkg, loaded: false, parent: tree, fromShrinkwrap: spec, path: childPath(tree.path, pkg), realpath: childPath(tree.realpath, pkg), children: pkg._bundled || [] }) tree.children.push(child) if (pkg._bundled) { inflateBundled(child, child.children) } inflateShrinkwrap(child, sw.dependencies || {}, next) })) })) })) }, finishInflating) }
function inflatableChild (onDiskChild, name, topPath, tree, sw, requested, opts) { validate('OSSOOOO|ZSSOOOO', arguments) const usesIntegrity = ( requested.registry || requested.type === 'remote' || requested.type === 'file' ) const regTarball = tarballToVersion(name, sw.version) if (regTarball) { sw.resolved = sw.version sw.version = regTarball } if (sw.requires) Object.keys(sw.requires).map((_) => { sw.requires[_] = tarballToVersion(_, sw.requires[_]) || sw.requires[_] }) const modernLink = requested.type === 'directory' && !sw.from if (hasModernMeta(onDiskChild) && childIsEquivalent(sw, requested, onDiskChild)) { // The version on disk matches the shrinkwrap entry. if (!onDiskChild.fromShrinkwrap) onDiskChild.fromShrinkwrap = requested onDiskChild.package._requested = requested onDiskChild.package._spec = requested.rawSpec onDiskChild.package._where = topPath onDiskChild.package._optional = sw.optional onDiskChild.package._development = sw.dev onDiskChild.package._inBundle = sw.bundled onDiskChild.fromBundle = (sw.bundled || onDiskChild.package._inBundle) ? tree.fromBundle || tree : null if (!onDiskChild.package._args) onDiskChild.package._args = [] onDiskChild.package._args.push([String(requested), topPath]) // non-npm registries can and will return unnormalized data, plus // even the npm registry may have package data normalized with older // normalization rules. This ensures we get package data in a consistent, // stable format. normalizePackageDataNoErrors(onDiskChild.package) onDiskChild.swRequires = sw.requires tree.children.push(onDiskChild) return BB.resolve(onDiskChild) } else if ((sw.version && (sw.integrity || !usesIntegrity) && (requested.type !== 'directory' || modernLink)) || sw.bundled) { // The shrinkwrap entry has an integrity field. We can fake a pkg to get // the installer to do a content-address fetch from the cache, if possible. return BB.resolve(makeFakeChild(name, topPath, tree, sw, requested)) } else { // It's not on disk, and we can't just look it up by address -- do a full // fpm/inflate bundle pass. For registry deps, this will go straight to the // tarball URL, as if it were a remote tarball dep. return fetchChild(topPath, tree, sw, requested) } }
function Installer (where, dryrun, args) { validate('SBA', arguments) this.where = where this.dryrun = dryrun this.args = args this.currentTree = null this.idealTree = null this.differences = [] this.todo = [] this.progress = {} this.noPackageJsonOk = !!args.length this.topLevelLifecycles = !args.length this.dev = npm.config.get('dev') || (!/^prod(uction)?$/.test(npm.config.get('only')) && !npm.config.get('production')) || /^dev(elopment)?$/.test(npm.config.get('only')) this.prod = !/^dev(elopment)?$/.test(npm.config.get('only')) this.rollback = npm.config.get('rollback') this.link = npm.config.get('link') this.global = this.where === path.resolve(npm.globalDir, '..') }
module.exports = function (idealTree, log, next) { validate('OOF', arguments) var moduleMap = flattenTree(idealTree) var force = npm.config.get('force') var nodeVersion = npm.config.get('node-version') var strict = npm.config.get('engine-strict') var modules = Object.keys(moduleMap).map(function (name) { return moduleMap[name] }) asyncMap(modules, function (mod, done) { chain([ [checkEngine, mod, npm.version, nodeVersion, force, strict], [checkPlatform, mod, force], mod.parent && !isInLink(mod) && [checkGit, mod.realpath], [checkErrors, mod, idealTree] ], done) }, andValidateAllPeerDeps(idealTree, andCheckTop(idealTree, andFinishTracker(log, next)))) }
function addDependency (name, versionSpec, tree, log, done) { validate('SSOOF', arguments) var next = andAddParentToErrors(tree, done) childDependencySpecifier(tree, name, versionSpec, iferr(done, function (req) { var child = findRequirement(tree, name, req) if (child) { resolveWithExistingModule(child, tree, log, iferr(next, function (child, log) { if (child.package._shrinkwrap === undefined) { readShrinkwrap.andInflate(child, function (er) { next(er, child, log) }) } else { next(null, child, log) } })) } else { resolveWithNewModule(req, tree, log, next) } })) }
Deduper.prototype.generateActionsToTake = function (cb) { validate('F', arguments) log.silly('dedupe', 'generateActionsToTake') chain([ [this.newTracker(log, 'hoist', 1)], [hoistChildren, this.idealTree, this.differences], [this, this.finishTracker, 'hoist'], [this.newTracker(log, 'sort-actions', 1)], [this, function (next) { this.differences = sortActions(this.differences) next() }], [this, this.finishTracker, 'sort-actions'], [filterInvalidActions, this.where, this.differences], [checkPermissions, this.differences], [decomposeActions, this.differences, this.todo] ], cb) }
module.exports = function (top, differences, next) { validate('SAF', arguments) var action var keep = [] /*eslint no-cond-assign:0*/ while (action = differences.shift()) { var cmd = action[0] var pkg = action[1] if (pkg.isInLink || pkg.parent.target) { log.warn('skippingAction', 'Module is inside a symlinked module: not running ' + cmd + ' ' + pkg.package._id + ' ' + path.relative(top, pkg.path)) } else { keep.push(action) } } differences.push.apply(differences, keep) next() }
function computeVersionSpec (tree, child) { validate('OO', arguments) var requested = child.package._requested if (requested.registry) { var version = child.package.version var rangeDescriptor = '' if (semver.valid(version, true) && semver.gte(version, '0.1.0', true) && !npm.config.get('save-exact')) { rangeDescriptor = npm.config.get('save-prefix') } return rangeDescriptor + version } else if (requested.type === 'directory' || requested.type === 'file') { return 'file:' + path.relative(tree.path, requested.fetchSpec) } else { return requested.saveSpec } }
function markDeps (spec, done) { validate('SF', arguments) realizePackageSpecifier(spec, packageRelativePath(tree), function (er, req) { if (er || !req.name) return done() var child = findRequirement(tree, req.name, req) if (child) { resolveWithExistingModule(child, tree, log, andIgnoreErrors(done)) } else if (tree.package.dependencies[req.name] != null) { tree.missingDeps[req.name] = req.rawSpec done() } else if (tree.package.devDependencies[req.name] != null) { tree.missingDevDeps[req.name] = req.rawSpec done() } else { done() } }) }
function getThingsToRemove (args, tree) { validate('AO', arguments) if (!tree.removed) return [] var toRemove = tree.removed.map(function (child) { return { name: moduleName(child), save: child.save } }) var saveType = getSaveType(args) args.forEach(function (arg) { toRemove.push({ name: arg, save: saveType }) }) return toRemove }
function readLinkOrShim (path, cb) { validate('SF', arguments) lstat(path, iferr(cb, function (stat) { if (stat.isSymbolicLink()) { readlink(path, cb) } else { readCmdShim(path, function (er, source) { if (!er) return cb(null, source) // lstat wouldn't return an error on these, so we don't either. if (er.code === 'ENOTASHIM' || er.code === 'EISDIR') { return cb(null, null) } else { return cb(er) } }) } })) }
Installer.prototype.runPostinstallTopLevelLifecycles = function (cb) { validate('F', arguments) if (this.failing) return cb() if (!this.topLevelLifecycles) return cb() log.silly('install', 'runPostinstallTopLevelLifecycles') var steps = [] var trackLifecycle = this.progress.runTopLevelLifecycles steps.push( [doOneAction, 'build', this.idealTree.path, this.idealTree, trackLifecycle.newGroup('build:.')], [doOneAction, 'install', this.idealTree.path, this.idealTree, trackLifecycle.newGroup('install:.')], [doOneAction, 'postinstall', this.idealTree.path, this.idealTree, trackLifecycle.newGroup('postinstall:.')]) if (this.dev) { steps.push( [doOneAction, 'prepare', this.idealTree.path, this.idealTree, trackLifecycle.newGroup('prepare')]) } chain(steps, cb) }
var diffTrees = module.exports._diffTrees = function (oldTree, newTree) { validate('OO', arguments) var differences = [] var flatOldTree = flattenTree(oldTree) var flatNewTree = flattenTree(newTree) var toRemove = {} var toRemoveByUniqueId = {} // find differences Object.keys(flatOldTree).forEach(function (flatname) { if (flatNewTree[flatname]) return var pkg = flatOldTree[flatname] toRemove[flatname] = pkg var pkgunique = getUniqueId(pkg.package) if (!toRemoveByUniqueId[pkgunique]) toRemoveByUniqueId[pkgunique] = [] toRemoveByUniqueId[pkgunique].push(flatname) }) Object.keys(flatNewTree).forEach(function (path) { var pkg = flatNewTree[path] pkg.oldPkg = flatOldTree[path] if (pkg.oldPkg) { if (!pkg.userRequired && pkgAreEquiv(pkg.oldPkg.package, pkg.package)) return setAction(differences, 'update', pkg) } else { var vername = getUniqueId(pkg.package) var removing = toRemoveByUniqueId[vername] && toRemoveByUniqueId[vername].length var bundlesOrFromBundle = pkg.fromBundle || pkg.package.bundleDependencies if (removing && !bundlesOrFromBundle) { var flatname = toRemoveByUniqueId[vername].shift() pkg.fromPath = toRemove[flatname].path setAction(differences, 'move', pkg) delete toRemove[flatname] } else if (!(pkg.isInLink && pkg.fromBundle)) { setAction(differences, 'add', pkg) } } }) Object .keys(toRemove) .map(function (path) { return toRemove[path] }) .forEach(function (pkg) { setAction(differences, 'remove', pkg) }) return differences }
function shrinkwrapDeps (deps, top, tree, seen) { validate('OOO', [deps, top, tree]) if (!seen) seen = {} if (seen[tree.path]) return seen[tree.path] = true tree.children.sort(function (aa, bb) { return moduleName(aa).localeCompare(moduleName(bb)) }).forEach(function (child) { var childIsOnlyDev = isOnlyDev(child) if (child.fakeChild) { deps[moduleName(child)] = child.fakeChild return } var pkginfo = deps[moduleName(child)] = {} var req = child.package._requested || getRequested(child) if (req.type === 'directory' || req.type === 'file') { pkginfo.version = 'file:' + path.relative(top.path, child.package._resolved || req.fetchSpec) } else if (!req.registry && !child.fromBundle) { pkginfo.version = child.package._resolved || req.saveSpec || req.rawSpec } else { pkginfo.version = child.package.version } if (child.fromBundle || child.isInLink) { pkginfo.bundled = true } else { if (req.registry) { pkginfo.resolved = child.package._resolved } // no integrity for git deps as integirty hashes are based on the // tarball and we can't (yet) create consistent tarballs from a stable // source. if (req.type !== 'git') { pkginfo.integrity = child.package._integrity if (!pkginfo.integrity && child.package._shasum) { pkginfo.integrity = ssri.fromHex(child.package._shasum, 'sha1') } } } if (childIsOnlyDev) pkginfo.dev = true if (isOptional(child)) pkginfo.optional = true if (child.children.length) { pkginfo.dependencies = {} shrinkwrapDeps(pkginfo.dependencies, top, child, seen) } }) }
Installer.prototype.readGlobalPackageData = function (cb) { validate('F', arguments) log.silly('install', 'readGlobalPackageData') var self = this this.currentTree = new readPackageTree.Node(null, this.where, this.where, null, {}) this.loadArgMetadata(iferr(cb, function () { mkdirp(self.where, iferr(cb, function () { asyncMap(self.args, function (pkg, done) { readPackageTree(path.resolve(self.where, 'node_modules', pkg.name), function (err, subTree) { if (subTree) { subTree.parent = self.currentTree self.currentTree.children.push(subTree) } done() }) }, cb) })) })) }
Installer.prototype.executeActions = function (cb) { validate('F', arguments) log.silly('install', 'executeActions') var todo = this.todo var cg = this.progress.executeActions var node_modules = path.resolve(this.where, 'node_modules') var staging = path.resolve(node_modules, '.staging') var steps = [] var trackLifecycle = cg.newGroup('lifecycle') cb = unlockCB(node_modules, '.staging', cb) steps.push( [doSerialActions, 'global-install', staging, todo, trackLifecycle.newGroup('global-install')], [doParallelActions, 'fetch', staging, todo, cg.newGroup('fetch', 10)], [lock, node_modules, '.staging'], [rimraf, staging], [mkdirp, staging], [doParallelActions, 'extract', staging, todo, cg.newGroup('extract', 10)], [doParallelActions, 'preinstall', staging, todo, trackLifecycle.newGroup('preinstall')], [doReverseSerialActions, 'remove', staging, todo, cg.newGroup('remove')], [doSerialActions, 'move', staging, todo, cg.newGroup('move')], [doSerialActions, 'finalize', staging, todo, cg.newGroup('finalize')], [doSerialActions, 'build', staging, todo, trackLifecycle.newGroup('build')], [doSerialActions, 'global-link', staging, todo, trackLifecycle.newGroup('global-link')], [doParallelActions, 'update-linked', staging, todo, trackLifecycle.newGroup('update-linked')], [doSerialActions, 'install', staging, todo, trackLifecycle.newGroup('install')], [doSerialActions, 'postinstall', staging, todo, trackLifecycle.newGroup('postinstall')]) if (this.npat) { steps.push( [doParallelActions, 'test', staging, todo, trackLifecycle.newGroup('npat')]) } var self = this chain(steps, function (er) { if (!er || self.rollback) { rimraf(staging, function () { cb(er) }) } else { cb(er) } }) }
Deduper.prototype.loadIdealTree = function (cb) { validate('F', arguments) log.silly('install', 'loadIdealTree') var self = this chain([ [this.newTracker(this.progress.loadIdealTree, 'cloneCurrentTree')], [this, this.cloneCurrentTreeToIdealTree], [this, this.finishTracker, 'cloneCurrentTree'], [this.newTracker(this.progress.loadIdealTree, 'loadAllDepsIntoIdealTree', 10)], [function (next) { loadExtraneous(self.idealTree, self.progress.loadAllDepsIntoIdealTree, next) }], [this, this.finishTracker, 'loadAllDepsIntoIdealTree'], [this, function (next) { recalculateMetadata(this.idealTree, log, next) }] ], cb) }
var mutateIntoLogicalTree = module.exports = function (tree) { validate('O', arguments) validateAllPeerDeps(tree, function (tree, pkgname, version) { if (!tree.missingPeers) tree.missingPeers = {} tree.missingPeers[pkgname] = version }) var flat = flattenTree(tree) function getNode (flatname) { return flatname.substr(0, 5) === '#DEV:' ? flat[flatname.substr(5)] : flat[flatname] } Object.keys(flat).sort().forEach(function (flatname) { var node = flat[flatname] var requiredBy = node.package._requiredBy || [] var requiredByNames = requiredBy.filter(function (parentFlatname) { var parentNode = getNode(parentFlatname) if (!parentNode) return false return parentNode.package.dependencies[moduleName(node)] || (parentNode.package.devDependencies && parentNode.package.devDependencies[moduleName(node)]) }) requiredBy = requiredByNames.map(getNode) node.requiredBy = requiredBy if (!requiredBy.length) return if (node.parent) node.parent.children = without(node.parent.children, node) requiredBy.forEach(function (parentNode) { parentNode.children = union(parentNode.children, [node]) }) if (node.package._requiredBy.some(function (nodename) { return nodename[0] === '#' })) { tree.children = union(tree.children, [node]) } }) return tree }
function andForEachChild (load, next) { validate('F', [next]) next = dezalgo(next) return function (er, children, logs) { // when children is empty, logs won't be passed in at all (asyncMap is weird) // so shortcircuit before arg validation if (!er && (!children || children.length === 0)) return next() validate('EAA', arguments) if (er) return next(er) assert(children.length === logs.length) var cmds = [] for (var ii = 0; ii < children.length; ++ii) { cmds.push([load, children[ii], logs[ii]]) } var sortedCmds = cmds.sort(function installOrder (aa, bb) { return moduleName(aa[1]).localeCompare(moduleName(bb[1])) }) chain(sortedCmds, next) } }
Installer.prototype.loadIdealTree = function (cb) { validate('F', arguments) log.silly('install', 'loadIdealTree') chain([ [this.newTracker(this.progress.loadIdealTree, 'loadIdealTree:cloneCurrentTree')], [this, this.cloneCurrentTreeToIdealTree], [this, this.finishTracker, 'loadIdealTree:cloneCurrentTree'], [this.newTracker(this.progress.loadIdealTree, 'loadIdealTree:loadShrinkwrap')], [this, this.loadShrinkwrap], [this, this.finishTracker, 'loadIdealTree:loadShrinkwrap'], [this.newTracker(this.progress.loadIdealTree, 'loadIdealTree:loadAllDepsIntoIdealTree', 10)], [this, this.loadAllDepsIntoIdealTree], [this, this.finishTracker, 'loadIdealTree:loadAllDepsIntoIdealTree'], [this, function (next) { computeMetadata(this.idealTree); next() }], [this, this.pruneIdealTree] ], cb) }
function andCheckTop (idealTree, next) { validate('OF', arguments) if (idealTree.package.error) { return next } else { return function (er) { // FIXME: when we replace read-package-json with something less magic, // this should done elsewhere. // As it is, the package has already been normalized and thus some // errors are suppressed. var pkg = clone(idealTree.package) normalizePackageData(pkg, function (warn) { var warnObj = new Error(getPackageId(idealTree) + ' ' + warn) warnObj.code = 'EPACKAGEJSON' idealTree.warnings.push(warnObj) }, false) next(er) } } }
function recalculateMetadata (tree, log, seen, next) { validate('OOOF', arguments) if (seen[tree.path]) return next() seen[tree.path] = true if (tree.parent == null) resetMetadata(tree) function markDeps (spec, done) { validate('SF', arguments) realizePackageSpecifier(spec, packageRelativePath(tree), function (er, req) { if (er || !req.name) return done() var child = findRequirement(tree, req.name, req) if (child) { resolveWithExistingModule(child, tree, log, andIgnoreErrors(done)) } else if (tree.package.dependencies[req.name] != null) { tree.missingDeps[req.name] = req.rawSpec done() } else if (tree.package.devDependencies[req.name] != null) { tree.missingDevDeps[req.name] = req.rawSpec done() } else { done() } }) } function specs (deps) { return Object.keys(deps).map(function (depname) { return depname + '@' + deps[depname] }) } var tomark = specs(tree.package.dependencies) if (!tree.parent && (npm.config.get('dev') || !npm.config.get('production'))) { tomark = union(tomark, specs(tree.package.devDependencies)) } tree.children = tree.children.filter(function (child) { return !child.failed }) chain([ [asyncMap, tomark, markDeps], [asyncMap, tree.children, function (child, done) { recalculateMetadata(child, log, seen, done) }] ], function () { tree.userRequired = tree.package._requiredBy.some(function (req) { req === '#USER' }) tree.existing = tree.package._requiredBy.some(function (req) { req === '#EXISTING' }) tree.package._location = flatNameFromTree(tree) next(null, tree) }) }
function login (username, password, conf) { validate('SSO', arguments) const userobj = { _id: 'org.couchdb.user:'******'user', roles: [], date: new Date().toISOString() } const logObj = {} Object.keys(userobj).forEach(k => { logObj[k] = k === 'password' ? 'XXXXX' : userobj[k] }) process.emit('log', 'verbose', 'login', 'before first PUT', logObj) const target = url.resolve(conf.registry, '-/user/org.couchdb.user:'******'PUT', target: target, body: userobj}, conf)).catch(err => { if (err.code === 'E400') err.message = `There is no user with the username "${username}".` if (err.code !== 'E409') throw err return fetchJSON(Object.assign({method: 'GET', target: target + '?write=true'}, conf)).then(result => { Object.keys(result).forEach(function (k) { if (!userobj[k] || k === 'roles') { userobj[k] = result[k] } }) const req = { method: 'PUT', target: target + '/-rev/' + userobj._rev, body: userobj, auth: { basic: { username: username, password: password } } } return fetchJSON(Object.assign({}, conf, req)) }) }) }