summaryrefslogtreecommitdiff
path: root/deps/npm/lib/outdated.js
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2018-04-20 18:26:37 -0700
committerRebecca Turner <me@re-becca.org>2018-05-24 23:24:45 -0700
commit468ab4519e1b92473acefb22801497a1af6aebae (patch)
treebdac1d062cd4b094bde3a21147bab5d82c792ece /deps/npm/lib/outdated.js
parentac8226115e2192a7a46ba07789fa5136f74223e1 (diff)
downloadnode-new-468ab4519e1b92473acefb22801497a1af6aebae.tar.gz
deps: upgrade npm to 6.1.0
PR-URL: https://github.com/nodejs/node/pull/20190 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'deps/npm/lib/outdated.js')
-rw-r--r--deps/npm/lib/outdated.js181
1 files changed, 80 insertions, 101 deletions
diff --git a/deps/npm/lib/outdated.js b/deps/npm/lib/outdated.js
index a38137b66c..8b0a43d6ba 100644
--- a/deps/npm/lib/outdated.js
+++ b/deps/npm/lib/outdated.js
@@ -24,13 +24,14 @@ var os = require('os')
var url = require('url')
var path = require('path')
var readPackageTree = require('read-package-tree')
-var readJson = require('read-package-json')
var asyncMap = require('slide').asyncMap
var color = require('ansicolors')
var styles = require('ansistyles')
var table = require('text-table')
var semver = require('semver')
var npa = require('npm-package-arg')
+var pickManifest = require('npm-pick-manifest')
+var fetchPackageMetadata = require('./fetch-package-metadata.js')
var mutateIntoLogicalTree = require('./install/mutate-into-logical-tree.js')
var npm = require('./npm.js')
var long = npm.config.get('long')
@@ -41,7 +42,6 @@ var computeVersionSpec = require('./install/deps.js').computeVersionSpec
var moduleName = require('./utils/module-name.js')
var output = require('./utils/output.js')
var ansiTrim = require('./utils/ansi-trim')
-var fetchPackageMetadata = require('./fetch-package-metadata.js')
function uniq (list) {
// we maintain the array because we need an array, not iterator, return
@@ -89,11 +89,11 @@ function outdated (args, silent, cb) {
} else {
var outList = list.map(makePretty)
var outHead = [ 'Package',
- 'Current',
- 'Wanted',
- 'Latest',
- 'Location'
- ]
+ 'Current',
+ 'Wanted',
+ 'Latest',
+ 'Location'
+ ]
if (long) outHead.push('Package Type')
var outTable = [outHead].concat(outList)
@@ -117,25 +117,19 @@ function outdated (args, silent, cb) {
// [[ dir, dep, has, want, latest, type ]]
function makePretty (p) {
- var dep = p[0]
var depname = p[1]
- var dir = dep.path
var has = p[2]
var want = p[3]
var latest = p[4]
var type = p[6]
var deppath = p[7]
- if (!npm.config.get('global')) {
- dir = path.relative(process.cwd(), dir)
- }
-
var columns = [ depname,
- has || 'MISSING',
- want,
- latest,
- deppath
- ]
+ has || 'MISSING',
+ want,
+ latest,
+ deppath
+ ]
if (long) columns[5] = type
if (npm.color) {
@@ -183,10 +177,10 @@ function makeJSON (list) {
dir = path.relative(process.cwd(), dir)
}
out[depname] = { current: has,
- wanted: want,
- latest: latest,
- location: dir
- }
+ wanted: want,
+ latest: latest,
+ location: dir
+ }
if (long) out[depname].type = type
})
return JSON.stringify(out, null, 2)
@@ -202,13 +196,15 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
var types = {}
var pkg = tree.package
+ if (!tree.children) tree.children = []
+
var deps = tree.error ? tree.children : tree.children.filter((child) => !isExtraneous(child))
deps.forEach(function (dep) {
types[moduleName(dep)] = 'dependencies'
})
- Object.keys(tree.missingDeps).forEach(function (name) {
+ Object.keys(tree.missingDeps || {}).forEach(function (name) {
deps.push({
package: { name: name },
path: tree.path,
@@ -262,7 +258,7 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
!npm.config.get('global')
)
if (doUpdate) {
- Object.keys(pkg.devDependencies).forEach(function (k) {
+ Object.keys(pkg.devDependencies || {}).forEach(function (k) {
if (!(k in parentHas)) {
deps[k] = pkg.devDependencies[k]
types[k] = 'devDependencies'
@@ -276,8 +272,8 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
deps = deps.filter(function (dep) { return dep !== child })
}
has[child.package.name] = {
- version: child.package.version,
- from: child.package._from
+ version: child.isLink ? 'linked' : child.package.version,
+ from: child.isLink ? 'file:' + child.path : child.package._from
}
})
@@ -286,11 +282,17 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
// otherwise dive into the folder
asyncMap(deps, function (dep, cb) {
var name = moduleName(dep)
- var required = (tree.package.dependencies)[name] ||
- (tree.package.optionalDependencies)[name] ||
- (tree.package.devDependencies)[name] ||
- computeVersionSpec(tree, dep) ||
- '*'
+ var required
+ if (tree.package.dependencies && name in tree.package.dependencies) {
+ required = tree.package.dependencies[name]
+ } else if (tree.package.optionalDependencies && name in tree.package.optionalDependencies) {
+ required = tree.package.optionalDependencies[name]
+ } else if (tree.package.devDependencies && name in tree.package.devDependencies) {
+ required = tree.package.devDependencies[name]
+ } else if (has[name]) {
+ required = computeVersionSpec(tree, dep)
+ }
+
if (!long) return shouldUpdate(args, dep, name, has, required, depth, path, cb)
shouldUpdate(args, dep, name, has, required, depth, path, cb, types[name])
@@ -309,11 +311,11 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) {
// show user that no viable version can be found
if (er) return cb(er)
outdated_(args,
- pkgpath,
- tree,
- has,
- depth + 1,
- cb)
+ pkgpath,
+ tree,
+ has,
+ depth + 1,
+ cb)
}
function doIt (wanted, latest) {
@@ -324,23 +326,32 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) {
}
if (args.length && args.indexOf(dep) === -1) return skip()
+
+ if (tree.isLink && req == null) return skip()
+
+ if (req == null || req === '') req = '*'
+
var parsed = npa.resolve(dep, req)
- if (tree.isLink && tree.parent && tree.parent.isTop) {
- return doIt('linked', 'linked')
- }
- if (parsed.type === 'git' || parsed.type === 'hosted') {
+ if (parsed.type === 'directory') {
+ if (tree.isLink) {
+ return skip()
+ } else {
+ return doIt('linked', 'linked')
+ }
+ } else if (parsed.type === 'git') {
return doIt('git', 'git')
- }
+ } else if (parsed.type === 'file') {
+ return updateLocalDeps()
+ } else {
+ return mapToRegistry(dep, npm.config, function (er, uri, auth) {
+ if (er) return cb(er)
- // search for the latest package
- mapToRegistry(dep, npm.config, function (er, uri, auth) {
- if (er) return cb(er)
-
- npm.registry.get(uri, { auth: auth }, updateDeps)
- })
+ npm.registry.get(uri, { auth: auth }, updateDeps)
+ })
+ }
function updateLocalDeps (latestRegistryVersion) {
- readJson(path.resolve(parsed.fetchSpec, 'package.json'), function (er, localDependency) {
+ fetchPackageMetadata('file:' + parsed.fetchSpec, '.', (er, localDependency) => {
if (er) return cb()
var wanted = localDependency.version
@@ -363,63 +374,31 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) {
}
function updateDeps (er, d) {
- if (er) {
- if (parsed.type !== 'directory' && parsed.type !== 'file') return cb(er)
- return updateLocalDeps()
- }
-
- if (!d || !d['dist-tags'] || !d.versions) return cb()
- var l = d.versions[d['dist-tags'].latest]
- if (!l) return cb()
-
- var r = req
- if (d['dist-tags'][req]) {
- r = d['dist-tags'][req]
- }
-
- if (semver.validRange(r, true)) {
- // some kind of semver range.
- // see if it's in the doc.
- var vers = Object.keys(d.versions)
- var v = semver.maxSatisfying(vers, r, true)
- if (v) {
- return onCacheAdd(null, d.versions[v])
- }
- }
+ if (er) return cb(er)
- // We didn't find the version in the doc. See if we can find it in metadata.
- var spec = dep
- if (req) {
- spec = dep + '@' + req
- }
- fetchPackageMetadata(spec, '', onCacheAdd)
-
- function onCacheAdd (er, d) {
- // if this fails, then it means we can't update this thing.
- // it's probably a thing that isn't published.
- if (er) {
- if (er.code && er.code === 'ETARGET') {
- // no viable version found
- return skip(er)
- }
+ try {
+ var l = pickManifest(d, 'latest')
+ var m = pickManifest(d, req)
+ } catch (er) {
+ if (er.code === 'ETARGET') {
+ return skip(er)
+ } else {
return skip()
}
+ }
- // check that the url origin hasn't changed (#1727) and that
- // there is no newer version available
- var dFromUrl = d._from && url.parse(d._from).protocol
- var cFromUrl = curr && curr.from && url.parse(curr.from).protocol
-
- if (!curr ||
- dFromUrl && cFromUrl && d._from !== curr.from ||
- d.version !== curr.version ||
- d.version !== l.version) {
- if (parsed.type === 'file' || parsed.type === 'directory') return updateLocalDeps(l.version)
-
- doIt(d.version, l.version)
- } else {
- skip()
- }
+ // check that the url origin hasn't changed (#1727) and that
+ // there is no newer version available
+ var dFromUrl = m._from && url.parse(m._from).protocol
+ var cFromUrl = curr && curr.from && url.parse(curr.from).protocol
+
+ if (!curr ||
+ (dFromUrl && cFromUrl && m._from !== curr.from) ||
+ m.version !== curr.version ||
+ m.version !== l.version) {
+ doIt(m.version, l.version)
+ } else {
+ skip()
}
}
}